A4988 with nema 17 only one direction

Im using driver a4988 with nema 17 stepper, 17hs4023 . For some reason my stepper only goes in one direction even though I am setting the direction pin to LOW.

Could it be I got it wrong wired? Im running out of ideas

it is connected like this:

// Define pin connections & motor's steps per revolution

const int dirPin = 2;
const int stepPin = 3;
const int stepsPerRevolution = 1000;

void setup()
{
  // Declare pins as Outputs
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
}
void loop()
{
  // Set motor direction clockwise
  digitalWrite(dirPin, HIGH);

  // Spin motor slowly
  for(int x = 0; x < stepsPerRevolution; x++)
  {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(2000);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(2000);
  }
  delay(1000); // Wait a second
  
  // Set motor direction counterclockwise
  digitalWrite(dirPin, LOW);

  // Spin motor quickly
  for(int x = 0; x < stepsPerRevolution; x++)
  {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(1000);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(1000);
  }
  delay(1000); // Wait a second
}
1 Like

You have connected pins 2 and 3 but your code is using 3 and 4.

To what value did you set the all-important driver current limit?

What happens if you set dirPin HIGH?

sorry, just a typo. it is correct connected

0,56 v according to
Vref = Imax * 8 * 0.1
Vref = 0,56 v

What happens if you set dirPin HIGH?
Still the same direction no matter if I set it to LOW or HIGH

I'm surprised the stepper moves at all. There's no power to the controller.
As already replied, not being able to read the pin designations, things are uncertain. That's the difference between real schematics and toy pictures like Fritzings.

In my opinion, checking up quite a number of steppers, one of the stepper 1000 delays could by raised to 5000, 6000. Know that the active pulse can be some microseconds, the other delay is the real step delay.

dont understand what you mean

Remembering one faulty stepper. Use a DMM and measure the resistance in the 2 stepper coils. Once one wire was off inside the plastic insulation.

That could work if the current sense resistors are 0.1 Ohms. Did you check the actual values of the resistors, and Vref?

In the picture there is no power feeding the controller. Too often problems start at that point.

yes I check the resistors on the driver. it is correct

well there is 12v 2 ampere powersupply if that is what you are asking?

That's good for the stepper. Where is the power for the controller? Nothing visible in the picture.

Are you asking me if my arduino have got power?? in that case ... yes

ok I found the problem. Pin number 3 on arduino is corrupt. I tried with pin 4 instead but that didnt work. Dont know why. Worked as soon as I switched to another arduino

No. Actually how!
Trying the best to help members for quite some time You have no idea how often inadequate powering has been the reason for failure. It's a question based on knowledge. You didn't answer it. Too many members having inadequate powering have been totally unaware of the mistake claiming powering is okey.
Without a verified proper powering all further investigation is a waist of time, bringing no help to the member.

1 Like

Well done! Buying some 20 UNOs, all clones, I've never been facing that.