3

I know that direction can be changed with

.setSpeed(speed);
... //check input
.setSpeed(-speed);

I need to slowly decelerate and accelerate backwards, so I have to use

.setAcceleration(200);
...
.setMaxSpeed(speed);
... //check input
.setMaxSpeed(-speed);

but documentation told that .setMaxSpeed argument Must be > 0.

So how to properly change direction with deceleration? Probably I have to use .moveTo with some very big values

2
  • have you looked at the example code that is included with the library? – jsotola Oct 4 '20 at 21:25
  • The library defines speed as steps per second. It doesn't care about the direction the steps are in. Just like you can't get out of a speeding tickets by always driving in reverse ;-). – Gerben Oct 5 '20 at 15:37
2

I have tested it on real motor, and it works as I want with function .moveTo . Speed slowly changed from +maxSpeed to -maxSpeed acording to Acceleration

#define maxSpeed 1000
#define Acceleration 500
............
void setup(){  
  stepper.setMaxSpeed(maxSpeed);
  stepper.setAcceleration(Acceleration);
}
void loop() {
 ............
 if(bDirection!=bDirection_last)
 {
  stepper.moveTo(bDirection?6000000:-6000000);
  ...........
 }
 stepper.run();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.