I'm trying to home a stepper by going into one limit switch and then back out to another and seem to be having trouble making it move correctly.
When I power up the motor runs to the in limit switch but it doesn't seem to want to move to the out limit switch. It stops correctly at the in but when I ask it to move in the opposite direction it starts to go in the in direction no matter what I set the motion direction with a positive or negative step.
I'm not sure what to make of the direction problem and any help is appreciated.
#include <AccelStepper.h>
AccelStepper gantry(AccelStepper::DRIVER, 5, 6);
//VALUE FOR GANTRY MOVE
int gantryin = 46;
int gantryout = 43;
void setup() {
pinMode(gantryout, INPUT);
pinMode(gantryin, INPUT);
Serial.begin(115200);
gantry.setMaxSpeed(1500.0);
while (digitalRead(gantryin) == HIGH) {
gantry.move(1);
gantry.setSpeed(100);
gantry.runSpeed();
}
delay(1000);
while (digitalRead(gantryout) == HIGH) {
gantry.moveTo(-1);
gantry.setSpeed(100);
gantry.runSpeed();
}
}