Arduino Library – AccelStepper

library icon

Installatie van Arduino IDE libraries: Arduino info
arduino logo rond
Informatie (ENG):

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

The standard Arduino IDE includes the Stepper library 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
  • Supports stepper drivers such as the Sparkfun EasyDriver (based on 3967 driver chip)
  • Very slow speeds are supported
  • Extensive API
  • Subclass support

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

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

Theory
This code uses speed calculations as described in “Generate stepper-motor speed profiles in real time” by David Austin 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.
Adafruit Motor Shield V2

The included examples AFMotor_* are for Adafruit Motor Shield V1 and do not work with Adafruit Motor Shield V2.

Basic Usage

You can create multiple AccelStepper objects, giving a unique name to each motor. AccelStepper can manage any number of motors, as long as you repetitively call their “run” functions.

Defining & Configuring Motors

AccelStepper mystepper(1, pinStep, pinDirection);

A stepper motor controlled by a dedicated driver board.

AccelStepper mystepper(2, pinA, pinB);

A bipolar stepper motor controlled by an H-Bridge circuit.

AccelStepper mystepper(4, pinA1, pinA2, pinB1, pinB2);

A unipolar stepper motor, controlled by 4 transistors.

mystepper.setMaxSpeed(stepsPerSecond);

Sets the maximum speed. The default is very slow, so this must be configured. When controlled by setting position, the stepper will accelerate to move at this maximum speed, and decelerate as it reaches the destination.

mystepper.setAcceleration(stepsPerSecondSquared);

Sets the acceleration to be used, in steps per second per second.

Position Based Control

mystepper.moveTo(targetPosition);

Move the motor to a new absolute position. This returns immediately. Actual movement is caused by the run() function.

mystepper.move(distance);

Move the motor (either positive or negative) relative to its current position. This returns immediately. Actual movement is caused by the run() function.

mystepper.currentPosition();

Read the motor’s current absolution position.

mystepper.distanceToGo();

Read the distance the motor is from its destination position. This can be used to check if the motor has reached its final position.

mystepper.run();

Update the motor. This must be called repetitively to make the motor move.

mystepper.runToPosition();

Update the motor, and wait for it to reach its destination. This function does not return until the motor is stopped, so it is only useful if no other motors are moving.

Speed Based Control

mystepper.setSpeed(stepsPerSecond);

Set the speed, in steps per second. This function returns immediately. Actual motion is caused by called runSpeed().

mystepper.runSpeed();

Update the motor. This must be called repetitively to make the motor move

Example program

Bronnen: pjrc.com


Download @ airspayce.com

Top