Sample script of using CNC Shield V3 for Arduino UNO

A4988 Stepper Driver Configuration

M0M1M2Resolution
Full Step
Jumper1/ Step
Jumper1/4 Step
JumperJumper1/8
JumperJumperJumper1/16

The following code will run X Y Z axis motors by using the pinout:

// The script is being used to test Shield V3.0 with Arduino UNO
#define EN 8 //Stepper Motor Enable Pin
// #define X_DIR 5 //X Direction
// #define Y_DIR 6 //y Direction
// #define Z_DIR 7 //z Direction
// #define X_STP 2 //x Stepper
// #define Y_STP 3 //y Stepper
// #define Z_STP 4 //z Stepper

#define X_DIR 5
#define X_STP 2

#define Y_DIR 6
#define Y_STP 3

#define Z_DIR 7
#define Z_STP 4


void step(boolean dir, byte dirPin, byte stepperPin, int steps)
{
digitalWrite(dirPin, dir);
delay(50);
for (int i = 0; i < steps; i++) {
  digitalWrite(stepperPin, HIGH);
  delayMicroseconds(800);
  digitalWrite(stepperPin, LOW);
  delayMicroseconds(800);

}
}
void setup(){//Setup Related Pins as OUTPUT
  pinMode(X_DIR, OUTPUT); pinMode(X_STP, OUTPUT);
  pinMode(Y_DIR, OUTPUT); pinMode(Y_STP, OUTPUT);
  pinMode(Z_DIR, OUTPUT); pinMode(Z_STP, OUTPUT);
  pinMode(EN, OUTPUT);
  digitalWrite(EN, LOW);
}

void loop(){
  step(false, X_DIR, X_STP, 200); // X, 200 Steps = 360°, Clockwise 
  step(false, Y_DIR, Y_STP, 200); // Y, 200 Steps = 360°, Clockwise 
  step(false, Z_DIR, Z_STP, 200); // Z, 200 Steps = 360°, Clockwise 
  delay(1000);
  step(true, X_DIR, X_STP, 200);  // X, 200 Steps = 360°, Counterclockwise 
  step(true, Y_DIR, Y_STP, 200);  // Y, 200 Steps = 360°, Counterclockwise 
  step(true, Z_DIR, Z_STP, 200);  // Z, 200 Steps = 360°, Counterclockwise 
  delay(1000);
}

Leave a Comment