Nema 17 and A4988 barely spinning/vibrating one direction

Hello fellow Arduino users,

I'm working on a small project involving a Nema 17 stepper motor and the A4988 driver(hiletgo). The motor spins one direction no problem, but when it goes to spin the opposite direction the motor has a horrible vibration sound and barely moves the shaft. The schematic and code will be linked below. I can attach a video as well if that helps. Any feedback would be great. I adjusted the onboard potentiometer so that the Vref is 1.2 volts which is what a source told me to set it to. Power supply was set to 10 volts, I can adjust current if needed. I believe when the motor was running it was pulling about 0.5 A. Any help would be wonderful thank you!

// Define pin connections & motor's steps per revolution
const int dirPin = 2;
const int stepPin = 3;
const int stepsPerRevolution = 200;

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
}

You need to adjust the power supply current to maximum, since the A4988 regulated the motor current. Don't regulate the current twice!

1 Like

Ahhh okay that makes perfect sense. I will test that when I get home and see what happens. I apprecaite the help!

Try

digitalWrite(stepPin, HIGH);
delayMicroseconds(10);//Gives a 10 mikrosecond pulse
digitalWrite(stepPin, LOW);
delayMicroseconds(10000);// Gives 100 steps per second.

2 Likes

Railroader,

You are a life saver. The issue just seemed to be timing. I guess I never noticed it before, but everything works great now. Thank you!

1 Like

Great! Thanks a lot for telling!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.