Issues with A4988

Hello, I’m trying to interface the A4988 with an arduino uno but I am having some issues. The A4988 is to drive a 200 step stepper motor. I have tried connecting the circuit as shown in this picture:
skpang.co.uk/catalog/images/ … 0J3360.png
But when I ran the code below, the stepper starts turning continuously in one direction without stopping (not just a single step at a time). I connected the STEP pin to an oscilloscope to make sure the arduino was doing just a single pulse and it looked exactly what it should be doing (a single pulse on for 800 us).
Also, when the power is cycled, the direction of the motor seems to change (seemingly random) even though the code should only move it in a single direction. In order to try and fix this, the DIR pin was grounded but now the directions change at a constant frequency (<1Hz) and it still moves more than one step before changing directions.

My code looks like this:

void step(boolean dir,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 loop(){
step(true, 1);
delay(200);
// step(false,1);
// delay(200);
}

Any help would be much appreciated! Thanks.

I forgot to mention that when I disconnected the step pin, the stepper didn’t move at all.

Hello.

I am sorry you are having problems with your stepper motor driver. How are you supplying power? Could you please attach a picture that clearly shows how you have made your electrical connections? Could you also post your complete code? (Please enclose your code with to structure it nicely on our forum.)