Improved Stepper Library and also a StepperDriver Library

Hello all,
I did some work on an improved and very fast stepper library for the Maxuino project for interfacing Firmata to Max/MSP/Jitter and thought I would see if it was useful enough to everyone. I also implemented the changes to the standard stepper Library because of the following improvements:

  • The library can give commands to several (tested up to six so far) steppers at the same time because of the removal of delays. The arduino can also continue to handle other inputs and outputs because the stepper doesn't get stuck in a "while" loop but instead updates each cpu cycle.
  • The steppers can be given new commands at any time to override the current position for more "live control" or the stepper returns a flag when it has finished so the arduino can then send a new command to avoid override.
  • I moved to microseconds because millis was slowing the motors down.

The StepperDriver Library is made for the EasyDriver and Pololu stepper motor drivers and other that use the STEP and DIR control method. It also has a small difference of having an "empty" initiator for easy creation of an array of instances which can be configured later on the fly. I did not implement this into the standard Stepper library but it might be worth considering.

I would appreciate all feedback and thoughts as I hope to at least get the Stepper added to the Arduino distribution as an upgrade and thought the StepperDriver might also be such a candidate.

Stepper.zip (4.14 KB)

StepperDriver.zip (3.67 KB)

Hi-

Looks good. I think further additions would include 8-step mode to the stepper.cpp, and acceleration, deceleration to the driver, if possible.

Thanks again,
David

Eight-steps:
0: 1 0 0 0
1: 1 1 0 0
2: 0 1 0 0
3: 0 1 1 0
4: 0 0 1 0
5: 0 0 1 1
6: 0 0 0 1
7: 1 0 0 1

The trick with accel/decel is predicting when to slow down so you hit the target. One possible method is to record how long (how many steps - accelSteps) it takes to accelerate to speed, and then use that to start the decel (target minus accelSteps). Of course this fails if you change the speed mid move. Some math or just a loop to recalculate accelSteps would suffice.

  • D

The 8 wire is an easy add. The acc/de-acc would be interesting. I imagine it would be best to do it by time length, i.e. 1.5 seconds for and change in speed. It would default to 0 seconds so the behavior is straightforward but you could send a command to change that transitional time much like you send a speed command.
Would be interested to know if this is useful to others as well?
Chris

Thank you chris for such a nice libraries.. A ramp acc/de-acc would be interesting .. A backlash compensation will also be very helpful..

hey i was not able to find any example codes in the library files. can you please post some. iam working on differential motion of robots using stepper motors will this library file be useful to me??