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.
Thanks
Izar
#include <AccelStepper.h>
// for the Arduino Uno + CNC shield V3 + A4988 + FL42STH47-1684A
motor_X.setAcceleration(500); // Set Acceleration of Stepper
motor_X.move(-15000);
motor_X.setMaxSpeed(500); // Set Max Speed of Stepper (Slower to get better accuracy)
motor_X.run();
//Define the parameters for the bouncing movement on the loop
motor_X.setAcceleration(500); // Set Acceleration of Stepper
motor_X.move(-15000);
motor_X.setMaxSpeed(500); // Set Max Speed of Stepper (Slower to get better accuracy)
motor_X.run();
The run() method tells the class to determine if it is time to step ONCE. It may, or may not, be time to step. So, your stepper may, or may not, step ONCE.
There are other methods, such as runToPosition() to get the stepper to spin until it has stepped the required number of times.
Just spinning the motor until it slams the carriage into the physical limit sounds like you are trying to break the machine.
There is nothing in your code, even of were written correctly, that makes the stepper stop when some condition becomes true.
A limit switch is a must for a homing action. Looking at your code I saw nothing that would stop the motor when the end of travel is encountered. A recipe for damage.
A micro switch or a opto interrupter device is very inexpensive compared to the cost of a motor, power supply, stepper driver, or lead/ball screw and nut. All items that could suffer if driven onto a hard stop.
When I wrote Reply #1 I had not noticed that there was no limit switch.
I don't see anything wrong in principle with driving a stepper motor very slowly against a fixed end-stop as a means of establishing the home position. Of course the end-stop must be designed so that there will be no damage to any part of the machine.
Robin2:
I don't see anything wrong in principle with driving a stepper motor very slowly against a fixed end-stop as a means of establishing the home position. Of course the end-stop must be designed so that there will be no damage to any part of the machine.
...R
If the machine is designed with a jog switch, and there is a human pushing the switch, and the human is bright enough to stop pressing the switch when the mechanism is at the home position, I'd agree with you.
PaulS:
If the machine is designed with a jog switch, and there is a human pushing the switch, and the human is bright enough to stop pressing the switch when the mechanism is at the home position, I'd agree with you.
All of that is very sensible but I am not convinced that it is essential.
If the motor is moving slowly (which is essential) and it is set to do 500 steps but encounters the end stop after 300 steps it will just miss steps for the remaining 200 steps. Not very elegant - but I don't think the motor will come to any harm.