Nema17 Stepper Motor Microstepping
by rickbme in Circuits > Arduino
10913 Views, 8 Favorites, 0 Comments
Nema17 Stepper Motor Microstepping
So this will be my first instructable, and I'm sure I'll need to update things as I find issues with it. I'll try and fix things as time allows and with feedback. Thanks!
All the information I found searching for steppers and micro stepping was either too basic, or went into so much detail my eyes glossed over after a few pages. This is the result of my own take on steppers and micro stepping.
I've put together a simple Nema17 Stepper Motor setup that will demonstrate micro stepping and explain just a bit how things work and some sample code to see it in action.
Oddly enough my enjoyment comes from finding out how things work more than actually using them to build something :) ya I know, Weird! Anyway, here's a little something I came up with to satisfy my curiosity about steppers and micro stepping. The code is a bit over commented, but I wanted to try and answer any questions that may arise while looking it over. There's tons more to be learned but this should help get you started on your journey.
Code was written for an Arduino Nano, a DRV8825 stepper driver board and a Nema17 stepper motor (17HS4401S). It was also compiled and tested on an UNO R3 and a MEGA2650 R3. Hope this helps someone in a project or maybe just wants to know how your 3D printer or maybe CNC actually does those really smooth moves. Free to use in anyway you like.
Lets get started!
Parts Needed
If your looking at this instructable you probably have most,if not all of these, already. For those that don't here is what you'll need to duplicate things.
1. Arduino Nano, Uno R3, or Mega2560
2. Nema 17 Stepper motor. You could use any 4 wire stepper in all likely hood, but this is what I had
3. 100uf 25v electrolytic capacitor. We need this to handle any voltage spikes that can occur while running our stepper. 45v spikes can occur so lets be safe!
4. DRV8825 stepper driver board
5. Breadboard
6. Breadboard wires
7. Volt meter.
8. A power supply. You can use anything from a battery to a dedicated power supply. It just needs to supply 12volts and at least 1 amp. Preferably 2 amps as the driver will handle up to 1.5 before shut down.
Wiring Things Up!
Here's our schematic we'll use to wire things up. Your stepper may or may not have the same color wires. In this case you'll need to determine which wires are which windings. You may need to check your datasheet to determine how to connect yours.
One way to do it would be to measure the resistance of your stepper. Out of the 4 wires, 2 pair will read somewhere in the vicinity of 3ohms. These 2 pairs are your A and B windings. So just connect each "pair" to the DRV8825. 1 pair to A1 and A2, and the other pair to B1 and B2. Don't worry about polarity too much. If you have either one of the pairs swapped, the motor will simply turn an opposite direction. I know. I tried it! Just make sure each "pair" is connected to the same A or B on the driver.
Adjust the Vref
After you have everything all wired up and ready to go, we first need to set the vref of our DRV8825 board.
Flash your Arduino with the Stepper_Board_Adjust code. This will simply allow us to turn off and on the driver board.
Disconnect the stepper.
Open the serial monitor and turn the driver on. The code should be showing a simple menu. If not, double check your Arduino connections.
Grab your volt meter and connect the ground to the Logic Ground on the breadboard. Using your pointy positive lead connect it ever so gently to the small metal tab next to the potentiometer. Careful your shaky hands don't move it anywhere! Take a look at the image to see where to touch the lead. You make have a test via on your board near the adjustment you can use. Lucky you!
Slowly adjust the potentiometer with a small screwdriver (careful again! No coffee until you are done!) until you get around .8 volts. This will be a good starting point.
Good work so far!
Downloads
Flash the Main Code
Here's the code we'll be using to have our fun!
Now it's time to flash the main code to your Arduino.
I'm not going to go into a detailed description on connecting and configuring your Arduino. If your here reading this you know how to do this already. :P
Take a quick glance at the code. There are some comments that will help explain a few more things.
You will however need to load the <Accelstepper.h> library. This can be done in the Arduino IDE in the library manager.
After you have the library loaded, go ahead and flash your Arduino.
Open the serial port and if things go well you'll see a menu. Great job!
The rest is up to you!
I hope this was helpful in your quest for knowledge and fun. I know I learned a lot making this!
Thanks!
Downloads
Notes
A couple notes.
Always remember to never disconnect your stepper with it powered up. Always shut down the power first.
If you find your stepper is skipping steps at lower speeds and acceleration, try raising the vref a little at a time.
Microstepping!
This was taken at 30 revolutions, 1/4 step, 5000 speed, 3000 accel.