Moving 2 steppers at the same time?

Im trying to control 2 steppers at the same time using this sketch, but they don't move together, first one motor completes its rotation and then the other:

#include <Stepper.h>

const int step1 = 234; // random steps
const int step2 = 343; //random steps                             

Stepper myStepper1(200,2,3,4,5);
Stepper myStepper2(200,8,9,10,11);       

void setup() 
{
 
  myStepper1.setSpeed(60);
  myStepper2.setSpeed(60);
 
}
void loop() 
{
 
  myStepper1.step(step1);
  myStepper2.step(step2);
  delay(500);    
}

So i searched online and i found a solution using the For Loop:

for(int s=0; s<steps; s++)
{
  myStepper1.step(1);
  myStepper2.step(1);
}

but unfortunately this is not suitable for my application as the number of steps i want my 2 motors to move is different.

Is there any way i can control them together?

I'm not clear what effect you're trying to achieve.

I guess you want both motors to start together. Do they move at the same speed? Do they stop at the same time?

i dont think the stepper library was written for that.

Not exactly sure how you drive them,
and i think a tiny dependency should exist because you wont be able to set 2 pins at the same time.
but since normal code runs fast, it shouldnt be noticable. .. hmm or maybe it is possible read on..

it depends a bit on how you drive the stepper engine, directly by the arduino (not good, will most !! likely !! damage your arduino)
So by some logic chip (like L297) which drives another chip that can control more current .. L298 or something else like http://arduino.cc/forum/index.php/topic,117033.0.html (if you can get a l298 pit probably a better choice (also more expensive)

if you have like 2 L297 it should be easy to control them have each set the step mode you want set the direction you want, and AFTER that provide them both with the same pin that provides your clock (high / low pinout cycle).. this way they are in sync in think.
the l297 even got an extra option on the IC (find datasheet), to do improve sync actions (basicly conecting 2 clocks i think).

I have a program that calculates the number of steps motor1 and motor2 would have to move, now when i try to move the motors simultaneously it doesnt work, motor1 moves first and after it complete its steps motor2 begins its. I simply want them to move together.

Im using 2 L293d to control the stepper motors.

What about

if (steps1 > steps2) {
  for (int i=0; i<steps2; i++) {
    mtr1.step(1);
    mtr2.step(1);
  }
  mtr1.step(steps1-steps2);
}
else if (steps 2 > steps1) {
  // Same thing
}
else {
  // if they're the same
}

Wow, a simple solution to a complex problem :D, im going to try that now and tell you, my only concern is the speed of the motor maybe.

Another thing is that the value of steps can also be negative, but this code will not work for negative values, example: if step1 = 322, and step2=-322, both motors wont move at all would they?

my solution would be able to handle it, they would be in sync rotating and also be able to handle reverse turning, or for example one forward and the other backward at the same speed, and a cycle later just still at the same speed both forward.

only drawback it requires some additional IC's, one costed me 4.5 euro the darlingtion pair 0,70 makes 5,20 but you want 2 motors 10,40 plus 2 times resistor 22k ohm and 2 times 3,3 nf condensator.

Still your main control would be from the arduino, but the commands you would use would be a lot simpeler. (pulse, direction, clock)
where clock would be shared, so for 2 bipolar motors 5 arduino pins.

but maybe it isnt that important to be in sync, main reason i choose for this is that i can use stronger current and keep my program at the arduino smaller.

(like you at moment i'm in building stage, over a few days or more it will be ready)

adilmalik:
Wow, a simple solution to a complex problem :D, im going to try that now and tell you, my only concern is the speed of the motor maybe.

Another thing is that the value of steps can also be negative, but this code will not work for negative values, example: if step1 = 322, and step2=-322, both motors wont move at all would they?

Here's a more elegant solution, which works for negative numbers:

while (steps1 || steps2) {
  if (steps1 > 0) {
    mtr1.step(1);
    steps1--;
  }
  else if (steps1 < 0) {
    mtr1.step(-1);
    steps1++;
  }
  if (steps2 > 0) {
    mtr2.step(1);
    steps2--;
  }
  else if (steps2 < 0) {
    mtr2.step(-1);
    steps2++;
  }
}

Hmm, well, not as elegant as I hoped. There might be a way to use the sign function (1 if positive, -1 if negative, 0 if 0) to step, but the counting would get difficult.

The stepper library does not seem to be designed to support concurrent movement of multiple stepper motors. What is does do is move one motor a specified number of steps at a specified speed and wait until the movement has completed.

Maybe there's a better stepper library somewhere. But using the library you already have, it may be possible to get an acceptable solution as long as the speed of the stepper motors is relatively slow: just have your sketch move each stepper motor one step at a time, and loop around moving each stepper motor until it's moved the required number of steps.

I expect this requirement is the same for any CNS style solution and maybe there's a better library or a better way to use the existing library, but that's the best approach I can see.

Here's a more elegant solution, which works for negative numbers:
Code:
while (steps1 || steps2) {
if (steps1 > 0) {
mtr1.step(1);
steps1--;
}
else if (steps1 < 0) {
mtr1.step(-1);
steps1++;
}
if (steps2 > 0) {
mtr2.step(1);
steps2--;
}
else if (steps2 < 0) {
mtr2.step(-1);
steps2++;
}
}

Hmm, well, not as elegant as I hoped. There might be a way to use the sign function (1 if positive, -1 if negative, 0 if 0) to step, but the counting would get difficult.

Thankyou Again, ill try this asap.

I expect this requirement is the same for any CNS style solution and maybe there's a better library or a better way to use the existing library, but that's the best approach I can see.

There is a library called AccelStepper Library, but i have had no success with it. I can control my motors together, but there are erratic accelerations and decelerations. They say its something to with the arduino being slow, so the stepper misses a few pulses.