I have three stepper motors connected to the drv8825 drivers to an arduino uno.
I am using the example code below (from here), which works fine for moving multiple stepper motors at the same time BUT they all move for the same number of steps and in the same direction. I would like to tweak the code so that all of them move at the same time but each one for a different number of steps and in different directions. The motor with the least steps would probably have to wait for the motor with the most steps to finish its movement before going again.
int dirPin = 8;
int stepperPin = 7;
int bdirPin = 6;
int bstepperPin = 5;
void setup() {
pinMode(dirPin, OUTPUT);
pinMode(stepperPin, OUTPUT);
pinMode(bdirPin, OUTPUT);
pinMode(bstepperPin, OUTPUT);
}
void step(boolean dir,int steps){
digitalWrite(dirPin,dir);
digitalWrite(bdirPin,dir);
delay(50);
for(int i=0;i<steps;i++){
digitalWrite(stepperPin, HIGH);
digitalWrite(bstepperPin, HIGH);
delayMicroseconds(800);
digitalWrite(stepperPin, LOW);
digitalWrite(bstepperPin, LOW);
delayMicroseconds(800);
}
}
void loop(){
step(true,1600);
delay(500);
step(false,1600*5);
delay(500);
}
Thank you in advance for your help!