Thursday, September 11, 2008

EasyDriver v3.1 Tutorial

Update: I've posted a new Easy Driver 4.2 Tutorial for those who are using the new design.


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

69 comments:

Anonymous said...

Awesome tutorial. I like the way you filmed the video. The closeups of the Arduino and the stepper motor look great. I also like the music and the narration. Keep up the good work!

isarmien said...

Hi, Dan. Our site sell those three components that your are using here.

Can we link this tutorial in our site?

http://www.olimex.cl

greetings
Iván Sarmiento
Ingeniería MCI.

Dan Thompson said...

Hi Ivan, Sure no problems. Copy and paste what ever you need. Post links to this blog or embedded html on your site (Either way I don't mind).

Same goes for anyone else out there who sell any of these products.

Nick Deboar said...

Hey Dan,

This is so bizzare. I'm from adelaide too and I work in a VFX studio in Manchester now. And I just built my stepper setup last night using the same driver!

Small world!

Anonymous said...

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.

Anyhow, great tutorial and video!

!c

1 said...

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 :)

Dan Thompson said...

No worries, Glad I could help. The same thing happened to me first time round :)

There are other ways you could ground the ED3. This way just made the most sense as the pin provides extra support on a breadboard.

nb2000nb said...

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

Good luck,
Nathan

Anonymous said...

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?

Excellent ,excellent, video. :)

Dan Thompson said...

I could not give you the exact numbers, but yes the motor does have plenty of torque to keep spinning without a hitch when you try to stop it by hand.

One of my only frustrations with the easy driver board, is that it will only do micro stepping, 1/8th of a step.

The chip on the board can do half and single steps as well, but the board is not configured to deal with that.

So if it's speed you are after over precision, I would go for a board that can do single stepping.

Dan.

Anonymous said...

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

Jay
Albany, New York, USA

mike said...

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.

Dan Thompson said...

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.

Dan

Dan Thompson said...

Hey Jay,

I got breadboard from Dick Smith Electronics Kind of an Australian version of Radioshack I think. I got mine as a kit but I think they sell the pins separately as well.

Anonymous said...

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

Thanks Dan!

Unknown said...

Hey Dan,

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.

Dan Thompson said...

Hi srinivas,

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:

Serial communication

It works a great!

Unknown said...

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.

Unknown said...

Hi Dan, thanks for the good tutorial!

I want to know if its possible to use microstepping at low speed..like one revolution per 5 seconds ? with full microstepping résolusion.. (10 ms between step)

Each time tried I get jerked rotation ? It's a long headhack for me !

MERCI

nb2000nb said...

Samuel,

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.

Unknown said...

[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 put magnetic encoder (with someting like 8165 resolution) finaly I never see microstepping I only saw flull stepping 3.6 degree? on Easy driver ver3 ?? ..weird

KzCorp said...

Hi Daniel, how do you do?

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.

Thanks a lot.

Best regards.

from Brazil.

KzCorp®.

P.S.: forgive me my poor english.

Dan Thompson said...

KzCorp,

I have not had any experience with the motors you are using so I cannot comment on that.

maybe posting your questions on this forum will help:

http://forum.sparkfun.com/viewtopic.php?t=10378&highlight=easydriver

I can't see why you would need a 555 timer for any reason as the arduino takes care of all of pulses for step and direction pins.

I'm no expert on stepper motors either, but there is a lot of info on the web if you do a search.

Good luck!

Dan.

p.s. remember that the easydriver does microstepping so it may seem slower at first than drivers that do full step increments.

mike said...

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.

uwe said...

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)

Marcel said...

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.

hth

[m]

Dan Thompson said...

Marcel, uwe,

Thanks for posting this info. I've been so flat out with work the last couple of months, I haven't had the time for any real useful blog posts.

This practical information is much appreciated.

Thanks again,

Dan.

Laura Greig said...

Dan, thank you for the amazing tutorial, it has been super useful. Hope you don't mind it making you the defacto "Easydriver guy".

Has anyone had success using multiple Easydrivers off one Arduino? If so, did you have to do anything special? Not working for me and neither is the Arduino forum...

mike said...

[Zillathustra] I only used one Easydriver on an Arduino for initial prototyping, but have used two with a different controller without any problems: http://www.flickr.com/photos/pixl8ed/3550190829/

You'll need to use two pins (four total) to control two Easydrivers.

What'cha making?

Laura Greig said...

Thanks Mike!

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?

Laura Greig said...

Oh, wow, nice Etch-a-Sketch rig!! That is super cool.

I should add I'm using 2x 12V steppers w/ external power from a 12V transformer->wall.

Thanks!

Dan Thompson said...

Hi Zillathustra,

I'm certainly no expert on this. But it could be that you don't have enough current from you power source to run both motors at the same time, but that would be a complete guess.

Maybe try the Arduino or Sparkfun forums for a more informed answer. Good luck!

D.W. Jones said...

Great tutorial, thanks. I've got everything set up with your sketch and it's all running well.

My only problem is that I'd like to just run the program once, then stop without running the loop again.

I'm really new to Arduino programming, so pardon my ignorance.

Thanks.

Marcel said...

@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!!

see: schmalzhaus.com/EasyDriver/

Available from Sparkfun @ $15

Marcel said...

I read this recently...
http://www.instructables.com/id/Arduino-is-Slow-and-how-to-fix-it/

It talks about the speed at which Arduino processes it's DigitalWrite commands (that we use for stepping).

This chap is using C commands instead of DigitalWrite and seeing a 10x speed increase!!

I haven't played with it yet and I don't know what effect it might have on the sort of step commands we're using but it might be worth a play.

i.e. it may need some delays to be added along the way to make the steps long enough for the driver board to pick it up but it may free up time for more axis to be added without hindering each other.

Maybe one day I'll get to play! If anyone else can give it go and report back it would be useful to all I think.

[m]


(having problems posting with my blogger ID)

Dan Thompson said...

Marcel,

You've made my day! A new easy driver with full and half and micro step and an Arduino hack to make my motors go faster!

Two things I've been wanting to do for a long time. Thanks for this awesome info!

Dan Thompson said...

d.w.,

it sounds like you want a "while" loop in stead of a "for" loop.

http://arduino.cc/en/Reference/While

Example:
int i = 0;
void loop()
{
while(i < 4000){
// do something repetitive 4000 times
i++;
}
}

see if you can re-write the code using that example.

Also don't forget to declare i outside of the scope of the main void loop. Otherwise it will just reset when it hits 4000 and start over again.

good luck!

D.W. Jones said...

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.

Alan said...

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.

many thanks

Alan

Dan Thompson said...

Hi Alan,
There are some good tips on the easy driver site about v4.2
http://www.schmalzhaus.com/EasyDriver/

I have been planning on making a tutorial for 4.2 but have not had the time as of late.

I suggest for now to check the data sheet of the chip and the link above as this is the process I will take when I get around to making the tutorial.

Good luck!

Anonymous said...

Maybe try tying each pin to ground with say a 10K resistor.
Marcel

Alan said...

Tried all of above please hurry with ED4.2 tutorial as I really am lost for ideas now.

Thanks for all your help

Alan

Anonymous said...

Well Alan, forgive me, I'm sure it's not what you want hear, but it sounds like you don't need a tutorial.

The datasheet would be a good next step then maybe take a multimeter to it and pass your findings along to your supplier. Maybe it's a duff board.

[m]

Alan said...

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.

many thanks for the help.

Alan

Dan Thompson said...

Alan I have updated this post with a warning about the 4.2 board. Good luck with your endeavors.

regards,

Dan.

b said...

Thanks for your tutorial. I am in the process of learning how to control steppers from the Arduino using the EasyDriver. Here's my first blogpost on the subject:

http://blog.borud.no/2010/02/one-small-step-for-man.html

Marcel said...

FYI. Here's my latest test video.

Accordion Moco

It's just a few closeup tracking passes with my developing rig.

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.

pix said...

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.

Alan said...

Thanks for that Dan she's all going now with a ED3.1

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.

Thanks

Alan

Dan Thompson said...

Alan,

I know there are a lot of comments here. But I think your question has already been answered.

Look at the comment by d.w. on November 3, 2009 1:44 PM

Here is my response to the comment:
November 4, 2009 3:58 AM

Hope this helps. Good luck with it!

Dan.

Dan Thompson said...

Hey Pix,

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.

Hope to see you at the next meeting!

Dan.

kumar said...

thank u for posting this info
it works great

mikethe1wheelnut said...

please see: http://forum.sparkfun.com/viewtopic.php?f=14&t=23742&p=109893#p109893 for my comment. you will see that it is quite long. I tried submitting it here, but that didn't work :-)

looks like a great tutorial!

cheers,

-mike :-)

Unknown said...

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?

Dan Thompson said...

Hi Anthony,

Different motors have different levels of torque. I am no expert in this field. I would suggest looking at the data sheet that comes with your motor to find out it's performance ratings.

Dan.

Robert said...

Hi Dan,

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?

thanks for the tutorials.

Dan Thompson said...

Hi Robert,

I've never heard of a stepper motor stalling at slow speeds. Usually they stall when acceleration is to steep or the speed is too high for the motor/power supply combination.

delayMicroseconds(200); is the line you need to play with for speed changes.

you might want to try the delay() command instead of delayMicroseconds().

if you look at the http://arduino.cc/en/Reference/DelayMicroseconds

In the description it says:
"For delays longer than a few thousand microseconds, you should use delay() instead."


here's the docs on how to use delay()
http://arduino.cc/en/Reference/Delay

Good luck with your findings!

Dan.

Unknown said...

hey man, I'm form Mexico
I wanna use this picture for my blog
I wanna know if you agree

You gonna take all the benefits of course

I just want to make people know how tu use easy driver and arduino and I've pasted the image with your URL's blog

Thank's, my blog is:
http://hazafantasycnc.blogspot.com/

if you dont want to, please tell me

Dan Thompson said...

Sure no problem Hazael,

thanks for checking with me I appreciate it. There is another tutorial on a more recent easydriver board also. http://danthompsonsblog.blogspot.com/2010/05/easydriver-42-tutorial.html

Have fun!

Ross said...

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

Dan Thompson said...

Hey Ross,

I made this post just for you! see if you can modify it to make the stepper move 500 revs each time the led is switched on.

Let me know how you get on!

http://danthompsonsblog.blogspot.com/2011/12/arduino-push-button-onoff-example.html

Anonymous said...

hi dan will your code work on big easy v1.2 driver

ankur said...

hello
is there any way i could add limit swtiches to arduino or easy driver.

Unknown said...

come posso collegare due pulsanti (interruttori) per comandare il motore in avanti o indietro ? E' possibile e se si come secondo te

Grazie

Unknown said...

Hello Dan Thompson
Could I can contact you by email?

Unknown said...

Hello Dan Thompson
Could you give your e-mail adress?!
Please!

Chetan's Blog said...

hi sir,
i want arduino sketch for
stapper motor for multi speed with multi steps
1. 1 turn at 100 steps
2. 2 turn at 2000 steps
3. 4 turn at 150 steps

please give me guide .or link of sketch

chetan98250@gmail.com

Md Mubarak Hossain said...

Peace be upon you.

I wanna use Nema34 stepper motor which are big size need 50v and 5-10A current.
Therefore, what kind of driver I should use?
Does V3.1 OK for such big motors?

Harish Kumar said...

SantaMedical brings the range of improved and upgraded oximeters. This SM-165 finger pulse oximeter device is one of the best and the latest inventions from SantaMedical. Buy Now at Santamedical.com
Fingertip Pulse Oximeter