laurb9 / StepperDriver

Arduino library for A4988, DRV8825, DRV8834, DRV8880 and generic two-pin (DIR/STEP) stepper motor drivers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

I want to Move two steppers motors in sequence

adrianastrippoli opened this issue · comments

Describe the bug
The code is aimed to move a motor 1 forward, then, move a motor to forward and back, then, move the motor 1 back.

To Reproduce
Steps to reproduce the behavior:

  1. #include <Arduino.h>

#define MOTOR_STEPS 20
#define RPM 1200 //max value 3000
#include "DRV8834.h"
#define DIR 8
#define STEP 9
DRV8834 stepper(MOTOR_STEPS, DIR, STEP);//M0, M1

#define MOTOR_STEPS2 20
#define DIR2 4
#define STEP2 5
DRV8834 stepper2(MOTOR_STEPS2, DIR2, STEP2);//M0, M1

void setup()

{
stepper.begin(RPM);
stepper.enable();
}

void loop()

{
//stepper.setMicrostep(1);
//One complete reolution is 360°
//stepper.rotate(360); // forward revolution
// One complete revolution is also 50MOTOR_STEPS steps in full step mode
stepper.move(50
MOTOR_STEPS); // forward revolution
//stepper.move(-50*MOTOR_STEPS); // reverse revolution
delay(1000);

stepper.begin(RPM);
stepper.enable();

stepper.move(50MOTOR_STEPS2); // forward revolution
stepper.move(-50
MOTOR_STEPS2); // reverse revolution
delay(1000);

stepper.begin(RPM);
stepper.enable();

//stepper.move(50MOTOR_STEPS); // forward revolution
stepper.move(-50
MOTOR_STEPS); // reverse revolution
delay(1000);

while(true);
}

Expected behavior
I expect the 2nd motor to move back in the 4th sequence. but the code does not allows me to declare the pin of the arduino again for the 2nd time.

Platform Setup (please complete the following information):

  • Arduino UNO
  • Stepper Driver DRV8834
  • Stepper Motor NEMA8

Additional context
I just want to know how to move the 1st motor again to reverse, after i move the 2nd one.

Pls your help

I think you want to use stepper2 when moving the second motor, instead of stepper.

something like

void setup() {
  stepper.begin(RPM);
  stepper.enable();
  stepper2.begin(RPM);
  stepper2.enable();
}

void loop() {
  stepper.move(...); // moves first motor

  stepper2.move(...); // moves second motor  

} 

Also, while it is not important here because you do not use rotation methods, may still want to double check the value for MOTOR_STEPS. It is by definition the number of steps the motor makes in a single complete revolution. Common steppers usually have 200 steps.

commented

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.