How revers direction on stepper motor. Turn potentiometer to left motor direction left, turn potentiometer right stepper motor to left, need me to right. A4988 driver and arduino and nema 17. potentiometer is 10k.
The first thing to do is to determine whether the pot has been turned to the left or right. Start by doing that and printing a message to indicate which way the motor should turn and nothing else.
Don't you think that one of the two direction_pin codes need to change??
Normally in a step and direction setup direction CONTROLS the direction of the stepper.
they BOTH set direction_pin LOW:
void step_motor_forward()
{
if (digitalRead(Limit02)) {}
else {
digitalWrite(direction_pin, LOW); // SEE?? THIS IS SET LOW
digitalWrite(step_pin, HIGH);
digitalWrite(step_pin, LOW);
}
}
void step_motor_back()
{
if (digitalRead(Limit01)) {}
else {
digitalWrite(direction_pin, LOW); // THIS -ALSO- SETS
digitalWrite(step_pin, LOW);
digitalWrite(step_pin, HIGH);
}
}
If you are using a specialized stepper driver like an A4988 do NOT use the standard stepper library as it is not intended for them. Use the AccelStepper library or just write your own code,
The examples in this Simple Stepper Code can be used for testing and for understanding how the control works.