Re: Two motors and two steppers

I am also trying to control 2 x stepper motors with my UNO.
I have motor1 going to pins 8,9 and motor2 going to 10,11.
I have a button on pin 2.
When I press the button I want motor1 to rotate a certain number of times clockwise followed by motor2 rotating a quarter turn clockwise slower than motor1.
Then when I press the button again I want motor2 to return followed by motor1 and so on.
Can somebody help me with a code to do this as I am a complete novice and after hours of trying I cannot manage it.
Please help.....
Geoff

This is the program I am using for motor1 on pins 8,9.

int Distance = 0;
int Speed = 100;
int NumSteps = 200;
int MicroSteps = 160;
int FullRotation = NumSteps * MicroSteps;
int ButtonState = 0;
int OnOrOffState = 0;

void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(8, LOW);
digitalWrite(9, LOW);

}
void loop() {
ButtonState = digitalRead(2);
if (ButtonState == LOW){
OnOrOffState = 1;}

while(OnOrOffState ==1){
digitalWrite(9, HIGH);
delayMicroseconds(Speed);
digitalWrite(9, LOW);
delayMicroseconds(Speed);
Distance = Distance + 1;
if (Distance == FullRotation) {
OnOrOffState = 0;
if (digitalRead(8) == LOW){
digitalWrite(8, HIGH);
}
else{
digitalWrite(8, LOW);
}

Distance = 0;
delay(10);
}

}
}

GeoffBowes-Smith:
I am also trying to control 2 x stepper motors with my UNO.
I have motor1 going to pins 8,9 and motor2 going to 10,11.
I have a button on pin 2.
When I press the button I want motor1 to rotate a certain number of times clockwise followed by motor2 rotating a quarter turn clockwise slower than motor1.
Then when I press the button again I want motor2 to return followed by motor1 and so on.
Can somebody help me with a code to do this as I am a complete novice and after hours of trying I cannot manage it.
Please help.....
Geoff

You should start a thread of your own otherwise confusion will reign... And go and read the instructions
for posting - you haven't provided anything like enough information.

I am trying to control 2 x stepper motors with my UNO.
I have motor1 going to pins 8,9 and motor2 going to 10,11.
I have a button on pin 2.
When I press the button I want motor1 to rotate a certain number of times clockwise followed by motor2 rotating a quarter turn clockwise slower than motor1.
Then when I press the button again I want motor2 to return followed by motor1 and so on.
Can somebody help me with a code to do this as I am a complete novice and after hours of trying I cannot manage it.
Please help.....

pot.ino (897 Bytes)

OK - I presume you are happily controlling one motor at the moment - step+direction pulses by the look of it?

You need to abandon trying to do all the detailed timing yourself and go get the AccelStepper library. You can
have multiple instances driving different motors and do what you want when you want with them, as well
as setting speed and accelerations. Use the AccelStepper::DRIVER method to initialize when using
step + direction interface.

The AccelStepper library is probably the best solution.

However it is not difficult to manage the pulse timing without it. See the second example in this Simple Stepper Code. Note that the first example uses delay() and is only suitable for proving that a motor works.

...R
Stepper Motor Basics