Skip to content Skip to sidebar Skip to footer

Widget HTML #1

Keyes CNC Shield V4 GRBL How To Use It

Keyes CNC Shield V.4 GRBL

Keyes CNC Shield V4 GRBL How To Use It - CNC Shield is a module for CNC stepper motor drivers. In this article we will learn CNC Shield from Keyes Studio.

This Keyes CNC Shield uses the A4988 driver for each stepper motor and to drive or control this CNC Shield using the Arduino Nano.

The specifications of this CNC Shield are:

  • 3 Stepper motor drivers
  • Compatible with micro laser machines and engraving machines
  • Can control two-phase stepper motors up to 2A
  • I/O interfaces like ENDSTOP are easy to connect
  • An I2C interface is available which can be connected to the LCD module.
  • Has DC input Jack from 7.5 to 12V
  • Compatible with GRBL 8.

A. Keyes CNC Shield PinOut

The pinout of Keyes CNC Shield is as follows:
Chip Piko keyes cnc shield pinout
Keyes CNC Shield (Source: https://wiki.keyestudio.com)

B. Driver Motor Stepper A4988

Because this CNC Shield uses Driver A4988, it would be nice if we learn a little about this driver.

The A4988 driver is a DMOS microstep driver that supports full, 1/2, 1/4, 1/8, and 1/16 stepping resolutions. The specifications are as follows.
 
Driver A4988 Specs:
  • Min Logic Voltage 3V
  • Max Logic Voltage 5.5V
  • Max Current per Phase 2A
  • Continuous Current per Phase 1A
  • Min Operating Voltage 8V
  • Max Operating Voltage 35V
 
driver motor stepper a4988
Pin Out Driver A4988

 

To be able to choose the stepping resolution, this a4988 has pin out MS1, MS2, and MS3. The working setting modes are:
  1. Stepping Full Step
    MS1 = Low 
    MS2 = Low
    MS3 = Low

  2. Stepping 1/2
    MS1 = High
    MS2 = Low
    MS3 = Low

  3. Stepping 1/4
    MS1 = Low
    MS2 = High
    MS3 = Low

  4. Stepping 1/8
    MS1 = High
    MS2 = High
    MS3 = Low

  5. Stepping 1/16
    MS1 = High
    MS2 = High
    MS3 = High

    * Low = Gnd dan High = Vcc
In the A4899 driver module there is an SMD potentiometer which is useful for regulating current usage.

For more information about this driver, please go to the keyesstudio wiki page here.

Or if you want more details about the chip, here I attach the A4988 PDF Download Datasheet:

 

C. Arduino Nano

Now we will discuss a little about Arduino Nano serial communication and related things.
 
Many Arduino Nanos produce them, so the most basic difference from Arduino Nano is in the Serial Converter Chip section.
 
Some use FTDI chips and some use CH340. Most Arduino Nano products from China use the CH340 chip.
 
Especially for the CH340 chip, we have to install the software driver so that the code upload process will run smoothly.
 
Now, please attach the Arduino Nano to the CNC Shield keys.

D. Connect Stepper Motor to CNC Shield Keyes

After Arduino is attached to the Shield board, the next step is to connect this stepper motor to the shield board. Please follow the following picture:
Keyes CNC Shield Wiring Schematics  Chip Piko Keyes CNC Shield V.4 GRBL Serta Cara Menggunakannya
CNC Shield V4 Connection Stepper Motor

Make sure you connect to all the stepper motor header pins that have been provided on the board including X, Y, Z.
 

E. Stepper Test

Before we proceed to the next step, we must first test the stepper motor that we have connected to the Shield to ensure the motor works normally.
 
Please upload the following code to your arduino.

#define pinEN    8

#define stepPinX 5
#define stepPinY 6
#define stepPinZ 7

#define dirPinX  2
#define dirPinY  3
#define dirPinZ  4

void setup() {
  pinMode(stepPinX , OUTPUT);
  pinMode(stepPinY , OUTPUT);
  pinMode(stepPinZ , OUTPUT);

  pinMode(dirPinX , OUTPUT);
  pinMode(dirPinY , OUTPUT);
  pinMode(dirPinZ , OUTPUT);

  pinMode(pinEN , OUTPUT);
  digitalWrite(pinEN, LOW); // Enable Driver, if you want to disable the driver, set to HIGH
}

void loop() {
  digitalWrite(dirPinX, HIGH);
  digitalWrite(dirPinY, HIGH);
  digitalWrite(dirPinZ, HIGH);

  for (int x = 0; x < 200; x++)
  {
    digitalWrite(stepPinX, HIGH);
    digitalWrite(stepPinY, HIGH);
    digitalWrite(stepPinZ, HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPinX, LOW);
    digitalWrite(stepPinY, LOW);
    digitalWrite(stepPinZ, LOW);
    delayMicroseconds(500);
  }

  delay(1000);

  //Turn back
  digitalWrite(dirPinX, LOW);
  digitalWrite(dirPinY, LOW);
  digitalWrite(dirPinZ, LOW);

  for (int x = 0; x < 200; x++)
  {
    digitalWrite(stepPinX, HIGH);
    digitalWrite(stepPinY, HIGH);
    digitalWrite(stepPinZ, HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPinX, LOW);
    digitalWrite(stepPinY, LOW);
    digitalWrite(stepPinZ, LOW);
    delayMicroseconds(500);
  }
  delay(1000);
}

If your three stepper motors rotate the same, then the relationship between the stepper and the shield is normal.

Now we will go to the software part.

F. Control 1 Rotating Stepper Motor Via Serial Monitor

Now we will try to rotate the stepper motor using the Arduino IDE Serial Monitor. To be able to rotate, enter the degree value in the serial monitor form.

For example, we want the motor to rotate by 90°, then type 90 and then enter. If we want to go back 90° turning the other way around, type -90.

However, the program below is only for one axis stepper motor I made. If you want everything to be adjusted by serial monitor, please modify this program.

The program is as follows:
int pinEN = 8;
int dirPinX = 2;
int stepPinX = 5;

//int stepsPerRevolution = 200;  // 1/1 
int stepsPerRevolution = 400;  // 1/2  
//int stepsPerRevolution = 1600; // 1/8 
//int stepsPerRevolution = 3200;   // 1/16 

int dataSerial = 0;
int nilai = 0;
int nilaiDelay = 500;

void setup() {
  Serial.begin(9600);
  pinMode(stepPinX, OUTPUT);
  pinMode(dirPinX, OUTPUT);
  pinMode(pinEN, OUTPUT);
}

void loop()
{
  if (Serial.available() != 0)
  {
    digitalWrite(pinEN, LOW);       //Aktifkan driver
    dataSerial = Serial.parseInt();
    nilai = map(dataSerial, 0, 360, 0, stepsPerRevolution);

    Serial.print("Dari Serial:");
    Serial.print(dataSerial);
    Serial.print("   Step:");
    Serial.println(nilai);
  }

  //if value +, turn right
  if (dataSerial > 0)
  {
    digitalWrite(dirPinX, LOW);

    for (int i = 0; i < nilai; i++)
    {
      digitalWrite(stepPinX, HIGH);
      delayMicroseconds(nilaiDelay);
      digitalWrite(stepPinX, LOW);
      delayMicroseconds(nilaiDelay);
    }

  }

  //If value -, turn left
  if (dataSerial < 0)
  {
    digitalWrite(dirPinX, HIGH);

    for (int i = 0; i > nilai; i--)
    {
      digitalWrite(stepPinX, HIGH);
      delayMicroseconds(nilaiDelay);
      digitalWrite(stepPinX, LOW);
      delayMicroseconds(nilaiDelay);
    }
  }

  delay(1000);
  digitalWrite(pinEN, HIGH); //Turn off the driver, use this for testing only, to keep the stepper motor from overheating. 
}
After you upload it to Arduino Nano, please open the serial monitor and type the degree value, then send it.

G. Control 3 Stepper Motors Via Serial Monitor

To drive more than 1 stepper motor simultaneously through a serial monitor, we cannot use the above code (F), but we need to add an interrupt function.

For the full program because it is longer, I wrote it on a special page, please click here.

H. Install Firmware GRBL  dan GRBL Kontroller

What is the GRBL?
 
GRBL is a firmware for microcontrollers that can convert G-Code programming language into stepper motor movement on CNC machines.
 
This firmware will be programmed to Arduino. Then arduino receives the G-Code data from the PC and then processes it so that it sends a certain signal to the Stepper Motor Driver.
 
In this case the motor driver is A499.
 
To be able to run this GRBL G-Code to Arduino, on a PC we need a software called GRBL Controller.
 
To be able to use the GRBL Firmware, we first download the library file. Please download on the following button:
 
 
Please add it to your Arduino IDE.
 
After the library is added to your Arduino IDE, we have to change the pin direction and step rules by editing the "config.h" file.

The folder is in the grbl folder as shown in the following image:
Keyes CNC Shield V.4 GRBL Serta Cara Menggunakannya


Later in your config.h file look for this line of program:
// Define pin-assignments
// NOTE: All step bit and direction pins must be on the same port.
#define STEPPING_DDR       DDRD
#define STEPPING_PORT      PORTD
#define X_STEP_BIT         2  // Uno Digital Pin 2
#define Y_STEP_BIT         3  // Uno Digital Pin 3
#define Z_STEP_BIT         4  // Uno Digital Pin 4
#define X_DIRECTION_BIT    5  // Uno Digital Pin 5
#define Y_DIRECTION_BIT    6  // Uno Digital Pin 6
#define Z_DIRECTION_BIT    7  // Uno Digital Pin 7

Change to:
// Define pin-assignments
// NOTE: All step bit and direction pins must be on the same port.
#define STEPPING_DDR       DDRD
#define STEPPING_PORT      PORTD
#define X_STEP_BIT         5  // Uno Digital Pin 2
#define Y_STEP_BIT         6  // Uno Digital Pin 3
#define Z_STEP_BIT         7  // Uno Digital Pin 4
#define X_DIRECTION_BIT    2  // Uno Digital Pin 5
#define Y_DIRECTION_BIT    3  // Uno Digital Pin 6
#define Z_DIRECTION_BIT    4  // Uno Digital Pin 7

Now please save the file "config.h".

Then to be able to communicate between the stepper shield motor and the GRBL Controller, we have to program the arduino nano with the GRBL program.

Please upload and burn the bootloader with the basic program being:
 
#include <grblmain.h>
void setup(){
startGrbl();
}
void loop(){}
//Burn the code above to keyestudio nano ch340
 
After the above program is uploaded to the Arduino Nano, please download the GRBL Controller to be able to control the motor driver in a GUI via a computer.
 
 
Then install GRBL Controller on your Windows operating system to completion, then the display of the GRBL Controller is as follows:
 
Chip Piko Keyes CNC Shield V.4 GRBL Serta Cara Menggunakannya
 

H. Testing G-Code on Grbl Controller

Now we will test the GRBL that has been burned into the chip. Please connect the arduino Nano to the computer, then open the GRBL controller.
 
In the "Port name" form, select the detected Arduino Nano port name. Then setting the Baud Rate at a value of 9600.

And click the "Open" button.
 
After pressing the "open" button, the button turns red and the text is "Close/Reset", meaning that the GRBL controller has been connected to the Arduino Nano.
 
Now look at the picture below, the button circled by a red box.
 
Chip Piko Keyes CNC Shield V.4 GRBL Serta Cara Menggunakannya
GRBL Controller Testing (This image belongs to wiki.keyestudio.com)

The red box circled is the testing button, please click on the button and pay attention to the stepper motor.

If your stepper motor is moving. This means that the GRBL controller can be used.


I. Test G-Code on Grbl Controller Using G-Code File

 
Now we will test using a G-Code file.
 
Notice on the GRBL controller, you will see a "Choose File" button. Please click the button and please select the Gcode file.
 
For example in this article I selected one of the GCode files with the name "test.nc".
 
Then a review of G Code will appear on the right menu. Then click "Begin", then you will see the process will take place on the left. Look at the following picture:
 
Chip Piko Keyes CNC Shield V.4 GRBL Serta Cara Menggunakannya
Testing Kontroller GRBL

Good luck. Thank you for visiting the website Chip Piko.

If you found this article useful, you can share it using the following buttons:

Post a Comment for "Keyes CNC Shield V4 GRBL How To Use It"