Step motor shifting/ misstepping

İ am using a4988 step motor driver and 17hs4401 step motor. İ will use them in a system. before it, i made i simple test. Just make 1 revolution every in 3 seconds. But motor had shifted around 10 degree in every hour. There was no load at the motor. İs there any way to reduce this?

  1. is this because of motor or driver?
  2. is this reduce if i use half step or quarter step?
  3. my budged is low, so may be i added rotary encoder is this a good solution?

4)(+ question)when upload empty code to my Arduino, motor wiggling turn slowly? Or just in setup function, i still turning. Why is this happening

İ am using Arduino mega

// 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(3000); // Wait a second


	
	
}

The speed might be too high. Usually the pulse itself can be 10 microseconds but the other delay, deciding the speed. I would try 10 mS, 10 000 microseconds.

Oh i will definitely try this thank you so much. So is there any chance to make damage motor or driver if i increase this time let's say 50 Ms? İs there any upper limit?

Sending the pulses at a too high frequency the motor will only make noise but not move. Stopping and starting are the most critical parts.
Read the datasheets and lok for "pull in" and "pull out". That's the maximum rate versus a stand still.

No, no risk for damaging the stepper.

Why not use the AccelStepper library? They have an lots of examples. Since you are using a driver, you declare your stepper as

#include <AccelStepper.h>

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

//AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
AccelStepper stepper(AccelStepper::DRIVER, stepPin, dirPin);

void setup()
{  
   stepper.setMaxSpeed(1000);
   stepper.setSpeed(50);	
}

void loop()
{  
   stepper.runSpeed();
}

Have you set the A4988's current limit to match the stepper's 1.7 Amp rating? What is your power supply voltage and current rating?

İ make vref=0.68 volt as recommended. İs it wrong?

Why i need to use it? I thought that i don't need this , did i?

What does that mean in terms of current (Amps)? What power supply (volts and current)? What voltage do you read across the motor leads?

İ intentionally said vref because i am not sure it's corresponding amp value. As far as i know(not %100 sure) amp =vref x 2.5 and that is 1.7 amp

What voltage do you read across the motor leads?
3rd & last request:
What power supply (volts and current)?

Sorry, my power supply is 12 v 5 amp
How can I read motor leads voltage? Because it is changing so fast.

With the motor enabled but not stepping (standing still), measure (carefully) from 1A to 1B and 2A to 2B. Motor winding resistance is 1.5 Ohms, times 1.7 Amps, volts should be around 2.5V.

The A4988 cannot deliver 1.7A, so it may be overheating and shutting down. Set the current limit to 1 Ampere, maximum.

Also, unless you are using the original Pololu A4988 driver, the current limit Vref setting that they recommend will probably not work. The formula (see the A4988 data sheet) depends on the current sense resistor, which is different for different board manufacturers.

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