Thursday, September 11, 2008

A quick tutorial on how to get things up and running with the EasyDriver v3.1 Stepper Motor Driver Board. A big thank you to Brian Schmalz, the designer of this board. It's obvious why he has called it the EasyDriver. It was indeed, an "EasyDriver" to set up ;)

PLEASE NOTE: some people have overlooked the extra (ground) pin on the easydriver board. It is not labeled on the board itself, but it is visible as the top right pin in the picture above. Grounding the easydriver board is essential but sometimes overlooked by newbies like myself :)

WARNING Easy Driver v4.2:
Please do not attempt this tutorial with new Easy Driver v4.2 board. Please consult the QA for version 4.2 on the Easy Driver Site for explanations on 4.2's extra functionality. For more information you can always look at the Data Sheet and Schematic as well.

Here is a copy of the code used in this Video:

////////////////////////////////////////////////////////// Stepper Motor skecth for use with the EasyDriver 3.1 ////////////////////////////////////////////////////////// Dan Thompson 2008
//// Inpired by the code and chat on this thread.
//http://forum.sparkfun.com/viewtopic.php?t=10378&highlight=easydriver//// Use this code at your own risk.
// For all the product details visit http://greta.dhs.org/EasyDriver/// For the full tutorial visit http://danthompsonsblog.blogspot.com///int dirpin =3;
int steppin =12;
void setup() {
Serial.begin(9600);
pinMode(dirpin, OUTPUT);
pinMode(steppin, OUTPUT);
}
void loop()
{
int i;
digitalWrite(dirpin, LOW); // Set the direction.
delay(100);
Serial.println(">>"); for (i =0; i<4000; i++) // Iterate for 4000 microsteps. {
digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the
digitalWrite(steppin, HIGH);// "Rising Edge" so the easydriver knows to when to step.
delayMicroseconds(200); // This delay time is close to top speed for this
} // particular motor. Any faster the motor stalls. digitalWrite(dirpin, HIGH); // Change direction.
delay(100);
Serial.println("<<");
for (i =0; i<4000; i++) // Iterate for 4000 microsteps {
digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the
digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step. delayMicroseconds(200); // This delay time is close to top speed for this
} // particular motor. Any faster the motor stalls.}

Hi Dan - I like the tutorial! I was thinking that you might want to point out that the pin you used to create a common ground between the arduino and easydriver is a "hidden" ground, in that it isn't labeled on the board. (I didn't fathom that it was a ground myself until the other day when someone pointed it out =) This might help the new guys not sure of why you hooked up there.

WOW. Thanks for that tip about the "hidden" ground pin. I bought an easydriver v3 and the motor from Sparkfun over a year and a half ago for another project, and I couldn't get it to work. Now I have found out why. I feel like a retard, but thanks :)

I am using the same parts you are. Our project needs good accuracy so I did some testing...

Just some FYI for those needing accuracy:I noticed stepper errors at anything under 12.6 volts (which you are probably experiencing). They advertise +- 5% on the motors, though neither of mine had any error. So it took 1600 steps with the EasyDriver board ( 360 / (1.8 * 1/8)) without needing to account for error to go one full rotation at >12.6 volts (max ~15.4 volts).

I planned on using this exact board and motor, but I was unaware until watching your video that the controller micro stepped..does this affect the holding torque of the motor? If you try can you stop the motor with your fingers while the motor is running or does it have the torque to pull through them?

Hi Dan,Can't say enough about your site here. The tutorial is amazing and has helped me decide to go with the EasyDriver for my stepper project. Thanks!

Would you mind sharing your source for the breadboard-compatible screw terminals (2.54mm pitch and decent length pins)? I've been looking all over but only find PCB-compatible terminals (with the shorter pin lengths).

Great post (and great site also)!Any idea why it's necessary to have a 100μs delay after each pin write?According the the docs on the chip the EasyDriver uses, it seems like the level only needs to be held for 1μs. So far, I've only been able to reduce the delay to 50μs without losing steps.

Hey Mike, I guess it comes down to the hardware in the end. I found that anything under 80 and my stepper struggles. Acceleration is also a contributing factor. Eventually, I plan on checking out the fscale library to see if I can get the motor to go faster when using a slow logarithmic acceleration curve to "ease in" to top speed.

Personally I'm thinking if it's speed you want, then maybe microstepping is not the best solution. If you are game enough and have a steady hand, you might be able to modify the board. The chip is capable of doing full and half steps as well. But the ED3 board isn't set up to do this.

Hi Dan,I posted a comment regarding the torque of the stepper a while back.. Thanks for your response!! Would you mind emailing me so I could pick your brain on some planning issues I'm having on my project? I don't want to clog up your blog spot....blaing65@yahoo.com

Is there any way you can manually enter the number of steps you can take in either direction using the serial monitor and the Serial.read() function. Can you please help me with trying to figure this out as I am stuck with this. Thank you and AWESOME tutorial.

I think your question has been well answered on the Arduino forums, but for those who are interested in controlling the stepper with some simple serial commands check out this example code on this post:

Thanks a lottt Dan. The comments helped me a lot. Also the code on the Forums works fine. I just have a problem with the baud rate. after I key in lets say "100+". Until I change my baud rate to any other value my motor doesnt move. Is it supposed to take long and then move by itself or changing the baud rate is what is actually moving the motor?Thank you so much.

Just add an extra delay after you pulse the motors high. So delay an extra 10,000 microseconds (10ms) after you pull the step pin low. I'm using an ATmega128 microcontroller in my project so I just pulse the pin high for 100us, leave it low for 100us, and continue to leave it low for any extra delay I wish to have between steps. I recommend creating a "step" function that pulse high for 100us then low for 100us. After calling this function you can add any delay you want before the next call to it.

[nathan]The same probleme.. ; ( and I realyse something, I gave 800 pulse to easydriver and motor turn only 100 time in one revolution.. ? (on 3.6 degree motor)200 uSec time HIGH and 500mSec time LOW... ?

I buy a EasyDriver v3 board in Sparkfun.com. I'll build a PCB laminator like this: www.py2bbs.qsl.br/laminador.php but with the easydriver and a bipolar stepping motor.The only function of the motor is spin very slowly in one direction. Pleasy tell me what can I do to do this? I have to add a 555 generator for the step input? And what i have to do with the dir input?

I don't understand nothing about stepping motors and driver. Pleasy help me.

It sounds like KzCorp might be trying to control the easydriver without an Arduino, just using a 555 to generate the step pulses. In that case, the dir input could just be tied high or low to move in one direction, depending on how the stepper's hooked up.

Hi all.Dan, thenks for your nice tutorial. sorry for my english ;-)I want answer Samuel.Yes; it is possible to make slow steps!!

Hi have a problem that his Stepper motor not make microsteps but only big full steps.

To undestand it you must undestand the theory of microsteps and the Allegro A3967. Full Step: everytime 2 winding of the stepper motor are on.Half step: between 2 full steps is a half step who is given current to only one winding. This make that the rotor rotate a half step.

In both case (full and half steps) the current can are limitated to the winding resistance. Not necessary by the driver circuit.

Quarter step It is used a limiting the current of the motor by the chopper mode of the driver. When you look 2 windings: the current is sequential: 100%-0%, 92-38, 70-70, 38-92, 0-100 of Imax (setting point with the adj pontentiopmeter on Easydrive) In this way the rotor make steps between half steps.Eighth step or more: the motor current is modulated by the driver in a bigger number of steps.

ok this is the theory. Now the solution of the problem.

If the stepper motor is a motor with a highter resistence (20 ohm or more) the Alegro A3967 cannot limit the current in the windings to make a eighth step bycause the current is limiting by the resistece of the motor winding not by the chopper function of the driver. Example: The max current of a 50 ohm motor on 12 V is 240 mA. The limit of the driver is set to 750 mA. The first eighth step are 140 mA and 735mA. This value are not the current of the motor. The motor current are 140 mA and 240mA. The motor make a big step not a small eighth step (aproximatly a half step).

To resolve this problem: You can try to limit more the max current (turn the limit to lower value, up to 150 mA), use a higher power supply (you can use up to 30 V) or use a other model of stepper motor.

I hope my explaning is comprehensible and helpfull.in peace Uwe.

A nice page that explan microsteps:http://www.zaber.com/wiki/Tutorials/Microstepping)

With regard to the delays surrounding a STEP pulse. I have found it unnecessary to add any 'high' delay. I just have two consecutive lines of code that say 'stepPin HIGH' then 'stepPin LOW'.

Mike commented earlier that the docs for the EasyDriver say it only needs a 1μs pulse. Given that the Arduino takes longer than that to execute a line of code I figured it was not a problem.

I am of course using a longer delay after the pulse to control the speed of the stepper. I've had it down to about 70μs running happily but it must be noted that you can't go from standstill to a 70μs step cycle - the motor will stall. You have to ease your way up there.

Yeah, the two drivers are wired in identically. One is on pins 2&3 (driver A), one on 5&6 (driver B). A works in 2&3 and 5&6, same with B. But when I have both A and B plugged in, only the motor on 5&6 runs.

In sum: both motors work, both drivers work, all 4 pins work, the code is right.

Maybe I need to put resistors in front of the drivers somewhere to even out power distribution?

@everyone: Brian Schmalz has now released the EasyDriver v4.2 — which brings a number of refinements and new functionality... such as the ability to modify the microstepping output (full, quarter, half and eighth step). Excellent! Thank you Brian!!

Thanks a lot, Dan. Things seem to be working ok. I have another question, though.

I want to set the speed with a potentiometer. If the maximum value of the analog input in the arduino is 1023, but I want to maximum speed of the stepper to equal 200 (delayMicroseconds) as you've done, how do I write that?

I'm assuming there's some sort of mathematical equation multiplying the sensorValue of the pot by the ratio of 1023 and 200 (0.195), but I really have no idea.

Hi Dan I like and used your tutorial and code as I am new to Arduino and stepper motors, I bought the ED4 board from Sparkfun connected as per your instructions and nothing happens, the only way I can get it to rotate is by shorting the STEP pin and DIR pin together with the respective pins still connected to Arduino then I can change the speed and amount of turns but I can't change the direction of the motor, any ideas.

Yes I'm getting that feeling trouble is I bought it from Sparkfun and I live in New Zealand but my findings do seem to suggest that the board is indeed duff. I think I'll order a v3.1 from my local supplier and try again.

The biggest develpment recently has been offloading the control and move-setup side of things to my computer rather than (as I had been) developing a handheld controller with LCD screen. The reality was I was spending excessive amounts of time in getting the setup and control part working and not refining the code that does the actual moov.

Now I just pass a bunch of numbers to the Arduino down the USB and it gets on and does the magic. Much quicker but I do have to lug a laptop around on the shoot. Swings and roundabouts.

In time I'd like to replace the USB cable with a Bluetooth link. Apparently it's easy to do, but it requires £40 that I don't have right now!

I'm presently awaiting two EasyDriver v4.2 cards which will replace the 'one-way-only' v3.1 card that's currently running the track moves, and open up PAN! — which I've yet to build ;)

Further to that I'm wondering about doing TILT with a servo - which I've got on hand already so it might be worth a play.

Hey Dan, funny that we just met last week at the hackerspace meeting, and then I stumble onto your blog while looking for information about the EasyDriver board I just from SeeedStudio.com ;)

After playing with it using your Arduino sketch, I quickly discovered that microstepping completely obliterates any torque in my ex-scanner stepper motor, so I attempted to modify the board to ground MS1 & MS2 to select full stepping. I seem to have been successful. Here's a photo of the modified board.

http://www.flickr.com/photos/_xiq/4380726669/

Now I notice that when the Arduino is resetting it causes the motor to move a few steps. I might not have noticed this before because most of the steps under 8x microstepping had no effect. Perhaps I need a pull-down resistor on the step pin.

But could you tell me how to make a stepper motor only turn xnumber of turns then stop, every thing I try and the motor keeps turning as the code keeps looping I have searched every where and still no luck. example I flick a switch and the motor moves one turn clockwise I turn the switch off and the moves one turn counterclockwise I am sure it's not that hard but I have spent far to long on it and need a helping hand on this one.

Nice hack on the Easy Driver board! I've been wondering if that would work for a while now. Just wasn't gaim enough to try it.

The new Easy Driver v4 board now gives you access to the different stepping functions as well as various sleep methods which may help with your issue. Or like you said maybe a pull down resistor would do the trick also.

I am using the same stepper motor and the stepper controller v43. The power I have hooked up to the v43 is a 12V car battery. However, I am able to stop the stepper with my thumb and for finger. Not sure why this is. Is it programming or is this motor not designed to handle all that much resistance?

Thanks for this tutorial and your more recent with the easydriver v4.2.

I've worked through this an have things working fine. (thanks) I'm attempting to get a very low rpm... about 0.2rpm or 1rph. Things start to stall when playing around with timing of this code. I've been scouring the various forums and blogs but have yet to find an alternative coding solution.

Any suggestions? Can steps() or setSpeed() be used with an easydriver?

Hi Dan, thanks for your tutorial it was a great help i have a question thou would it be possible to make an stepper motor move say 500 revolutions and then stop by a press of a button i have been looking all over but cant find any example help any where