where is the error ???

Hi arduino members i need to connect 2 stepper motors to arduino uno , So that each one do different function ( speed control , sweep ) , i tried this code but only one of them is running well & the other one is making discrete steps without continuous motion i need to know what’s the error in this code ,
note that : i tried each code separately it’s working very well

#include <Stepper.h>

const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motors

Stepper stepper(stepsPerRevolution, 4, 5, 6, 7);

Stepper myStepper(stepsPerRevolution, 8,9,10,11);
int stepCount = 0; // number of steps the motor has taken

void setup()
{
}

void loop() {
stepper.setSpeed(60);
stepper.step(200);
delay(100);
stepper.setSpeed(20);
stepper.step(-50);

// read the sensor value:
int sensorReading = analogRead(A0);
// map it to a range from 0 to 100:
int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
// set the motor speed:
if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed);

// step 1/100 of a revolution:
myStepper.step(stepsPerRevolution/100);
}
}

see this video ( http://www.mediafire.com/download.php?3jwf9z651gguqmb ) to know the error exactly ,

cheers

( Not too happy about downloading a video file - would preer a YouTube or Vimeo link )

I'd prefer some better names rather than "stepper" and "mystepper" - Iike Xmove and Ymove or Swingarm and Lifter

The motors are doing what you ask them to: You move "stepper" a bot forward a bit backward. Then you move "mystepper".

The problem with the Stepper library is that the calls block - ie. no other code is executing while one motor moves. So the only way to get simultaneous movement is to call the two stepper motion with only one step, and the relative number of times you call them is the ratio you want the motors to move at.

any way i will purchase an extra arduino uno to do what i want ? , but what do u mean by ( only one step ) ???

thanks

No, one Arduino can comfortably control several steppers. The typical 3D printer uses 4 motors and one Arduino.

Your code at the moment does something like

Move StepperOne 200 units
Move StepperTwo 100 units

What you need is something more like

Repeat 200 times:
  Move StepperOne one unit
  Has StepperOne moved an even number of times?
    Yes - Move StepperTwo one unit

So yes, the program suddenly becomes more complicated. In my example above I have assumed a fixed ratio (2-to-1). You can have any ration (a rational fraction to be mathematical correct) with a bit of integer math to decied if the slower stepper needs to move a step.

is that what do u mean

#include <Stepper.h>

const int stepsPerRevolution = 100; // change this to fit the number of steps per revolution
// for your motors

Stepper stepper(stepsPerRevolution, 4, 5, 6, 7);

Stepper myStepper(stepsPerRevolution, 8,9,10,11);
int stepCount = 0; // number of steps the motor has taken

void setup()
{
}

void loop() {
stepper.setSpeed(60);
stepper.step(200);
delay(100);
stepper.setSpeed(20);
stepper.step(-50);

// read the sensor value:
int sensorReading = analogRead(A0);
// map it to a range from 0 to 100:
int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
// set the motor speed:
if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed);

// step 1/100 of a revolution:
myStepper.step(stepsPerRevolution/100);
}
}

At this risk of sounding a bit overbearing - have you tried to understand what is happening with a "blocking" call? My explanation may not have been clear, sorry about that.

Try and use the "#" button on the input editor so your code comes in a box, ie is surrounded by the "code" brackets. (it is not just pretty that way, there are some formatting issues, too)

Meanwhile, the problem is that you still use stepper.step(200);which does 200 steps, and while doing so does NOTHING ELSE. SO you have to "manually" in your program alternate between one step with one motor and one step with the other motor in an apprioate ratio

stepper.step(1);

unfortunately i tried it but in vain the same problem happened ,

thanks 4 help

Post that version of your code.