Controlling two stepper motors, one each time, but it depend to the another

Hello Everyone!

I'm beginner at programm anything, so I need your help guys!
Well, Im using Accelstepper.

I need to control two motor steppers, and it should move like this:

Loop:

-stepper1: move 260 steps, (then wait the another stepper finish its movement to move 200 steps again;
-stepper2: move 200 steps CW, after more 200 steps CCW;

Repeat this loop until a EndSwitch be enable;
When EndSwitch is enable, stepper1 goes back to initial position (or until enable the EndSwitch 2).

That's it, it doesnt look so difficult :slight_smile:

Thanks!

The AccelStepper library as the function distanceToGo() which gives the number of steps still to go. When it is 0 the motor will have completed its move.

Does that help?

If not, please give more details of what you are trying to do. And post your program.

...R
Stepper Motor Basics

Hello!!!

I attached the current program. All lines with english comments (There are some portuguese too).

Thanks Robin2 for replying me.

Hugs

Accelstepper_Teste_09.10.2017.ino (8 KB)

I have not studied your code carefully but this suggests that you do not know how to use the AccelStepper library

void tapafuro()              // Setting the Subroutine "Tapafuro"



          stepper2.run();
          stepper2.runToPosition();

First of all, run() and runToPosition() are alternates - use one or the other.

Second, if you are using run() then it should only be called in loop() and not in a sub-function.

...R

Second, if you are using run() then it should only be called in loop() and not in a sub-function.

If the function is called by loop(), often enough, it is OK to call run() from a function that is called by loop().

Robin2's other comments are right on the money, though.

PaulS:
If the function is called by loop(), often enough, it is OK to call run() from a function that is called by loop().

I was trying to keep things simple :slight_smile:

...R