/*Arduino Sketch Controlling NEMA 17 Stepper Motor with A9488 driver
This code will help us control the stepper motor using the A9488 driver’s DIR and STEP pins.
*/
const int DIR = 6;
const int STEP = 7;
const int steps_per_rev = 200; // define the steps per revolution. This is the number of steps our motor requires to move one complete revolution.
void setup() {
Serial.begin(115200); // establish the serial connection between the development board at a baud rate of 115200.
// configure the digital pins connected with STEP and DIR as output pins.
pinMode(STEP, OUTPUT);
pinMode(DIR, OUTPUT);
}
void loop() {
// To control the direction of the motor we will use the digitalWrite() function and pass the DIR pin as the first parameter and the state of the pin as the second parameter. To move the motor in the clockwise direction a high signal is passed to the DIR pin.
digitalWrite(DIR, HIGH);
Serial.println("Spinning Clockwise...");
for(int i = 0; i < steps_per_rev; i++){
digitalWrite(STEP, HIGH);
delayMicroseconds(2000);
digitalWrite(STEP, LOW);
delayMicroseconds(2000);
}
delay(1000);
// To move the motor in the anti-clockwise direction, a low signal is passed to the DIR pin. Additionally, the serial monitor will display the direction of the motion of the motor.
digitalWrite(DIR, LOW);
Serial.println("Spinning Anit-Clockwise...");
for(int i = 0; i < steps_per_rev; i++){
digitalWrite(STEP, HIGH);
delayMicroseconds(1000);
digitalWrite(STEP, LOW);
delayMicroseconds(1000);
}
delay(1000);
}