Controlling 3 stepper motors diffrently at the same time

I'm making a project that involves having 3 stepper motors each running at its own speed and running time. I understand the basics of programming, but not this advanced.

Thanks in advance!

You have not provided much information about your project.

What stepper motors are you using? Post a link to their datasheet.
What stepper motor drivers are you using?
What are the motors being used for?

These links may help
Stepper Motor Basics
Simple Stepper Code

also look up the AccelStepper library

...R

Thanks for the reply

I am using this motor: http://qqtrading.com.my/stepper-motor-17hs-hybrid-series-2-phase-4-wire
and this driver: StepStick - RepRap

I only need 2 pins to make a singel motor work (STEP, DIRECTION)
I am trying to make a camera slider, one motor would be used to slide, one to rotate and one to zoom the camera.
The motors need to rotate at given speed and for given amount of time, but I only know how to make one rotate with given information, but not all three at the same time.
Is there a crucial command I'm misssing?

Please share some code to let us see how you are trying to make it work.

The only code I have made so far is 2328 lines long and is 99% used for making a menu on an lcd display where you can change the speed at which the motors will run and duration of time the motors will run, so the only code that is useful is this:

int SlideDirection=1;
int SlideDistance=1000;
int SlideTime=100;
int RotationDirection=1;
int RotationAngle=45;
int RotationTime=100;
int ZoomDirection=0;
int ZoomAngle=10;
int ZoomTime=50;

basically the Slide, Rotation and Zoom are the 3 motors
the direction is 1=right 0=left
I tried numerous ways to make all 3 motors rotate at the same time, but the only solution I see is to buy 4 arduinos, one for each motor and one master arduino.
But if there is a way to make all three motors move at the same time (or in the same time period, because the camera mounted on will be filming this and the movement must be smooth), like via some command I don't know about or some library perfect for this I also don't know about.

Thanks in advance

int SlideDirection=1;

int SlideDistance=1000;
int SlideTime=100;
int RotationDirection=1;
int RotationAngle=45;
int RotationTime=100;
int ZoomDirection=0;
int ZoomAngle=10;
int ZoomTime=50;



basically the Slide, Rotation and Zoom are the 3 motors
the direction is 1=right 0=left
I tried numerous ways to make all 3 motors rotate at the same time, but the only solution I see is to buy 4 arduinos, one for each motor and one master arduino.

Try using a for-loop with time measuring.

int SlideDirection=1;
int SlideDistance=1000;
int SlideTime=100;

int RotationDirection=1;
int RotationAngle=45;
int RotationTime=100;

int ZoomDirection=0;
int ZoomAngle=10;
int ZoomTime=50;


unsigned long starttime    = millis();
unsigned long currenttime;
unsigned long elapsedtime;


// loop

currenttime = millis();
elapsedtime = currenttime - starttime;


if (SlideDistance > 0) {
  if (elapsedtime >= SlideTime) {
    SlideDistance --; 
    
    // put your move code for motor one here
  }
}

if (RotationAngle > 0) {
  if (elapsedtime >= RotationTime) {
    RotationAngle --; 
    
    // put your move code for motor two here
  }
}

if (ZoomAngle > 0) {
  if (elapsedtime >= ZoomTime) {
    ZoomAngle --; 
    
    // put your move code for motor three here
  }
}

starttime = millis(); // reset the timer to measure next delay

You should probably measure time separate for each motor, but I should help and not write the complete solution for you.

Hi,
Have you tried to write your code in stages?
Forget the menu.
Write code to just get one stepper working.
Write code just to get the next stepper working.
Write code just to get the third stepper working.

Now you have three working codes.
Now combine them and get them working.

Then think about your display and menus.
Get just that code working, then combine it with your combined stepper drive.

It sounds long and laborious, but it will make you a better programmer and make for easier code to debug.

A clear and concise circuit diagram will help as you go too.

Tom... :slight_smile:

Thank you for your great solutions!
I will try them out as soon as possible.

TomGeorge:
It sounds long and laborious, but it will make you a better programmer and make for easier code to debug.

I reckon if you follow what @TomGeorge has said you will actually get to a final working project more quickly.

But if there is a way to make all three motors move at the same time (or in the same time period, because the camera mounted on will be filming this and the movement must be smooth), like via some command I don't know about or some library perfect for this I also don't know about.

There will be no problem making all 3 motors move at the same time.

One detail that you have not mentioned is whether you want coordinated movement - in other words do you want MotorA to move (say) 517 steps in the same time that MotorB moves 963 steps. That is a little trickier, but still perfectly possible.

Or would it be OK for MotorA to finish its 517 steps and then wait for MotorB to complete its 963 steps?

Whether the movements need to be coordinated or not, the trick to getting the motors to move at the same time is to interleave the step instructions.

...R