2 steppers simultaneously but inverse

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.

  1. Is it possible to switch wires on the driver or on the motor (maybe even with only one driver needed)?
  2. 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.

This is the step sequence for a 28BYJ-48 motor

switch(stepSequence){
    case 0:
         digitalWriteFast(motorPin1, HIGH);
         digitalWriteFast(motorPin2, HIGH);
         digitalWriteFast(motorPin3, LOW);
         digitalWriteFast(motorPin4, LOW);
        break;
    case 1:
         digitalWriteFast(motorPin1, LOW);
         digitalWriteFast(motorPin2, HIGH);
         digitalWriteFast(motorPin3, HIGH);
         digitalWriteFast(motorPin4, LOW);
        break;
    case 2:
         digitalWriteFast(motorPin1, LOW);
         digitalWriteFast(motorPin2, LOW);
         digitalWriteFast(motorPin3, HIGH);
         digitalWriteFast(motorPin4, HIGH);
    break;
    case 3:
         digitalWriteFast(motorPin1, HIGH);
         digitalWriteFast(motorPin2, LOW);
         digitalWriteFast(motorPin3, LOW);
         digitalWriteFast(motorPin4, HIGH);

    break;
}

If you work through it in the order 0123 0123 it will move one way. If you go 3210 3210 it will go the other way. As far as I can see that cannot be achieved by wiring one motor one way and the other motor another using the same 4 signal wires.

In this link there is a wiring diagram for controlling a 28BYJ-48 using two signal wires. I have not tried it but it could be that this would allow opposite directions if the connections are reversed. Alternatively it would simply allow the two motors to be controlled separately with 4 Arduino pins if you are short of I/O pins

...R

Thank you for the answer. I now went the 'normal' way and use 4 data wires for each stepper.

Interesting observation: I bought several 28byj-48 stepper motors from different shops (and obviously different manufacturers). Some turn clockwise and the others counterclockwise with the same data wires. Using that could be a solution for others but I now decided to use only steppers from the same manufacturer.