Multiple stepper motors

I have just made one circuit for the Unipolar stepper motor using the L293B driver chip with arduino using the following code
#include <Stepper.h>

// steps value is 360 / degree angle of motor
#define STEPS 200

// create a stepper object on pins 4, 5, 6 and 7
Stepper stepper(STEPS, 4, 5, 6, 7);

void setup()
{
}

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

However i intend to control five stepper motors simultaneously with the Arduino,what do i have to change in the code ,i first want to try it out with two stepper motors so far i have two circuits of the L293B,but i am still puzzled in the code.

You will likely run into problems with the Delay's when trying to control multiple motors.

Look at the example in the playground called "blink without delay" it shows one way to deal with it.

I have some experience with steppers, bipolar only and unfortunately not with the l293 nor with Tom Igoes library found in the standard examples.

If it works a bit like most other libraries this may be… an example to drive 2 motors.

#include <Stepper.h>
 
// steps value is 360 / degree angle of motor
#define STEPS 200
 
// create a stepper object on pins 4, 5, 6 and 7
Stepper stepper1(STEPS, 4, 5, 6, 7);
Stepper stepper2(STEPS, 8, 9, 10, 11);
  
void setup()
{
}

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

In Toms example code he didn’t use delays, not using them is often the best…, but I just adapted your code a little, left the delays in the code and besides controlling the steppers it should just wait for a small moment after each turn.
Hope this works, if you don’t have 2 steppers yet you could run the example with 1, take all power of the board and circuits (!) after the first test, connect the circuitry to the arduino pins of the second motor and… power the whole circuit again.

By the way… I do guess this example won’t give you steppers operating really simultaneously, because of the stepper.step() function. In the example it uses 200 and -50 steps (whole and quarter turn), while 1 motor is turning I expect the other to be motionless.

It is possible to drive both at the same time by sending the right pulses to those 8 pins, but you’ll need to check out how this works with your steppers and probably need to write routines to adjust speed.

The problem with the reliance on libraries is that you become stuck when you need to do something that the library was not designed to cope with. You get a false sense that you know what you are doing.

i intend to control five stepper motors simultaneously

So do these need to operate all at the same time? If so it is comparatively easy, you work out what motor needs to move the furthest, and then for the others work out the fractional increment you have to apply in order for them to complete their movement in the same time as the main motor. This is very similar to drawing a straight line between two points on a display.

The fractional increment is applied to each motors total an only when the total moves over one integer do you actually step the motor. For example suppose you want to move motor 1 by 800 steps and motor 2 by 200 steps. The fractional increment will be 200 / 800 = 0.25. So for each step of the main motor you add 0.25 to motor2's position. Only actually step motor2 when the integer part of this increases.

Hi guys;

@Uganda

Since the Arduino can not do things at the same time like a pentium, I assuming your stepper motor will be running at different paterns ex: one motor run a bit, the other run a lot , the others in the middle. So what about each motor has it own controller ( microcontroller + step-motor interface ) , it simply wait for instructions and send a reply, kind of Master controlling multi slave units. ( I2C ? ) end each slave has it own ID. So you send intruction to one unit ( ID code + instructions codes ) and reply ( results + ID code ) , a commun Transmit Bus and a Receiving Bus and GND line and Power line.

Just an idea.

@jgatvi, you have added your question to a 4 year old Thread. I have asked the Moderator to split it off into a new Thread.

Please post a link to the datasheets for your motors and for your stepper drivers.

Don't read the serial input for one motor at a time. Read all the input data and then control the motors with the data you have received. The examples in serial input basics may be useful.

Look at how the code is organized into separate small functions in Planning and Implementing a program. By keeping things separate you can easily test each part on its own.

...R