I want to run two stepper motor one after the other Stepper1 has to5 rotation And stepper 2 has to move 1rotation Here is the code
Stepper 1 is nema 34 And stepper 2 is nema 24
#include <AccelStepper.h>
// Define a stepper and the pins it will use
AccelStepper stepper1 (1, 3, 2); // Defaults to 4 pins on 2, 3, 4, 5 mortor (A)
AccelStepper stepper2 (1, 5, 4); // Defaults to 4 pins on 2, 3, 4, 5 motor (B)
long Steps_For_Distance1 = 3; // 3cm
long Steps_For_Distance2 = 5; // 5cm
long currentPos = 0;
long targetPos = 200;
long targetPos_Reverse = -200;
long Motor_Speed1 = 50;
long Motor_Speed2 = 400;
long Motor_Speed3 = 800;
int Op_Sw = 0;
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup()
{
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void checkStepper1_For_DT(AccelStepper &astepper)
{
if (astepper.distanceToGo() == 0)
{
// Random change to speed, position and acceleration
// Make sure we dont get 0 speed or accelerations
astepper.setCurrentPosition(currentPos);
astepper.moveTo(targetPos);
astepper.setSpeed(Motor_Speed1);
astepper.setAcceleration(100);
}
}
void checkStepper2_For_360(AccelStepper &astepper)
{
if (astepper.distanceToGo() == 0)
{
// Random change to speed, position and acceleration
// Make sure we dont get 0 speed or accelerations
astepper.moveTo(targetPos);
astepper.setMaxSpeed(Motor_Speed2);
astepper.setAcceleration(100);
}
}
void PatternToBeLooped_For_Cycle1()
{
int count = 0;
for (count == 0; count <= 5; count ++)
{
checkStepper1_For_DT(stepper1);
stepper1.runSpeedToPosition();
}
checkStepper2_For_360(stepper2);
stepper2.runSpeedToPosition();
}
void loop() {
PatternToBeLooped_For_Cycle1();
}
I had run the code But it didn't work Both motor are running at same time
Please help me
Where I made mistake
Thank you in advance
I had try by delay (1000); But Still they both stepper are moving at a same time and get delay at same time