using run function clockwise and counterclockwise

397 views
Skip to first unread message

Elias Moubayed

unread,
Jun 30, 2022, 4:37:00 AM6/30/22
to accelstepper
Hi everyone, I'm very new to this library and I'm trying to use it with my stepper motor. what I'm trying to do is I want to control it by buttons. as long as the button is pressed the motor is running. one button controls it clockwise and the other one counterclockwise. i'm trying to use stepper.run() to control it. it's working in the clockwise direction but I'm not sure how to do it in the counterclockwise direction. I'm not knowing how to make it go counterclockwise unless i flick the switch on the driver but then it won't clockwise. if someone can help me i'd really appreciate it.

fyi: i have the pulse (-) and digital (-) connected to the arduino and pulse (+), digital(+) and enable(+) connected to the 5v of the arduino.

Tom

unread,
Jun 30, 2022, 4:51:30 AM6/30/22
to accelstepper
I'm not entirely sure what your problem is but rhe run() function will try to move the motor (at most one step per call) from the current position to the target position set by the most recent call to this function. 
But you first have to set the target position either relative or absolute to your current position. Either use  move()moveTo() for that. Negative values will rotate the shaft ccw and positive values will rotate the shaft cw.
Message has been deleted

Elias Moubayed

unread,
Jun 30, 2022, 4:57:38 AM6/30/22
to accelstepper
i want it to run without giving it a position in either cc and ccw direction. is there a way to do that ? 

Tom

unread,
Jun 30, 2022, 5:15:21 AM6/30/22
to accelstepper
Imagine you are the stepper and someone wants you to run? Where will you run if nobody told you where? stepper.move(-1) is also a position. You have to somehow have to communicate to the driver what it should do. 

PW

unread,
Jun 30, 2022, 5:21:14 AM6/30/22
to accels...@googlegroups.com
I take it you only want it to run while a button is held pressed? One button for CE and one for CCW? If that’s the case you then it a rather easy task. 

Sent from my iPhone

On 30 Jun 2022, at 7:15 pm, Tom <tom.b...@gmail.com> wrote:

Imagine you are the stepper and someone wants you to run? Where will you run if nobody told you where? stepper.move(-1) is also a position. You have to somehow have to communicate to the driver what it should do. 
--
You received this message because you are subscribed to the Google Groups "accelstepper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/accelstepper/9923b360-6563-4b0d-a1d4-d0de2edf6932n%40googlegroups.com.

Jim Larson

unread,
Jun 30, 2022, 2:23:45 PM6/30/22
to accelstepper
What the OP wants to do is not only reasonable, it is fairly easy.

First, I highly recommend reading the Missing Manual if you want to really understand AccelStepper.

If you just want a quick solution, here it is. I'm presuming that when a button is held down, you will first set the speed you want to go (negative to go in the opposite direction)m, then just sit in a loop calling runSpeed().

So in setup, call setMaxSpeed() with a value that works for your system. Later calls to setSpeed() cannot be greater than this.
For each button, first call setSpeed() with the speed you want to run. Use a negative value to run the opposite direction (of the direction the positive value causes). Then just continuously call runSpeed() until the button is released.
That's it! That should do what you asked for.
Note that there is no need to set moveTo() or anything else.

HTH!
   -jim
Reply all
Reply to author
Forward
0 new messages