Hi community
I have two stepper motors (28byj-48) with a driver each (ULN2003A). Now I need to turn one motor counterclockwise and the other one anti-counterclockwise simultaneously.
Using 4 data wires each, 8 in common, it's possible to let it run as needed:
// Include the AccelStepper library:
#include <AccelStepper.h>
// Motor pin definitions:
#define motor1Pin1 1
#define motor1Pin2 2
#define motor1Pin3 3
#define motor1Pin4 4
#define motor2Pin1 5
#define motor2Pin2 6
#define motor2Pin3 7
#define motor2Pin4 8
#define MotorInterfaceType 8
AccelStepper stepper1 = AccelStepper(MotorInterfaceType, motor1Pin1, motor1Pin3, motor1Pin2, motor1Pin4);
AccelStepper stepper2 = AccelStepper(MotorInterfaceType, motor2Pin1, motor2Pin3, motor2Pin2, motor2Pin4);
void setup() {
}
void loop() {
stepper1.setMaxSpeed(1000);
stepper1.setAcceleration(500);
stepper1.moveTo(999999999999);
stepper1.run();
stepper2.setMaxSpeed(1000);
stepper2.setAcceleration(500);
stepper2.moveTo(-999999999999);
stepper2.run();
}
Now the goal is to run the two steppers as required without needing 8 wires in total.
- Is it possible to switch wires on the driver or on the motor (maybe even with only one driver needed)?
- Is it possible to declare the second motor with different pin sequence? For example:
#define motor1and2Pin1 1
#define motor1and2Pin2 2
#define motor1and2Pin3 3
#define motor1and2Pin4 4
AccelStepper stepper1 = AccelStepper(MotorInterfaceType, motor1and2Pin1, motor1and2Pin3, motor1and2Pin2, motor1and2Pin4);
AccelStepper stepper2 = AccelStepper(MotorInterfaceType, motor1and2Pin1, motor1and2Pin2, motor1and2Pin3, motor1and2Pin4);
(or something similar)
Thank you and best regards
Tesla
postscript:
Found this thread but I don't fully understand it. Changing + and - sounds obvious though, but I cannot figure out which wires (red, pink, yellow, pink, blue?!?) I need to switch... if it's possible with this motor at all. For the code part, J-M-L unfortunately doesn't describe the proceedure for my type of constructors.
According to the AccelStepper class reference, pin 2 (of the constructor) is the direction input.
[in] pin2 Arduino digital pin number for motor pin 2. Defaults to pin 3. For a AccelStepper::DRIVER (interface==1), this is the Direction input the driver. High means forward.
I haven't tested this yet but if I wire pin 2 seperately to the drivers while wiring all other pins together for the two motor drivers, it should work. If so, 5 wires totally were needed.