laurb9 / StepperDriver

Arduino library for A4988, DRV8825, DRV8834, DRV8880 and generic two-pin (DIR/STEP) stepper motor drivers
MIT License
555 stars 228 forks source link

Bug. Two motors nema 17 do not rotate at the same time. #106

Closed EugenGavrisciuc closed 2 years ago

EugenGavrisciuc commented 3 years ago

Describe the bug So, if I want to use at the same time two different nema 17 motors and two different drivers (A4988 and DRV8825), the motors don't work correct. So, instead of rotating at the same time both motors, one of them is doing half of rotation and then stop. While the first stepper is "stopping" the second motor is doing too a half of rotation and then stops.

To Reproduce Steps to reproduce the behavior:

include

include "DRV8825.h"

include "A4988.h"

define MOTOR_STEPS_R 200

define RPM_R 120

define MOTOR_STEPS 200

define RPM 120

define MICROSTEPS_R 1

define DIR_R 48

define STEP_R 12

define MICROSTEPS 1

define DIR 49 // Pin 49

define STEP 9 // Pin 10

A4988 stepper(MOTOR_STEPS, DIR, STEP); DRV8825 stepper2(MOTOR_STEPS_R, DIR_R, STEP_R);

void setup() { stepper2.begin(RPM_R, MICROSTEPS_R); stepper.begin(RPM, MICROSTEPS); // Motorul pas cu pas }

void loop() { stepper.rotate(360); // Rotire jos stepper2.rotate(360); // Rotire jos }

Expected behavior At the same time, nema motors to rotate without problem.

Platform Setup (please complete the following information):

laurb9 commented 3 years ago

Thank you for providing the code and setup. The rotate() function in this library is blocking, it will wait to complete the motion before allowing the next step to continue. The motors moving in sequence is what should happen. If they are moving half-way only, it means the hardware microstep set for the board is most likely 2 and not 1.

There are two ways to move the motors together. The easiest is using the MultiDriver or SyncDriver shown in the MultiAxis example. The other is the Nonblocking example

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.