Hello ,
I am starting to work on a project using the Accelstepper library. But I have a problem, when I put a delay in my loop to make the stepper motors wait, the whole stepper motor stops working.
But when I remove the delay, the motors are working fine again. I see on the Internet, delay, block the code with the library accelstepper.
I'm trying to find a solution but I can't find one.
What I want to do is :
Stepper1 move
Stepper2/3 wait
Stepper2 move
Stepper1/3 wait
Stepper 3 move
Here is my code :
#include <AccelStepper.h>
// Define some steppers and the pins the will use
#define X_STEP 2
#define X_DIR 5
#define Y_STEP 3
#define Y_DIR 6
#define Z_STEP 4
#define Z_DIR 7
#define ENABLE 8
AccelStepper stepper1(AccelStepper::DRIVER,X_STEP,X_DIR,true); //(X-Axys)(type,step,dir)
AccelStepper stepper2(AccelStepper::DRIVER,Y_STEP,Y_DIR,true); //(Y-Axys)(type,step,dir)
AccelStepper stepper3(AccelStepper::DRIVER,Z_STEP,Z_DIR,true); //(Z-Axys)(type,step,dir)
void setup()
{
pinMode(ENABLE,OUTPUT);
digitalWrite(ENABLE,LOW);
Serial.begin(9600);
Serial.println("Iniciando");
stepper1.setMaxSpeed(6000.0);
stepper1.setAcceleration(9000.0);
stepper1.moveTo(3000); //MAX 9500
stepper2.setMaxSpeed(6000.0);
stepper2.setAcceleration(6000.0);
stepper2.moveTo(-3500);
stepper3.setMaxSpeed(6000.0);
stepper3.setAcceleration(6000.0);
stepper3.moveTo(3000); //MAX 10000
}
void loop(){
// Change direction at the limits
if (stepper1.distanceToGo() == 0){
stepper1.moveTo(-stepper1.currentPosition());
Serial.println("vuelta");
}
if (stepper2.distanceToGo() == 0){
stepper2.moveTo(-stepper2.currentPosition());
Serial.println("vuelta");
}
if (stepper3.distanceToGo() == 0){
stepper3.moveTo(-stepper3.currentPosition());
Serial.println("vuelta");
stepper1.run();
stepper2.run();
stepper3.run();
}
Can someone help me please ?
Thank you,
William33