Independent Stepper Control with continuous rotation

Hi All,
Newer arduino user here with some stepper motor control questions.
I’m using an arudino Uno, 28byj_48 stepper motors with ULN2003 driver boards.
My goal is to be able to have one stepper motor rotate at a specific speed continuously and at the same time have another (possible two) stepper motor execute a specific move sequence and repeat.

Example:
Motor #1 set to rotate at X,
Motor #2 step forward 40 steps, then back 100 and repeat,
Motor #3 backward 100 steps, forward 30, backward 50, forward 10, repeat.

I’d also like to not have acceleration if possible, or have minimal otherwise. I have a small arm attached to the steppers but they’re light enough that an instant direction change shouldn’t stall the motor

I can can get one motor to do what i want with the basic Stepper library but not two simultaneously due to blocking moves.

I’ve tried the AccelStepper library and almost got what i’m looking for but I find my stepper are lacking some torque and i have to have a specific first move.(code bellow)

#include <AccelStepper.h>

#define FULLSTEP 4

int r=1;
#define motorPin1  8 
#define motorPin2  9 
#define motorPin3  10
#define motorPin4  11
                        
#define motorPin5  4
#define motorPin6  5
#define motorPin7  6
#define motorPin8  7

AccelStepper stepper1(FULLSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
AccelStepper stepper2(FULLSTEP, motorPin5, motorPin7, motorPin6, motorPin8);

void setup()
{
  stepper1.setMaxSpeed(700);
  stepper1.setAcceleration(500);
  stepper1.setSpeed(200);
  stepper1.moveTo(2048);  
  
  stepper2.setMaxSpeed(700);
  stepper2.setSpeed(500);

}


void loop()
{
  if (stepper1.distanceToGo() == 0){ 
    if(r==1){
     stepper1.move(-100);
     r=2;
    }else{
      stepper1.move(500); 
      r=1;
    }
  }
  stepper1.run();
  stepper2.runSpeed();

}

I’ve also tried the TinyStepper_28BYJ_48 library as well. My motors seemed to have better torque when using this library but i couldn’t find a way to do continuous rotation with this library or how to make one motor execute a cycle of moves at the same time another is executing another cycle.

I didn’t know how to disable acceleration in either of the libraries.

Any help or ideas would be greatly appreciated.

Thanks
Oliver

The choice of library should have no effect on motor torque. Stepper motor torque falls off as speed increases.

The runSpeed() function in AccelStepper does not use acceleration.

...R

Hi Robin2,
Yes the runSpeed() does not use acceleration, but the move() and moveTo() do which i'd like to bypass/avoid if possible.

Oliver

I think the biggest problem i'm trying to figure out is how to have a stepper move through a specific pattern in a non blocking way so i can run other steppers at the same time.

Oliver

enoc22:
but the move() and moveTo() do which i'd like to bypass/avoid if possible.

Neither of those functions causes any movement of a motor. All they do is set the destination that is used when run() or runSpeed() is called.

...R

Ok I see.tried doing

stepper1.move(-100);
stepper1.move(100);
stepper1.run();

with the AccelStepper library to get the motor to move forward then backward but it only ran the move(100).(which i guess overwrites the move before it).

Do you know if there is a way to set multiple destinations that the motor will travel to in sequential order when run() is called?

Thanks
Oliver

Think about how things happen in the real world. If you tell a person "the destination is London" "the destination is Glasgow" "Move" what do you think would happen?

If you want the person to go to London and then go to Glasgow wouldn't you ask him "are you there yet?" and only tell him to go to Glasgow when he says he has arrived at London?

Your computer program needs to do the same thing. There is a distanceToGo() function that is the equivalent of "are you there yet"

...R

Ok, I have some ideas and i'll check back in with results. Thanks!

Oliver

I think i was able to figure it out.
I was able to use some logic to cycle through a pattern.

#include <TinyStepper_28BYJ_48.h>


//
// pin assignments, any digital pins can be used
//


const int ONE_REV = 2048;
int t =1;
int cycle = 1;
//
// create two stepper motor objects, one for each motor
//
TinyStepper_28BYJ_48 armA;
TinyStepper_28BYJ_48 armB;



void setup(){ 
 Serial.begin(9600);
 //
 // connect and configure the stepper motors to their IO pins
 //
 armA.connectToPins(8,9,10,11);
 armB.connectToPins(4,5,6,7);

}


void loop(){

 armA.setSpeedInStepsPerSecond(300);
 armA.setAccelerationInStepsPerSecondPerSecond(1000);

 armB.setSpeedInStepsPerSecond(500);
 armB.setAccelerationInStepsPerSecondPerSecond(1000);

 armA.setupRelativeMoveInSteps(1);

 armB.setupMoveInSteps(ONE_REV*10);

 while((!armA.motionComplete()) || (!armB.motionComplete())){
 if(armA.motionComplete()){
 switch(cycle){
 case 1:
 armA.setupRelativeMoveInSteps(ONE_REV/-8);
 cycle = 2;
 break;
 case 2:
 armA.setupRelativeMoveInSteps(ONE_REV/4);
 cycle = 3;
 break;
 case 3:
 armA.setupRelativeMoveInSteps(ONE_REV/-8);
 cycle = 4;
 break;
 case 4:
 armA.setupRelativeMoveInSteps(ONE_REV/4);
 cycle = 1;
 break;
 } 
 }
 if(!armA.motionComplete()){
 armA.processMovement();
 }
 if(!armB.motionComplete()){
 armB.processMovement();
 }
 }

}

There still a few small issues i’m trying to figure out but they should go on another topic.

Thanks
Oliver