Hi All,
I’ve been working on a project that has multiple stepper motors running simultaneously and independent of each other.
I am using the TinyStepper_28BYJ_48 with 28BYJ_48 motors and driver boards connected to and UNO.
I have one stepper I need to run continuously. I accomplished that by telling to a certain number of revolutions (one rev 20), but i have run into a problem, if i try to do more than about 15 revolutions (152048 steps) than the motor will complete about 11-12 then stop.
Does anyone know why this may be?
if i do 10 or 11 it does fine but higher numbers it stops before reaching the total steps.
Bellow is my code.
#include <TinyStepper_28BYJ_48.h>
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*20);
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();
}
}
}
Let me know if anyone has any insights as to why this may be.
PaulS:
Then, clearly, you should NOT be using a stepper motor.
I don't agree at all. A stepper motor has the great advantage (over a regular DC motor) that it can be programmed to run at a specific speed which won't change when the load changes. Assuming, of course, that the load never exceed the capability of the motor.
enoc22:
if i try to do more than about 15 revolutions (15*2048 steps) than the motor will complete about 11-12 then stop.
15 * 2048 = 30720 and the max positive value for an int variable is 32767 so I suspect you need to change the relevant int to a long
If you want the motor to run continuously it is probably easier to make it do one step at a time and look after the step timing yourself.