AccelStepper with multiple stepper motor

Hi,

I'm trying to write the code with the AccelStepper Library, I need to move some stepper motor drived by an uln2003 chip, for now I've done the moviment for each one separated, and it works...but I need to build some cycles to separate the operation, in one cycle move them toghether, and in another set for each one the position, all working at the same time, but when I create a cycle and move the code in all the motors works each one per time, when out of the cycle they work all toghether...can someone help me? Thanks in advance for the aviability, regards. Riccardo

Can I suggest that you post the code that you have already written with a clear explanation of what you want to happen and what actually happens.

Hi, this is the code to make a wave with four stepper:

#include <AccelStepper.h>

// Define some steppers and the pins the will use
AccelStepper stepper1(AccelStepper::FULL4WIRE, 0, 1, 2, 3); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
AccelStepper stepper2(AccelStepper::FULL4WIRE, 4, 5, 6, 7);
AccelStepper stepper3(AccelStepper::FULL4WIRE, 8, 9, 10, 11);
AccelStepper stepper4(AccelStepper::FULL4WIRE, 12, 13, 14, 15);

void setup()
{
stepper1.setMaxSpeed(1000.0);
stepper1.setAcceleration(150.0);
stepper1.moveTo(1500);
delay(0);
stepper2.setMaxSpeed(1000.0);
stepper2.setAcceleration(145.0);
stepper2.moveTo(1500);
delay(0);
stepper3.setMaxSpeed(1000.0);
stepper3.setAcceleration(140.0);
stepper3.moveTo(1500);
delay(0);
stepper4.setMaxSpeed(1000.0);
stepper4.setAcceleration(135.0);
stepper4.moveTo(1500);
}

void loop()
{
// Change direction at the limits

if (stepper1.distanceToGo() == 0)
stepper1.moveTo(-stepper1.currentPosition());
delay(0);
if (stepper2.distanceToGo() == 0)
stepper2.moveTo(-stepper2.currentPosition());
delay(0);
if (stepper3.distanceToGo() == 0)
stepper3.moveTo(-stepper3.currentPosition());
delay(0);
if (stepper4.distanceToGo() == 0)
stepper4.moveTo(-stepper4.currentPosition());
stepper1.run();
stepper2.run();
stepper3.run();
stepper4.run();
}

I'm trying to move the code of the void loop in two separate loop, that will be executed a number n of times and then switchto the next cycle, It's right what I'm trying to do? Thanks.

I'm trying to move the code of the void loop

Will people please STOP REFERRING TO THE LOOP() FUNCTION AS 'the void loop'.

It is not a void, it is a function. Function names are preceded by the type of data that the function returns. If the function does not return any data then it is referred to as void.

Whew. I feel better for that !

I'm trying to move the code of the void loop

Would you stop posting quotes in code tags?

Whew. I feel better for that ! :slight_smile:

:slight_smile: