AccelStepper

- Main Page
- Classes
- Files
- Examples

AccelStepper library for Arduino

This is the Arduino AccelStepper library. It provides an object-oriented interface for 2 or 4 pin stepper motors.

The standard Arduino IDE includes the Stepper library (http://arduino.cc/en/Reference/Stepper) for stepper motors. It is perfectly adequate for simple, single motor applications.

AccelStepper significantly improves on the standard Arduino Stepper library in several ways:

- Supports acceleration and deceleration
- Supports multiple simultaneous steppers, with independent concurrent stepping on each stepper
- API functions never delay() or block
- Supports 2, 3 and 4 wire steppers, plus 3 and 4 wire half steppers.
- Supports alternate stepping functions to enable support of AFMotor (https://github.com/adafruit/Adafruit-Motor-Shield-library)
- Supports stepper drivers such as the Sparkfun EasyDriver (based on 3967 driver chip)
- Very slow speeds are supported
- Extensive API
- Subclass support

The latest version of this documentation can be downloaded from http://www.open.com.au/mikem/arduino/AccelStepper

Example Arduino programs are included to show the main modes of use.

The version of the package that this documentation refers to can be downloaded from http://www.open.com.au/mikem/arduino/AccelStepper/AccelStepper-1.30.zip You can find the latest version at http://www.open.com.au/mikem/arduino/AccelStepper

You can also find online help and discussion at http://groups.google.com/group/accelstepper 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.

Tested on Arduino Diecimila and Mega with arduino-0018 & arduino-0021 on OpenSuSE 11.1 and avr-libc-1.6.1-1.15, cross-avr-binutils-2.19-9.1, cross-avr-gcc-4.1.3_20080612-26.5.

Installation
  Install in the usual way: unzip the distribution zip file to the libraries sub-folder of your sketchbook.

This software is Copyright (C) 2010 Mike McCauley. Use is subject to license conditions. The main licensing options available are GPL V2 or Commercial:

Theory
  This code uses speed calculations as described in "Generate stepper-motor speed profiles in real time" by David Austin http://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 Subsequent shorter step intervals are calculated based on the previous step until max speed is acheived.

Open Source Licensing GPL V2
  This is the appropriate option if you want to share the source code of your application with everyone you distribute it to, and you also want to give them the right to share who uses it. If you wish to use this software under Open Source Licensing, you must contribute all your source code to the open source community in accordance with the GPL Version 2 when your application is distributed. See http://www.gnu.org/copyleft/gpl.html

Commercial Licensing
  This is the appropriate option if you are creating proprietary applications and you are not prepared to distribute and share the source code of your application. Contact info@.nosp@m.open.nosp@m..com..nosp@m.au for details.

Revision History

Version:
  1.0 Initial release
  1.1 Added speed() function to get the current speed.
  1.2 Added runSpeedToPosition() submitted by Gunnar Arndt.
  1.3 Added support for stepper drivers (ie with Step and Direction inputs) with _pins == 1
  1.4 Added functional contructor to support AFMotor, contributed by Limor, with example sketches.
  1.5 Improvements contributed by Peter Mousley: Use of microsecond steps and other speed improvements to increase max stepping speed to about 4kHz. New option for user to set the min allowed pulse width. Added checks for already running at max speed and skip further calcs if so.
  1.6 Fixed a problem with wrapping of microsecond stepping that could cause stepping to hang. Reported by Sandy Noble. Removed redundant _lastRunTime member.
  1.7 Fixed a bug where setCurrentPosition() did not always work as expected. Reported by Peter Linhart.
  1.8 Added support for 4 pin half-steppers, requested by Harvey Moon
  1.9 setCurrentPosition() now also sets motor speed to 0.
  1.10 Builds on Arduino 1.0
  1.11 Improvments from Michael Ellison: Added optional enable line support for stepper drivers Added inversion for step/direction/enable lines for stepper drivers
  1.12 Announce Google Group
  1.13 Improvements to speed calculation. Cost of calculation is now less in the worst case, and more or less constant in all cases. This should result in slightly beter high speed performance, and reduce anomalous speed glitches when other steppers are accelerating. However, its hard to see how to replace the sqrt() required at the very first step from 0 speed.
  1.14 Fixed a problem with compiling under arduino 0021 reported by EmbeddedMan
  1.15 Fixed a problem with runSpeedToPosition which did not correctly handle running backwards to a smaller target position. Added examples
  1.16 Fixed some cases in the code where abs() was used instead of fabs().
  1.17 Added example ProportionalControl
  1.18 Fixed a problem: If one calls the funcion runSpeed() when Speed is zero, it makes steps without counting. reported by Friedrich, Klappenbach.
  1.19 Added MotorInterfaceType and symbolic names for the number of pins to use for the motor interface. Updated examples to suit. Replaced individual pin assignment variables _pin1, _pin2 etc with array _pin[4]. _pins member changed to _interface. Added _pinInverted array to simplify pin inversion operations. Added new function setOutputPins() which sets the motor output pins. It can be overridden in order to provide, say, serial output instead of parallel output Some refactoring and code size reduction.
  1.20 Improved documentation and examples to show need for correctly specifying AccelStepper::FULL4WIRE and friends.
  1.21 Fixed a problem where desiredSpeed could compute the wrong step acceleration when _speed was small but non-zero. Reported by Brian Schmalz. Precompute sqrt_twoa to improve performance and max possible stepping speed
  1.22 Added Bounce.pde example Fixed a problem where calling moveTo(), setMaxSpeed(), setAcceleration() more frequently than the step time, even with the same values, would interfere with speed calcs. Now a new speed is computed only if there was a change in the set value. Reported by Brian Schmalz.
  1.23 Rewrite of the speed algorithms in line with http://fab.cba.mit.edu/classes/MIT/961.09/projects/i0/Stepper_Motor_Speed_Profile.pdf Now expect smoother and more linear accelerations and decelerations. The desiredSpeed() function was removed.
  1.24 Fixed a problem introduced in 1.23: with runToPosition, which did never returned
  1.25 Now ignore attempts to set acceleration to 0.0
  1.26 Fixed a problem where certina combinations of speed and accelration could cause oscillation about the target position.
  1.27 Added stop() function to stop as fast as possible with current acceleration parameters. Also added new Quickstop example showing its use.
  1.28 Fixed another problem where certain combinations of speed and accelration could cause oscillation about the target position. Added support for 3 wire full and half steppers such as Hard Disk Drive spindle. Contributed by Yuri Ivatchkovitch.
  1.29 Fixed a problem that could cause a DRIVER stepper to continually step with some sketches. Reported by Vadim.
  1.30 Fixed a problem that could cause stepper to back up a few steps at the end of accelerated travel with certain speeds. Reported and patched by jolo.

Author:
  Mike McCauley (mikem.nosp@m.@ope.nosp@m.n.com.nosp@m..au) DO NOT CONTACT THE AUTHOR DIRECTLY: USE THE LISTS