I am trying to create a simple program to control a stepper (by means of a A4988 driver assembled on a CNC Shield) that moves a leadscrew. I started using the ‘bounce’ example of AccelStepper library with some modifications, since bouncing a load is all I need.
The problem has appeared when I have tried to add some code to make a simple homing. My plan is is to do the homing without switches just moving the nut of the leadscrew to de mechanical hardstop. As I only need the homing to be done at the start, I have put this part of the code at the start. The problem is that it is not executed at all, the mechanism starts bouncing directly without moving slowly to the end stop beforehand.
Any help is welcome.
// for the Arduino Uno + CNC shield V3 + A4988 + FL42STH47-1684A
#define MOTOR_X_ENABLE_PIN 8
#define MOTOR_X_STEP_PIN 2
#define MOTOR_X_DIR_PIN 5
AccelStepper motor_X(1, MOTOR_X_STEP_PIN, MOTOR_X_DIR_PIN);
motor_X.setPinsInverted(false, false, true);
//HOMING: Move to the leadscrew hardstop
motor_X.setAcceleration(500); // Set Acceleration of Stepper
motor_X.setMaxSpeed(500); // Set Max Speed of Stepper (Slower to get better accuracy)
//Define the parameters for the bouncing movement on the loop
if (motor_X.distanceToGo() == 0)