Stepper motors (Nema-17) wont run at the same speed

So in my project i need to drive a robot car at straight line .I am using Nema-17 motors and DRV8825 drivers

PROBLEM :
is that my left motor wont run at the same speed as the right one. its also missing steps (the left one ) at random rate .

CONFIGURATIONS :
For the power i am using a 12V li-ion battery with the drivers beeing connected in parallel with the power supply cause many tutorials seems to use that kind of connection .

I've already configured the Amps given from my drivers to the motors guided by the datasheet of my motors

CONCLUSION:

I think that the problem has something to do with my code and not the power i am giving to drivers

THE CODE :



#define MotorSteps 200

#define DIR_l 9
#define DIR_r 2
#define STEP_l 10
#define STEP_r 3



void setup(){

  pinMode(DIR_l, OUTPUT);
  pinMode(DIR_r, OUTPUT);  
  pinMode(STEP_l, OUTPUT);
  pinMode(STEP_r, OUTPUT);  
  
  }

void loop(){
  digitalWrite(DIR_l, LOW);
  digitalWrite(DIR_r, HIGH);

  
  for (int x= 0 ; x<MotorSteps ;x++){
    digitalWrite(STEP_l ,HIGH);
    digitalWrite(STEP_r ,HIGH);
    delayMicroseconds(2000);

    digitalWrite(STEP_l ,LOW);
    digitalWrite(STEP_r ,LOW);
    delayMicroseconds(2000);
    }
  
}

I'm not a stepper kind of guy, but there must be more to synchronization than On/Off as there is a library for that purpose:

https://youtu.be/Fzt75I_Zi14

Ideal would be if You had supplied schematics and link to power supply, drivers, motors. Especially the power supply needs to be verified.
I suggest raising the second delay to some 20000 as a beginning.
The 2000 for a still standing motor this might be too little and steps are missed.
Could You make a test version of the code, only running one motor at the time and check the RPM? This might tell whether the power source is up to the job or not.

1 Like

You lack speed-ramping, so the motors are going to miss-step(*). Try the AccelStepper library which provides acceleration (ramping) for you.

(*) Unless the steppers are absolutely tiny, or you only get them going at a few tens of rpm. Basically the laws of physics require the step rate to increase smoothly as the rotor starts to spin, otherwise the steps will get too far ahead of the rotor and the motor simply loses lock. (This then results is many forms of misbehaviour from stalling, intermittent running, running at the wrong speed or even backwards).

I seperated the motors .. i mean i powered the 2 motors alone and again the left motor works slower than the right one

i also swapped the driver of the left and placed it on the right but again the same result
(i placed drivers by default after this try )

2nd try i swapped left motor with the right and now the left (placed on the right driver) is running faster

Have you any idiea why is this happening ?

Did You try reply #3?
What happens when You do?

if you mean Marks solution i havent try it yet cause i have no clue how to use this lib and i am still searching
have you any idea where i can find some answers?

What about the two nema 17 are they the same, have you messured the impedance on both, are they the same ?

No. Reply #3 was from me. Try again. Increase the second delay by a factor 10 or more, as a first try. Do this for both motors.

yeah the motors have the same impadance and i bought them together from amazon

Nothing changed by increasing the delay

Have you any source where i can find info about how to use this lib ??

Hi,
Welcome to the forum.

Can you post link to specs/data on your steppers please?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Please include power supplies, component labels and pin names.

Hand drawn and photographed is perfectly acceptable.
Please no Fritzy pictures.

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

Which Arduino?

Okey. Not the biggest surprise. Stepping too fast steppers mostly don't move at all, only make a squeaking sound. Of course an increased demand for torque might stall the stepper and make it buzz.
New game, new bets.

A desperat and likely wrong suggestion.... Are the two stepper driver channels set up for the same stepping rate? I think about one using 16 micro stepping and the other 8...

both are using 1/16 micro stepping

I'm somewhat confused.

Does the problem follow the motor or the driver?

Is the problem with a motor/driver specific pair?

Is the problem related to the coding and which motor/driver is called first or second in the code?

I suggest a temporary test, using single step for both.
You have been swapping drivers in one try and motors in the other. You ought to know by now if the fault follows the motor or the driver.
Too many tests gives too many words and it's hard get here.
Report each test, one by one like thsi:

Keep the drivers connected to the same lines during the 2 tests!
Setup1) Driver 1 + motor A, driver 2 + motor B: Fastest is ......
Setup2) Driver 1 + motor B, driver 2 + motor A: Fastest is ......

Swap driver connections to the controller!
Setup1) Driver 1 + motor A, driver 2 + motor B: Fastest is ......
Setup2) Driver 1 + motor B, driver 2 + motor A: Fastest is ......

Do you have any idea what "Nema-17" means? :thinking: