A Stepper Motor Library all of my very own

Hi guys

Im currently trying write my own stepper motor library. Whilst I can move individual steps, I am unable to get the smooth movement at high speeds (100-120 rpm) that I get when I use the Arduino Stepper Library. I get a juddery motion at a slow speed, changing the speed tends to work up to slow rpms. Its all very obviously step, step, step, step, which is not the case with the Arduino Stepper Library. Basically Im trying to get computer control from a program like OF or SuperCollider, which you need to upload firmata or SMS onto the board, without buying drivers but just using a transistor array. I have tried it in Processing, OF and Supercollider and get the same results.

Any ideas what could be causing this? I know its not the equipment/wiring as it works perfectly with the Arduino librarys. I thought it could be to do with data transfer/frame rate of the environment with Processing but I get the same issues with OF and SuperCollider (code implemented in the same way) which should be pretty quick?

Kit: Astrosyn y129-5 Stepper Motor, Darlington ULN2003 transistor array

Code (Processing):

import processing.serial.*;

import cc.arduino.*;

Arduino arduino;
int in1;
int in2;
int in3;
int in4;
int stepNo=0;
float steps=200;
float speed=120;
float nextTime;
float gap;

void setup() {
arduino = new Arduino(this, Arduino.list()[0], 57600);
for (int i = 0; i <= 13; i++) {
arduino.pinMode(i, Arduino.OUTPUT);

void draw() {
if(millis()>=nextTime) {

void stepForward (int step) {
if(step%4==0) {
} else if(step%4==1) {
} else if(step%4==2) {
} else if(step%4==3) {

I am going to be a d### and say it again... it would be nice if there was one official code and ( and driver example something based on L298 would probably be ok for most users)) for a CNC controller that can work with mach3 or EMC :)

yeah I know I know I can make one myslef... probably I could but if there are ppl better than me at this stuff then... :)

Thanks for the reply.

I take your point, however, I was more looking for an insight into what makes the Igoe Arduino Stepper Library work with just a ULN2003 (32p), whereas when exactly the same algorithm is implemented in another environment, it doesnt. So, curiosity, plus the desire to not have to get a driver (£10-£15) to run a stepper motor

Controlling the Arduino IO via Processing is all done through the serial port. This will always be way too slow to implement a step motor controller with. The stepper motor controller will have to be implemented in native Arduino code (just use the Stepper library, no point reinventing the wheel), then just use Processing code to issue move commands to the Arduino.

Thanks alot, that makes perfect sense. Im sure Im begin horrifically dense, but how would I trigger something thats uploaded onto the board from an external program like processing? In my mind I can read from inputs and write to outputs so I can't work out how I would do it. Im sure its really simple, sorry


It would typically be done via Serial comms.

The processing sketch would send a string through RS232 to the Arduino, ex. "SX20", or "SY-10".

The Arduino would have to receive and interpret these strings to mean: Step x-axis 20, Step y-axis -10, and control the x and y axis steppers accordingly. It could alternatively send serial data back to the Processing sketch to let it know when the moves have completed.

That is brilliant, thanks alot, you've saved me infinite hassle. The only reason I was building my own was because I thought I would be unable to have the stepper library on as id overwrite it when I put on firmata or SMS. Everything makes sense now