I have an Arduino project where I'd like to control a stepper motor. Unfortunately, the Arduino library for stepper motors is very limited. I'd like to define parameters for the acceleration, deceleration, and total displacement and have the Arduino take care of the rest. Poking around on this forum, I surprised that no one seems to have posted anything relating to this - so I figured it was incumbent on me to get something started. I've attached my first iteration. Seems to be working well in my tests. Comments and suggestions will be greatly appreciated.

In my current setup, I'm using the EasyDriver stepper driver from sparkfun Electronics - though any driver that used pulse and direction should work fine.

// Other variableslong dly; // stepper pulse delay (microsec)long t = td/9; // current time (microsec) - You need to seed the initial time with something > 0// so you don't calculate to long of a delaylong t12; // time during constant velocity (microsec)

Hi Mike,The point about acceleration is that you can get the motor to run at a faster top speed if you accelerate up to it than you can if you try and drive it from a standing start. The latter is sometimes called the stall speed. It is due to the mechanical inertia you have.

However, if you get it accelerating too fast then you start skipping steps and so you loose accuracy. I used to use a liner ramp to get up to speed but you really should use a bit of control theory to work out the acceleration profile.Same goes for slowing down, if you just do a dead stop it can over run if going too fast.

I use the ED too to drive a 2axis panorama head and use a very simple approach: start slow and accelerate until the max and slow down again - done over the range of steps I want to go. It gives a smooth movement and I don't need consider extra time to stabilize the mount before I release the cams shutter.

I will improve the stepper library a little bit to include acceleration and deceleration and also allow a higher max. velocity. At the moment only 300rmp possible at a stepper with 200 steps because using delay() . The name of the new library will be "StepperHQ".