Guide on Accelstepper

Hi everyone.

I kinda need a little help here.
I am very new at arduino and now i am learning how to use accelstepper library.

My question is that is it possible to setMinSpeed rather than setMaxSpeed. I want to decelerate my motor until minspeed ? Is it possible ? I am so sorry for my bad english

Thank you very much and have a nice day

I don't think the library has that feature. The general usage of stepper motors is start-stop rather than continuous running.

It is not difficult to control a stepper motor without a library if your stepper driver takes step and direction signals. Look at this Simple Stepper Code

...R
Stepper Motor Basics

Actually right now i need to control 2 stepper motor with different speed, and if possible choice to accelerate and decelerate ? do i really need accelstepper library ?

Probably i need to use multistepper library to actually control it simultaneously.
thank you very much

In the stepper libraries, you adjust the speed by adjusting the timing between steps. The max speed setting can prevent the user from using intervals that are too short for the motor to respond, which causes it to skip steps.

You can set a lower limit in your code by defining the maximum interval between steps.

The library will let you create seperate stepper objects, one for each motor, which can be controlled seperately.

Programming acceleration/deceleration is complex. You want the library for that.

best,
Michael

Look at the AccelStepper.h file itself, it is copiously commented. In fact any library you
download or use you should checkout the comments in the .h file and checkout examples
that came with it.

lordchickenbreast:
do i really need accelstepper library ?

Probably not, is my answer.

I suspect that writing your own code would be easier than hacking the AccelStepper library.

...R

He doesn't need to hack the library to accomplish what's in the original post. Maybe the OP needs to give more specifics about what he wants to do.
--Michael

Thank you so much for the reply everyone. I really appreciate it.

Sorry if i didnot explain enough.

Basically i want to control two stepper at the same time. I will input the speed and acceleration at the void loop, through the ctrl+shift+m page. I can control one now . However i want the option to decelerate like the acceleration. It start with x step/s then decrease slowly to y step/s (minimum speed)

Hacking the library itself is also a challange for me since i am still begineer in arduino programming.

Hi,

Just took a quick look at the AccelStepper library. It is capable of doing everything you describe without modification.
www.airspayce.com/mikem/arduino/AccelStepper/classMultiStepper.html
You will have to write code to implement it. Evidently you've already written something to control a single stepper. If you post it, I and/or others here can help you with it. Be sure to follow the forum standards for posting: forum.arduino.cc/index.php?topic=97455.0 -- specifically, scroll down to item 6 and see especially bullets 3 - 6. (You'll save yourself a lot of snark if you do.)

best,
Michael

Actually, for your purposes, this would have been a more appropriate link for me to post: www.airspayce.com/mikem/arduino/AccelStepper/classAccelStepper.html
--Michael

Thank you so much Michael for your reply.

I am sorry as i cannot post it now as i am not with my laptop.

However i would like to explain my code a little bit:

#include accelstepper
Define the pin
Declare variable
( float speed, float acceleration)

Void setup
( serial begin(9600);
Set.speed (speed)//speed=variable i declare;
.... Set other parameter such as set.moveTo()
)

Void loop
(
While (serial.available == 0 )
{}// to wait for my input
Speed = read.parseFloat;

..... Etc and other parameter.

Stepper1.runToPostion()
)

I am so sorry if it is confusing, but this is the best i think i can do. I will post the full code as soon as possible .

Thank you so much.

And if possible may i know how do i put the decelerate command? I read through the page you gave me but i cannot found anything.

Thanks

Here's a link to the AccelStepper.h file that MarkT mentioned:
www.airspayce.com/mikem/arduino/AccelStepper/AccelStepper_8h_source.html
Scroll down to around line 300. This is where the descriptions start for the functions that the library makes available.

Time for me to call it a night. But if the topic is still alive when I get a chance to log in tomorrow, I imagine I will ask for more specific details about what you want to do.
In the library, acceleration and deceleration appear to come into play as the motor is asked to move to a position--accelerating from start and decelerating to stop. Changing speed while running may be more a matter of incrementing or decrementing a speed variable.

--Michael

Thanks Michael for the response.

Actually from what i understand the acceleration coding. The speed is actually step/second. And the accleration start from time=0. So from the start the motor will accelerate into the maximum speed set by user, which i think i can control perfectly.

However my concern right now is to have the another same scenario as the above. Rather than accelerate it decelerate. So when the program start. The motor will rise to speed until the maxspeed that i set then slowly decelerate per second to minimum speed i set.

So i was wondering do i need to tune the library ? Thanks for the help in advance

Hi,

Here's a page that may have more intelligible explanations for you:
www.pjrc.com/teensy/td_libs_AccelStepper.html
Note the description of setMaxSpeed, in particular: "When controlled by setting position, the stepper will accelerate to move at this maximum speed, and decelerate as it reaches the destination." It's an automatic thing that happens with runToPosition.

If I understand this right, setMaxSpeed will set the speed at which the motor moves from step to step if you program no delay between steps. You change running speed by changing the timing of when steps are initiated.

If you want to change the speed while the motor is turning, you modify the variable passed in the set speed function: mystepper.setSpeed(stepsPerSecond), incrementing whatever variable you use for stepsPerSecond to accelerate or decrementing it to decelerate.

Remember that stepper motors were invented for positioning control. Generally in positioning you want to motor to move as quickly as possible from position A to position B. But trying to go from 0 to max speed in one step--or from max speed to zero in one step--is a problem because of inertia and is likely to make the motor skip steps and lose track of position. That's the main purpose of the acceleration and deceleration that the library provides.

Hope this is helpful.

--Michael

I reckon it would be quicker to add acceleration and deceleration to my Simple Stepper Code :slight_smile:

...R