Accelstepper Library Download

0 views
Skip to first unread message

Dawnell Sechler

unread,
Aug 5, 2024, 1:09:04 PM8/5/24
to dipotoca
MicroBahner has written the MobaTools library that has a stepper class. I suppose that he did not mention it because he is too humble. He need not be as I think that his library is easier to learn and use than AccelStepper for many applications. He has good documentation and there are several examples (some in German, but Google translate helps with that).

You can also find online help and discussion at Please use that group for all questions and discussions on this topic. Do not contact the author directly, unless it is to discuss commercial licensing. Before asking a question or reporting a bug, please read


This code uses speed calculations as described in "Generate stepper-motor speed profiles in real time" by David Austin _Motor_Speed_Profile.pdf or -processors-and-socs/4006438/Generate-stepper-motor-speed-profiles-in-real-time or ://fab.cba.mit.edu/classes/MIT/961.09/projects/i0/Stepper_Motor_Speed_Profile.pdf with the exception that AccelStepper uses steps per second rather than radians per second (because we dont know the step angle of the motor) An initial step interval is calculated for the first step, based on the desired acceleration On subsequent steps, shorter step intervals are calculated based on the previous step until max speed is achieved.


This library is offered under a free GPL license for those who want to use it that way. We try hard to keep it up to date, fix bugs and to provide free support. If this library has helped you save time or money, please consider donating at or here:


AccelStepper is a trademark of AirSpayce Pty Ltd. The AccelStepper mark was first used on April 26 2010 for international trade, and is used only in relation to motor control hardware and software. It is not to be confused with any other similar marks covering other goods and services.


Yes it works perfectly now. I have to do a Factory reset after each Code adjustment. Kinda annoying but it works. If you can figure out a way that it works with System Mode AUTOMATIC or give me support on how to implement Spark.connect() that would be super awesome!!! :)))


@newclear, I had a good look at the AccelStepper library. It was clearly written for a platform that is dedicated to the stepper task. This is because all timing is done in software with no hardware interrupts (using a timer for example). This is why it will NOT work properly when anything injects a timing skew (ie WiFi and Cloud servicing). This is a known limitation of the AccelStepper code. Using timer interrupts has been tried by others (eg. on Teensy 3) with varying success. If you can find a suitable timer interrupt-driven stepper arduino library, I may be able to port it for you.


I suggest that if you want to use the AccelStepper library, you accept the fact that you cannot be connected to the Particle Cloud at the same time. You may be able to have wifi connected since it requires much less overhead. So stepping and connecting need to be mutually exclusive.


adafruit.com PhoBot - Robotics Shield for PhotonGet your Particle (formally known as Spark) Photon moving with a PhoBot Robotics shield. No, this is not a robot that makes you a delicious bowl of Vietnamese soup. Instead, ...


because I am looking into using the same library as the author. and here it was mentioned that the library is blocking.

I finally had a good look at the library, and while it has functions that are blocking (and are mentioned in the documentation that they block).

There are functions: run()/runspeed() that do not block, and every time they get called they pull the library to check if a step is due or not. So in a long program you should pull it as often as possible/needed but at least once in the main loop.


Steppers motors deserve to be used in our projects much more than they are. Their use in 3D printers has brought the prices for the motors and drivers down dramatically. But the libraries to drive them lag behind. The Stepper library, part of Arduino, is very limited since it blocks and only allows one motor at a time to move. The AccelStepper library, created by Mike McCauley and easily installed using the Arduino Library Manager, overcomes these restrictions, but is considered difficult to use. The purpose of this manual is to explain AccelStepper so its use can become much more widespread.


The AccelStepper library is a library for Arduino written in C++. To use it, you construct (or "instantiate" in C++ speak) named objects of AccelStepper type. These software objects typically have "motor" or "stepper" as part of their names and are related directly to physical stepper motors and their interface electronics ("drivers"). Several different interfaces are supported. The appropriate one for an individual application must be specified when the object is constructed. Once an object is constructed, the various functions (called "member functions") provided in the library may be used to control the objects. I find it helps to break these into groups. The first group is setup functions that specify physical capabilities (such as speed and acceleration) of the motor and physical values (such as position to move to). The next group are the functions that actually move the motor by sending it signals that will cause steps. These functions use the values from the setup functions to control the motion. Next are the functions that report information about the status of the motion. Then come the pin management functions that configure and control the pins that interact with the driver. These functions will be discussed below, but first it is good to understand how AccelStepper works.




A stepper moves when it receives an electrical signal that causes the motor to take a step. The AccelStepper library only has one callable function that causes motion: runSpeed(). Other functions that result in motion call runSpeed() to produce the actual steps. Each such function has the word "run" in its name. The motion functions are of two types: constant speed (limited by the current value of speed), and variable speed (limited by settings of acceleration and maxSpeed, and by position relative to the target). Each of these types contains blocking and non-blocking functions. Blocking functions will run until a stop condition occurs, but no other code will run until they complete. Non-blocking functions cause a single step (if a step is due - see below) and return immediately in any case. Since each call to a non-blocking function only makes at most a single step, they must be called as often as possible; usually in the main loop. Otherwise the motor will not be stepped at the desired speed.




The function runSpeed() determines when a step is to be taken. runSpeed() subtracts the time of the last step from the current time. If the result is greater than or equal to the value of stepInterval ( we say, "A step is due."), runSpeed will increment (or decrement, as required) currentPosition, call step(), and update the time the last step was taken. (step() is an internal function - not directly callable. It causes the correct electrical signal to be sent to the interface.) Each call to runSpeed() repeats this process, so runSpeed() must be called at least speed times per second. Usually, this means putting a call to runSpeed() in loop(). Calling runSpeed() when no step is due does nothing


The controlling variable for runSpeed() is stepInterval so we need to understand how AccelStepper calculates it. An internal variable, stepInterval is not directly manipulated by the user. In the simplest case, calling setSpeed() will cause a new value of speed - and stepInterval - to be calculated....


The only thing I can suggest is to force your control lines all low using digitalWrite. This will stop all current to the driver. I'm not sure what effect this will have when you start driving the motors again using run().




What voltage are you supplying to the ULN-2003? I ran my 28 BYJ-48 motor with a ULN-2003 driver using a simple bounce sketch for over half an hour. I drove it with 5 Volts and the motor warmed up a bit, but that was all.




stepper1.moveTo(posA); ( posA previously defined). stepper1 goes to posA and there must stay for quite a time. Problem is that 2 LEDs in ULN-2003 kepp lihgted so I suppose two coils are feed up and motor heats-up. The only way to switch off LEDs is resetting Arduino. I can se in examples provided by you or Library, when a final position is reached, that they have same problem. Any idea how to solve this problem?


With the AccelStepper.move() function, you are setting the target position of the motor. Then you run the motor with AccelStepper.runToPosition(). But that is a blocking function. It will not exit, until the motor reached it's target position. So you just picked the wrong function from the AccelStepper library.


Small adjacent about simultaneous action on microcontrollers: Since most microcontrollers, like in the Arduino, only have one core, they can only do exactly one thing at a time. But you can still execute things one after another, but so fast, that a human would say, they where happening at the same time. For this we need to divide down the actions into small chunks, that are executed very fast. In your case we have the big actions of running multiple motors to their target positions. Each of these big actions take long in total, but we can divide them down. And with stepper motors that is really easy, because one step would be one small chunk of that action.


The AccelStepper library helps you in doing this checking if it is time to do a step. This is what happens in the AccelStepper.run() function. You just need to call it regularily, fast enough to not miss the time for a step.


I have a 2 wheel driven differential drive for my robot. True straight line accuracy is not good enough without encoder feedback to the DC motors, but simple Accel/Decel Control and Progressive Steering changes are easy to achieve.


I would like to change to Stepper motor drives using the Allegro A4984: DMOS Microstepping Driver with Translator and Overcurrent Protection and the AcccelStepper library for the Arduino micro controller, using microstepping at the 8 microstep level.

3a8082e126
Reply all
Reply to author
Forward
0 new messages