Step motors working, but not at the same time.

Hi everyone, I have 2 step motors (28BYJ-48) that I have moving clockwise and counter clockwise 180 degrees. They are at the perfect speed, and the arc looks great. my problem is that they are not running simultaneously. Is there a way to do this in my current code? Thank you!

#include <Stepper.h>

const int stepsPerMotorRevolution = 32; //No of steps per internal revolution of motor,
//4-step mode as used in Arduino Stepper library

const int stepsPerOutputRevolution = 32*64; //no of steps per revolution of the output shaft

const int motorpin1 = 8; //Assign motor (ie board) pins to Arduino pins
const int motorpin2 = 9; //
const int motorpin3 = 10; //
const int motorpin4 = 11; //

const int motorpin5 = 4; //Assign motor (ie board) pins to Arduino pins
const int motorpin6 = 5; //
const int motorpin7 = 6; //
const int motorpin8 = 7; //

// initialize the stepper library on pins 8 through 11, Motor rev steps, "Firing" sequence 1-3-2-4,
Stepper myStepper1(stepsPerMotorRevolution, motorpin1,motorpin3,motorpin2,motorpin4);
Stepper myStepper2(stepsPerMotorRevolution, motorpin5,motorpin7,motorpin6,motorpin8);

void setup() {
// Stepper library sets pins as output

myStepper1.setSpeed(600); //Set the speed
Serial.begin(9600); // initialize the serial port:
myStepper2.setSpeed(600);
Serial.begin(9600);
}
// MAIN LOOP +++++++++++++++++++
void loop() {
// Half revolution clockwise
Serial.println("clockwise 1/2 rev");
myStepper1.step(stepsPerOutputRevolution/2);
delay(10);
// Half revolution counterclockwise
Serial.println("counterclockwise clockwise 1/2 rev");
myStepper1.step(-stepsPerOutputRevolution/2);
delay(10);

// Half revolution clockwise
Serial.println("counterclockwise 1/2 rev");
myStepper2.step(-stepsPerOutputRevolution/2);
delay(10);
// Half revolution counterclockwise
Serial.println("clockwise 1/2 rev");
myStepper2.step(stepsPerOutputRevolution/2);
delay(10);

}

The standard Stepper library is very basic. Try the AccelStepper library. It's run() function can control several motors simultaneously.

Be sure to study the examples as its usage is different from the Stepper library,

If you really do want to stay with the standard Stepper library then you will need to make the motors move one step at a time and manage the step timing yourself.

...R

Robin2:
The standard Stepper library is very basic. Try the AccelStepper library. It's run() function can control several motors simultaneously.

Be sure to study the examples as its usage is different from the Stepper library,

If you really do want to stay with the standard Stepper library then you will need to make the motors move one step at a time and manage the step timing yourself.

...R

And if you want them to step together, then you will have to interleave the coding for both motors, not do one and then wait and then do the other and wait and expect them to step at the same time.

Paul

Paul_KD7HB:
And if you want them to step together, then you will have to interleave the coding for both motors, not do one and then wait and then do the other and wait and expect them to step at the same time.

Thanks. That's what I intended to convey, but I should have been explicit.

...R

Robin2:
Thanks. That's what I intended to convey, but I should have been explicit.

...R

Just watching your back!

Paul

Following