Pages: [1]   Go Down
Author Topic: A Stepper Motor Library all of my very own  (Read 1199 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
  }
  nextTime=millis();
  in1=8;
  in2=9;
  in3=10;
  in4=11;
  gap=(1000*60)/(speed*steps);
  frameRate=300;
}

void draw() {
  if(millis()>=nextTime) {
    stepForward(stepNo); 
    stepNo++;
    nextTime=millis()+gap;
  }
  System.out.println(frameRate);
}

void stepForward (int step) { 
  if(step%4==0) {
    arduino.digitalWrite(in1,Arduino.HIGH);
    arduino.digitalWrite(in2,Arduino.LOW);
    arduino.digitalWrite(in3,Arduino.HIGH);
    arduino.digitalWrite(in4,Arduino.LOW);
  } else if(step%4==1) {
    arduino.digitalWrite(in1,Arduino.LOW);
    arduino.digitalWrite(in2,Arduino.HIGH);
    arduino.digitalWrite(in3,Arduino.HIGH);
    arduino.digitalWrite(in4,Arduino.LOW);
  } else if(step%4==2) {
    arduino.digitalWrite(in1,Arduino.LOW);
    arduino.digitalWrite(in2,Arduino.HIGH);
    arduino.digitalWrite(in3,Arduino.LOW);
    arduino.digitalWrite(in4,Arduino.HIGH);
  } else if(step%4==3) {
    arduino.digitalWrite(in1,Arduino.HIGH);
    arduino.digitalWrite(in2,Arduino.LOW);
    arduino.digitalWrite(in3,Arduino.LOW);
    arduino.digitalWrite(in4,Arduino.HIGH);
  }
}
Logged

0
Offline Offline
Full Member
***
Karma: 6
Posts: 229
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley

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...  smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

New Hampshire
Offline Offline
God Member
*****
Karma: 17
Posts: 781
There are 10 kinds of people, those who know binary, and those who don't.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Louis
Logged

New Hampshire
Offline Offline
God Member
*****
Karma: 17
Posts: 781
There are 10 kinds of people, those who know binary, and those who don't.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Thanks
Logged

Pages: [1]   Go Up
Jump to: