Here is my contribution. This is the NEW and improved EasyDriver library. Makes using an easydriver a breeze.
Header:
/*
EasyDriver.h - Arduino Library for EasyDriver 3.0 stepper driver board from Sparkfun.com
Based on:
EasyDriver.h - - EasyDriver library for Wiring/Arduino - Version 0.4
Original library (0.1) by Tom Igoe.
Two-wire modifications (0.2) by Sebastian Gassner
Combination version (0.3) by Tom Igoe and David Mellis
Bug fix for four-wire (0.4) by Tom Igoe, bug fix from Noah Shibley
Additional functionality and bug fixes (0.5) by Richard Lowe
I wanted This library to be a simple drop-in replacement for the standard stepper lib.
just change some defines and go!!
Makenb "at" gmail.com 8/28/09
*/
// ensure this library description is only included once
#ifndef EasyDriver_h
#define EasyDriver_h
#include <inttypes.h>
// library interface description
class EasyDriver {
public:
// constructors:
EasyDriver(int numberOfSteps, uint8_t dirPin, uint8_t stepPin, uint8_t MS1Pin, uint8_t MS2Pin, uint8_t enablePin, uint8_t sleepPin);
// speed setter method:
void setSpeed(long whatSpeed);
// mover method:
void step(int numberOfSteps);
// get version
uint8_t version(void);
// set steps
void setStepping(uint8_t steping);
// save power by putting it to sleep
void setSleep(bool sleep);
// enables or disables the mc
void setEnable(bool enabled);
private:
// motor pin numbers:
uint8_t _dirPin;
uint8_t _stepPin;
// optional pins
uint8_t _MS1Pin;
uint8_t _MS2Pin;
uint8_t _enablePin;
uint8_t _sleepPin;
// variables
long _lastStepTime; // time stamp in ms of when the last step was taken
int _direction; // Direction of rotation
uint8_t _speed; // Speed in RPMs
unsigned long _stepDelay; // delay between steps, in ms, based on speed
uint8_t _numberOfSteps; // total number of steps this motor can take
uint8_t _stepNumber; // which step the motor is on
// methods
void stepMotor(uint8_t thisStep);
};
#endif
Source:
/*
EasyDiver.cpp - Arduino Library for EasyDriver 3.0 stepper driver board from Sparkfun.com
Based on:
EasyDriver.cpp - - EasyDriver library for Wiring/Arduino - Version 0.4
Original library (0.1) by Tom Igoe.
Two-wire modifications (0.2) by Sebastian Gassner
Combination version (0.3) by Tom Igoe and David Mellis
Bug fix for four-wire (0.4) by Tom Igoe, bug fix from Noah Shibley
Additional functionality and bug fixes (0.5) by Richard Lowe
I wanted This library to be a simple drop-in replacement for the standard stepper lib.
just change some defines and go!!
Maken "at" maken.org 8/28/09
*/
#include "WProgram.h"
#include "EasyDriver.h"
/*
* EasyDriver constructor.
* Sets Direction and Step Pins.
*/
EasyDriver::EasyDriver(int numberOfSteps, uint8_t dirPin, uint8_t stepPin, uint8_t MS1Pin, uint8_t MS2Pin, uint8_t enablePin, uint8_t sleepPin)
{
this->_stepNumber = 0; // which step the motor is on
this->_speed = 0; // the motor speed, in revolutions per minute
this->_direction = 0; // motor direction
this->_lastStepTime = 0; // time stamp in ms of the last step taken
this->_numberOfSteps = numberOfSteps; // total number of steps for this motor
// Arduino pins for the motor control connection:
this->_dirPin = dirPin;
this->_stepPin = stepPin;
this->_MS1Pin = MS1Pin;
this->_MS2Pin = MS2Pin;
this->_enablePin = enablePin;
this->_sleepPin = sleepPin;
// required pins on the microcontroller:
pinMode(this->_dirPin, OUTPUT); // direction pin
pinMode(this->_stepPin, OUTPUT); // step pin
// MS1 MS2 Resolution //
// L L Full Step //
// H L Half Step //
// L H Quarter Step //
// H H Eighth Step //
// Optional Pins
if (_MS1Pin != NULL) pinMode(this->_MS1Pin, OUTPUT);
if (_MS2Pin != NULL) pinMode(this->_MS2Pin, OUTPUT);
if (_enablePin != NULL) pinMode(this->_enablePin, OUTPUT);
if (_sleepPin != NULL) pinMode(this->_sleepPin , OUTPUT);
}
/*
Sets the speed in revs per minute
*/
void EasyDriver::setSpeed(long whatSpeed)
{
this->_stepDelay = 60L * 1000L / this->_numberOfSteps / whatSpeed;
}
/*
Moves the motor steps_to_move steps. If the number is negative,
the motor moves in the reverse direction.
*/
void EasyDriver::step(int stepsToMove)
{
int stepsLeft = abs(stepsToMove); // how many steps to take
// determine direction based on whether steps_to_mode is + or -:
if (stepsToMove > 0) {this->_direction = 1;}
if (stepsToMove < 0) {this->_direction = 0;}
// decrement the number of steps, moving one step each time:
while(stepsLeft > 0) {
// move only if the appropriate delay has passed:
if (millis() - this->_lastStepTime >= this->_stepDelay) {
// get the timeStamp of when you stepped:
this->_lastStepTime = millis();
// increment or decrement the step number,
// depending on direction:
if (this->_direction == 1) {
this->_stepNumber++;
if (this->_stepNumber == this->_numberOfSteps) {
this->_stepNumber = 0;
}
}
else {
if (this->_stepNumber == 0) {
this->_stepNumber = this->_numberOfSteps;
}
this->_stepNumber--;
}
// decrement the steps left:
stepsLeft--;
// step the motor to step number 0, 1, 2, or 3:
stepMotor(this->_direction);
}
}
}
/*
* Moves the motor forward or backwards.
*/
void EasyDriver::stepMotor(uint8_t thisDir)
{
digitalWrite(_dirPin, thisDir);
delayMicroseconds(100);
digitalWrite(_stepPin, LOW);
delayMicroseconds(100);
digitalWrite(_stepPin, HIGH);
delayMicroseconds(100);
}
/*
sets the mc stepping 1,2,4, or 8 (represents full, half, quarter, or eighths)
*/
void EasyDriver::setStepping(uint8_t stepping){
switch(stepping){
case 1:
digitalWrite(_MS1Pin, LOW);
digitalWrite(_MS2Pin, LOW);
break;
case 2:
digitalWrite(_MS1Pin, HIGH);
digitalWrite(_MS2Pin, LOW);
break;
case 4:
digitalWrite(_MS1Pin, LOW);
digitalWrite(_MS2Pin, HIGH);
break;
case 8:
digitalWrite(_MS1Pin, HIGH);
digitalWrite(_MS2Pin, HIGH);
break;
default:
digitalWrite(_MS1Pin, LOW);
digitalWrite(_MS2Pin, LOW);
}
}
/*
puts the EasyDriver to sleep or wakeup
*/
void EasyDriver::setSleep(bool sleep){
if (sleep) digitalWrite(this->_sleepPin, LOW);
if (!sleep) digitalWrite(this->_sleepPin, HIGH);
}
/*
allows for disabling the mc
*/
void EasyDriver::setEnable(bool enabled){
if (enabled) digitalWrite(this->_enablePin, LOW);
if (!enabled) digitalWrite(this->_enablePin, HIGH);
}
/*
version() returns the version of the library:
*/
uint8_t EasyDriver::version(void)
{
return .05;
}
And keywords file:
#######################################
# Syntax Coloring Map For EasyDriver
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
EasyDriver KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
setSpeed KEYWORD2
step KEYWORD2
setStepping KEYWORD2
setSleep KEYWORD2
setEnable KEYWORD2
version KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
Let me know if there is anything else we can add.