Stepper misses steps on low speeds

Hi guys,
I am using a stepper motor with an A4988 driver. I am using a potentiometer to change the speed using accel stepper library. However, as you can see, at low speed the stepper misses steps.
Any ideas?

Code:

#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper(AccelStepper::DRIVER,5,4);

// This defines the analog input pin for reading the control voltage
// Tested with a 10k linear pot between 5v and GND
#define ANALOG_IN A0
double lastTime=0;
double thisTime=0;
void setup()
{  
  stepper.setMaxSpeed(200);
  
}

void loop()
{     int analog_in = analogRead(ANALOG_IN);
      stepper.setSpeed(analog_in);
      stepper.runSpeed();
}

1000 rpm ?
Can you start with a maximum speed of 50 ?
And divide the value from analogRead() by 20 ?

Stepper may be overloaded/underpowered/driver current limit not set correctly.

I agree with you. I don't need 1000rpm. But the issue is at low speeds.

Think about how many times per second you are doing the analog read. Is this really necessary? The data sheet for the Arduino processor states the processor is STOPPED for two instruction cycles while the analog read is taking place. How many times will this take place while running the stepper at low speed?
Paul

1 Like

Changed the code. Still have the same issue.

I am sorry I am new to this. Can you please explain how that would affect the motor only at low speeds.

Momentum.

Something is very wrong with your setup, but you have provided no useful information about it.

AKA intrtia. Things at rest want to stay at rest. Your motor does rest between steps. The length of the rest time is what determines the rotation time.
Paul

If you change the code, post the new version so that we can keep up.

Read the forum guidelines to see how to properly post code.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

1 Like

Thank for you that. I have changed the code in the original post with correct formatting.

What information do you need?

Please do not change the code in any post. Changing the original post loses the continuity of the thread. Post the changed code in a new post.

1 Like

To start with, post a wiring diagram, giving the voltage and current capabilities of the stepper motor power supply, and state the value to which you set the current limit on the A4988 driver. Post a link to the motor data sheet.

Provide details on the mounting arrangement of the stepper. Is a gearbox involved?

How much does the robot weigh? Have you done the power/torque calculations on what is required to move it?

1 Like

I followed this wiring diagram


The power supply for motors is 12V, 3.2A
Datasheet: https://www.datasheet4u.com/datasheet-pdf/MotionKing/17HS4401/pdf.php?id=928661
Model: 17HS4401
I bought the wheels which can be mounted directly on the motor shaft.
Motors run on full-step mode
I am building a self-balancing robot which weights 1.2kg approx.
I am testing the motor program using a potentiometer and later I will hook it up with a PID program.

Revised code

#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper(AccelStepper::DRIVER, 5, 4);

// This defines the analog input pin for reading the control voltage
// Tested with a 10k linear pot between 5v and GND
#define ANALOG_IN A0
double lastTime = 0;
double thisTime = 0;
void setup()
{
  stepper.setMaxSpeed(200);

}

void loop()
{ thisTime = millis();
  if ((thisTime - lastTime) > 100) {
    lastTime = thisTime;
    int analog_in = analogRead(ANALOG_IN);
    stepper.setSpeed(analog_in);
  }
  stepper.runSpeed();
}

Are these wheels non-slip? Balance using the wheels will be difficult with slipping wheels.
Paul

1 Like

The information in reply #15 is helpful, but to what value did you set the all-important current limit on the A4988 (must be 1 Ampere or less)?

Note that doing so requires you to know the value of the current sense resistors on the driver, so please state that as well.

1 Like

Yes sir, plastic wheels with silicon 'tires'.

And the plastic is firmly attached to the steel motor shaft?
Paul

1 Like

Yes. I use these hubs on the motor shaft and these are mounted on hubs.