Go Down

### Topic: 2 Stepper Moving Simultaneiously. (Read 1 time)previous topic - next topic

#### Gfast

##### Dec 06, 2012, 03:28 pm
Hello, Geeks!

I am working on a projekt, that need control two Steppers with two Potis. The Model is something like a balance. Ja as the topic say, the two stepper should work simultaneiously.

I look up so much much info. on the site.like
the Kritzler(http://tinkerlog.com/2011/09/02/der-kritzler/), accelstepper(http://www.open.com.au/mikem/arduino/AccelStepper/),
Interrup(http://www.uchobby.com/index.php/2007/11/24/arduino-interrupts/)

Some of them really done a perfect deep research. But I can still not get the very idea how to control them.
So, is anyone can share a tutorial about how to control two stepper simultaneously with accelstepp library(cause I am not a programmer, the C and C++ code is not that easy for me). Or just make a small sample here.
BTW. must I use the Interrupt to control the two motor?

gfast

#### johnwasser

#1
##### Dec 06, 2012, 06:19 pm
Code: [Select]
`void loop() {   unsigned long currentTime = millis();   // If it's time to step Motor 1...   if (motor1Stepping && (currentTime - lastMotor1Time > motor1Interval))      stepMotor1();   // If it's time to step Motor 2...   if (motor2Stepping && (currentTime - lastMotor2Time > motor2Interval))      stepMotor2();    // Do other stuff like figuring out which way and how fast to step the motors.    }`

Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

#### Gfast

#2
##### Dec 07, 2012, 02:44 pm

Code: [Select]
`void loop() {   unsigned long currentTime = millis();   // If it's time to step Motor 1...   if (motor1Stepping && (currentTime - lastMotor1Time > motor1Interval))      stepMotor1();   // If it's time to step Motor 2...   if (motor2Stepping && (currentTime - lastMotor2Time > motor2Interval))      stepMotor2();    // Do other stuff like figuring out which way and how fast to step the motors.    }`

Thanks??
After reading your codes and some sample, Last night I've really getting startted.

Hier is the little sample to share.

Code: [Select]
`// AFMotor_MultiStepper.pde// -*- mode: C++ -*-//// Control both Stepper motors at the same time with different speeds// and accelerations. // Requires the AFMotor library (https://github.com/adafruit/Adafruit-Motor-Shield-library)#include <AccelStepper.h>#include <AFMotor.h>// two stepper motors one on each portAF_Stepper motor1(200, 1);AF_Stepper motor2(96, 2);// you can change these to DOUBLE or INTERLEAVE or MICROSTEP!// wrappers for the first motor!void forwardstep1() {    motor1.onestep(FORWARD, SINGLE);}void backwardstep1() {    motor1.onestep(BACKWARD, SINGLE);}// wrappers for the second motor!void forwardstep2() {    motor2.onestep(FORWARD, SINGLE);}void backwardstep2() {    motor2.onestep(BACKWARD, SINGLE);}// Motor shield has two motor ports, now we'll wrap them in an AccelStepper objectAccelStepper stepper1(forwardstep1, backwardstep1);AccelStepper stepper2(forwardstep2, backwardstep2);void setup(){      stepper1.setMaxSpeed(300.0);    stepper1.setAcceleration(100.0);    stepper1.moveTo(240);        stepper2.setMaxSpeed(300.0);    stepper2.setAcceleration(100.0);    stepper2.moveTo(240);    }void loop(){    // Change direction at the limits    if (stepper1.distanceToGo() == 0)        stepper1.moveTo(-stepper1.currentPosition());    if (stepper2.distanceToGo() == 0)        stepper2.moveTo(-stepper2.currentPosition());    stepper1.run();    stepper2.run();}`

#### Gfast

#3
##### Dec 08, 2012, 10:31 pm
Cause I wanna the Balance to balance as a definite proportion between four different things . So I've changed the motor controller from Adafruit Motor shield to four A4988 Stepper Driver from Pololu.
And the result is pretty tricky.Till to three steppers, the Arduino code that written like the above works still well beside the low speed range. But if I defined four "AccelStepper" in the code.they seemed like they just block them from each another,and the motors stay still.
I searched Youtube the installation from other Guys. There is mainly two types of solution. One is use something like "A Big Chip, which have so many Pins" and the other changed the Arduino by a Board named ChipKit, which have a 80MHz work frequency.

I thought the Problem over, and decided to try ChipKit. But I'm not sure the circuit wired up right. So please check out the Picture. Thanks!!

Go Up