Stepper motor does not turn anticlockwise

Hi, I am using nema 17 and TB6560 driver. I am trying to run the motor in clockwise and anti-clockwise direction. but the motor just keeps running in clockwise direction even when the stepsize given is negative. please help.
this is the code

AccelStepper stepper1(AccelStepper::DRIVER, STEPPER1_STEP_PIN, STEPPER1_DIR_PIN);

int stepsize1;
void setup()
{
  Serial.begin(9600);
  Serial.println("start");
}

void loop()
{
  if (stepper1.distanceToGo() == 0)
  {

    stepsize1 = 200; // or -200
    stepper1.setMaxSpeed(1000);
    stepper1.moveTo(stepsize1);
    stepper1.setSpeed(106);
  }
  stepper1.runSpeed();
}

You should take a look at the documentation of AccelStepper :wink:
using moveTo / setMaxSpeed together with setSpeed/runSpeed does not make sense.
if you want to position the stepper with moveTo use only setMaxSpeed and run instead of runSpeed.

Thank you so much that brought a lot of clarity.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.