Making Max/Ableton talk Firmata/Arduino

StepperDriver Library

This page is for the StepperDriver Library we created as part of adding stepper motor support to Maxuino. It is useful for any Stepper Motor driver board using the two pin (STEP and DIR) configuration. It will not work to directly drive Stepper motors. This should be compatible with all EasyDriver and most Pololu Stepper motor drivers. It was based on the structure of the Stepper Library that comes standard with the Arduino. The Functions are:

Stepper()
- this is for initiating an instance of a stepper. This was made so you could easily initiate an array of these for multiple motors.

setStep(steps, dirPin, stepPin)
- this configures the stepper: the number of steps for a full revolution, the pin# that is connected to DIR on the stepper Driver, and the pin# that is connected to STEP on the stepper driver.

setSpeed(rpm)
- set the speed in revolutions per minute

step(steps)
- set the number of steps you want to move, negative numbers rotate in reverse of positive numbers. The stepper motor will continue to move until it finishes the latest step command, therefore a new step command before the previous one finishes will override the previous command.

update()
- returns a zero normally and a “1″ when it finishes the latest step command (i.e. if step(500) was sent, a “1″ is returned when all 500 steps are completed). Run this every loop for each motor.

Download the StepperDriver Library

Here is some example code using the driver:

#include <StepperDriver.h>

const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution for your motor
StepperDriver myStepper; //initialize for one stepper

void setup() {
  myStepper.setStep(stepsPerRevolution, 12,10);
  myStepper.setSpeed(8); //with 1/8th stepping turned on, 1 rpm * 8 = 8
  myStepper.step(stepsPerRevolution*8); //with 1/8 stepping turned on, one full revolution needs to be multiplied x 8
}

void loop() {
// step one revolution in one direction:

  if (myStepper.update() == 1){ //here we check to see if the motor has finished the last step command and at the same time call the update for the motor to keep running
    delay(1000); //when a full revolution is complete, wait 1second and do another full rev.
    myStepper.step(stepsPerRevolution*8);
  }
}