The first thing to do is to set the coil current limit on the A4988 stepper driver. The coil current should be found in the motor data sheet. Set the current to less than or equal to the spec current. To set the current limit you will need to know the value of the sense resistor on the A4988 driver board. Then enter the value of the resistor and the required coil current into the formula Vref = Imot x 8 x Rsen where Imot = the coil current and Rsen = the value of the sense resistor. The Pololu A4988 page covers how to set the Vref but you must use the sense resistor value on YOUR board. This page shows how to locate the sense resistor.
Then load and run this (slightly modified) simple stepper test code from Robin2's simple stepper code tutorial.
// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// this version uses delay() to manage timing
const byte directionPin = 5; // **** change to suit
const byte stepPin = 2; // **** change to suit
const byte enablePin = 8; // **** change to suit
int numberOfSteps = 100;
byte ledPin = 13;
int pulseWidthMicros = 20; // microseconds
int millisbetweenSteps = 100; // milliseconds - or try 1000 for slower steps
void setup()
{
Serial.begin(9600);
Serial.println("Starting StepperTest");
digitalWrite(ledPin, LOW);
delay(500);
pinMode(directionPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, LOW);
pinMode(ledPin, OUTPUT);
digitalWrite(directionPin, HIGH);
for (int n = 0; n < numberOfSteps; n++)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(pulseWidthMicros); // this line is probably unnecessary
digitalWrite(stepPin, LOW);
delay(millisbetweenSteps);
digitalWrite(ledPin, !digitalRead(ledPin));
}
delay(3000);
digitalWrite(directionPin, LOW);
for (int n = 0; n < numberOfSteps; n++)
{
digitalWrite(stepPin, HIGH);
// delayMicroseconds(pulseWidthMicros); // probably not needed
digitalWrite(stepPin, LOW);
delay(millisbetweenSteps);
digitalWrite(ledPin, !digitalRead(ledPin));
}
}
void loop()
{
}
The motor should rotate 1/2 turn one way (200 step/revolution motor) wait 3 seconds and rotate 1/2 turn the other direction.