I'm working on a project and using a nema 23 stepper motor and driver.

  • Need to be able to move the stepper 1/32 rotation when I press a button.

  • I need a small delay so I have time to release the button and not move the 1/32 rotation twice or more (its in a loop) before I can release the button.

  • I also want to the stepper to continue to move in 1/32 rotation increments as long as the button is held down.

I can get this to work with the move() and runToPosition() commands, but it accelerates and decelerates each time making the movement much slower then I need. I would just use the runSpeed() command inside a while loop setting move() each time, but I need the acceleration as the pull in torque of the stepper is not great enough to start at the full speed needed.

Any ideas or suggestions would be greatly appreciated.

  • It is unclear to me, what your actual problem is. If the motor accelerates to slow, I think the AccelStepper library has a function to set the acceleration, so you could just set it to a bigger value. Or is the problem with reading the button for the described behavior?
    – chrisl
    Jan 31, 2021 at 22:43
  • 1
    it is absolutely simple ... do not move the motor when the button is pressed ... move the motor when the button transitions from not pressed to pressed
    – jsotola
    Jan 31, 2021 at 23:10
  • Currently If I press the button, the stepper moves 1/32 rotation using acceleration and deceleration. If I press the button and hold it down, the stepper moves 1/32 rotation with acceleration and deceleration, delays for a short time (this is to allow me to release the button if I only want to move 1/32nd) and then goes into a while loop while the button is held down. but since the commands i'm using are move(1/32) and moveToPosition() it accelerates and decelerates on each movement, and since each movement is short only 1/32 of a rotation it cant accelerate to much and so moves slow
    – clint
    Feb 1, 2021 at 2:44
  • Jsotola, I understand what you are saying, but not sure how to implement that while retaining the needed 1/32nd step on a short press, and also the continues movement that I need to be in 1/32 steps while the button is held down. What I want it to do is move one 1/32 rotation when I press the button and release it using acceleration and deceleration, but if I hold the button I want it to smoothly accelerate to maxSpeed, stay at maxSpeed until I releasethe button, and then stop on a even 1/32 rotation step with smooth deceleration.
    – clint
    Feb 1, 2021 at 2:48
  • If I understand your request properly (Move a little step for a short button press / Move continuously while pressed longer) you need to distinguish between long and short. This can only be detected when you release the button, or when the time distinguishing short/long has elapsed. -> You cannot start moving immediately when button is pressed. Feb 1, 2021 at 10:43


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.