Introduction: Identifying Stepper Wiring With the Pmod STEP
"Oh no! Not yet another stepper motor tutorial!" Well yes and no. This tutorial will explain how stepper motors work and how to use them, but that's not all.
For this tutorial, I'll be using the Pmod STEP sold by Digilent. This board is essentially a breakout board for the ST L293DD, which is a motor driver with four channels. What's nice about this motor driver is that it can be used to function like an H-bridge, without the risk of shorting out! That means you can safely play around with stepper motors without worrying about damaging any of your hardware.
I'm taking advantage of that useful feature to explore how stepper motors work, and show you how to map the wiring for a completely unknown stepper. No googling part numbers, or searching for data sheets, just a little good old fashioned fiddling with circuits.
Let's get started!
For more things that I've done, you can check out my profile page!
For more info from Digilent or the Digilent Makerspace, check out the Digilent blog!
While you're there, consider signing up for the Digilent newsletter!
Step 1: What You'll Need
In order to figure out the wiring for your stepper motor, you'll need:
- A stepper motor of any kind.
- A breadboard.
- Breadboard wires.
- 220 Ohm resistors (x4).
- Breadboardable push-buttons (x4).
- The Pmod STEP from Digilent.
- An Ohm-meter.
- A pad of paper and a pen.
- Something long and thin to use as a dial. (I'm using a pen cartridge.)
- A hot glue gun (and some hot glue of course).
It can also be helpful to have a some sort of 6-pin splitter cable, but wires with female header pins will work too.
I'll also be showing you how to use the Pmod STEP with a microcontroller, so you'll want one of those too. I'm using the WF32.
Step 2: Angle Indicator
Stepper motors can have very small rotations for each step. This makes it difficult to keep track of what angle you're at. To make the change in angle a little more obvious, we're going to glue a dial onto our stepper motor.
Set your stepper on its end, with the shaft pointing upward. Use hot-glue to glue your dial on at an angle. You want the tip of your indicator to rest just above the surface of a notepad or piece of paper. This will let it move freely, but also keep it close to the paper so you can mark where it points later.
Step 3: Stepper Theory Part 1: Types of Steppers
Essentially, inside a stepper motor there are several electromagnetic coils surrounding a magnet. In order to make the motor take a step, we power each of the coils in turn.
Check out the first picture in this step. It's a diagram of the four most common wiring for stepper motors. These are called 4-wire, 5-wire, 6-wire, and 8-wire respectively. They're named for the number of wires coming out of the case, in case that wasn't obvious.
However, there are actually only two types of steppers, as we'll see next.
Step 4: Stepper Theory Part 2: Bi-Polar Steppers
4-wire stepper motors are the most common. These are also known as "bi-polar" steppers because of how they operate.
I'll do my best to explain, but you should check out the diagram above, because that will do a much better job.
In a bi-polar stepper, there are only two coil sets, and each coil only has two leads. We make these motors step by polarizing one coil, then the other. That's two steps.
In order to make the third step, we switch the polarity of the first coil. The fourth and final step is made by switching the polarity of the second coil. Then the whole process repeats.
This change in direction or polarity of both coils is why these motors are called "bi-polar". They're a simpler design, and also more powerful, but also more complex to use because you must not only energize each coil, but also be able to switch polarity for each.
I've embedded a video by Kevin Darrah where he demonstrates stepper motor operation using just some buttons. This is a good video in its own right, but notice how his tutorial uses 8 buttons. That's because he's using a bi-polar stepper motor, and making his own H-bridge with those buttons. As we'll see later in this tutorial, using the Pmod STEP, we only need four buttons.
Step 5: Stepper Theory Part 3: Mono-Polar Steppers
Mono-polar steppers are less powerful than bi-polar steppers, but easier to use.
In the diagram above, I show how a 5-wire stepper operates. Notice how the center lead of both coil pairs is connected to a common ground? In 6-wire steppers, that common ground is split into two grounds, one for each coil pair, and in 8-wire steppers, both of those grounds are split into individual grounds for each coil.
This type of stepper is called "mono-polar" because each coil is only ever polarized in one direction. This makes these steppers easier to use, because you don't need to switch polarity. If Kevin Darrah had used a mono-polar stepper in his video, he could have gotten away with only 4 buttons.
Step 6: Bi-Polar Coil Identification
Before we wire up our stepper motor, we need to identify which leads are connected to the same coil. To do this, we can use an Ohm-meter. For each lead, two of the other leads will result in a "no connection" signal from the Ohm-meter, while one of them will result in some small resistance.
It's also possible to use a simple battery and LED as a logic probe to test these connections.
(It's always worth writing these values down so you don't lose track.)
Step 7: Mono-Polar Coil Identification
Mono-polar steppers are a little more difficult to identify, especially with the 5-wire stepper I used.
In this case, we'll use our Ohm-meter to check the resistance between each wire. Most of the wires will have some normal resistance, but one of the wires should always give half the normal resistance, no matter what other wire it's connected to.
This is because the stepper's coils, like any electrical component, generate some resistance when powered. When you connect two coil leads together, you get the resistance of two coils in series. However, when you check the resistance between the common ground and any of the other coil leads, you only get the resistance of one coil. That's why the resistance is halved.
So our goal here, is simply to find out what resistance represents a single coil (the smaller resistance). Then we find which lead gives that resistance for all the other connections. That lead will be our common ground.
(Again, it's worth writing these values down so you don't lose track.)
Step 8: Pmod STEP Theory
Before we start using the Pmod STEP, we should know a little about how it works.
The Pmod STEP operates, essentially, like four two-way switches. Each output, by default, connects to ground. Bringing the pin for that particular output high, effectively throws the "switch" so it connects to VDD instead.
By wiring these four outputs as shown above, each coil of the bipolar stepper motor can be activated individually simply by bringing one of the outputs high. What's more, the polarity of each coil can be reversed by bringing the opposite output high.
With a normal H-bridge, there's a risk of shorting, which will destroy your H-bridge, and may damage your board. The nice thing about the Pmod STEP is that it completely prevents the risk of shorting out. That means you can play around as much as you like, and you don't have to worry about damaging it!
Step 9: Button Wiring
Now it's finally time to wire our test circuit.
This amounts to several buttons with pull-down resistors, each connected to one of the pins on a 6-pin, male header. The first two pins on the header being power and ground, respectively. It's this header that we're going to connect to the Pmod STEP.
Step 10: Connecting the Pmod STEP
In this step it's very important that you pay attention to the little, three-lobed symbol on the cable connecting the Pmod STEP to the board. I refer to that as the cable's "paw print", and it indicates the cable's direction. The lead closest to the paw print on one side will be closest to the paw print on the other.
This is important to keep track of, because while installing the cable backwards will not damage the Pmod STEP, it will prevent the board from functioning properly.
(I've included the paw-print on the breadboard layout and schematic above, so you can see how the pins on the Pmod STEP connect to the button circuit.)
Step 11: Connecting the Stepper Motor
The Pmod STEP is designed for 4-wire and 6-wire connectors, but it's easy enough to connect a 5-Wire, as I've shown above.
The trick is that the central two pins on the 6 wire connectors are VDD, and the two male connectors on either side of the 6-pin connectors are ground.
To connect the 5-wire motor, I used a splitter cable to connect my common ground to one of the grounding pins, while my 4 signal pins went to the 4-wire connector.
Step 12: Testing Your Motor
It's finally time to test your motor!
With the buttons connected to the Pmod, and the Pmod connected to the motor, press each of the four buttons. You should see the indicator jump to different positions. While it's possible to make your motor go through an actual rotation this way, it's unlikely to do that using a random combination of button presses.
Now, press and hold one of the buttons. Use a pen to mark where the indicator points, and which wire is being pulled high to get to that position.
Do this for all four buttons, and you should get all four positions, and which wire needs to be pulled high.
Step 13: Rotating Your Motor
Now you know which button will take you to what position. If you press those buttons in order from right to left, the motor will rotate left. If you press them in order from left to right, the motor will rotate right!
Step 14: Connecting the Pmod STEP to the WF32
Now that we know our stepper's wiring, we can get rid of the test circuit and connect it to the WF32.
I used my splitter cable from before to separate the signal lines from the power and ground, and plugged it directly into the WF32.
Step 15: Code
This step includes a sketch that will rotate your motor one way, and then the other.
To use it, simply enter the pin numbers for each coil in the order they are activated. This is the same as the order in which you pressed their buttons to rotate the servo. See the second picture for an example.
The first part of this sketch will rotate the servo using full steps. This means that when one coil turns on, the next turns off.
The second part of this sketch takes advantage of something called "half-stepping". This allows the servo to take a half-step in between each full step, thus doubling the number of steps it can take in one full rotation.
As you watch the motor move, you should notice that one rotation is faster than the other. The faster rotation uses full steps, while the slower one uses half steps because it has to take twice as many steps to do a full rotation.
Step 16: What Is Half-Stepping?
In half-stepping, instead of alternating coils, where one coil is on while the other is off, two coils are turned on at the same time. This creates a sort of "half-step" while the magnet is caught between coils. This doubles the steps a stepper can take in a full revolution (thus increasing the resolution and making the motor capable of more precise movements).
Not only that, but because the stepper is using both coils to hold the magnet in position, half-stepping can also slightly increase the strength of your stepper.
Step 17: Pros and Cons of Steppers
As you probably already know, stepper motors are used everywhere from 3D printers, to claw machines, to a certain plate and ball desk-toy. With so many applications, it can be easy to just assume steppers are the best choice for any given application, but that's just not the case.
Steppers are very precise, and can make repeated movements without accumulating error. That makes them ideal for applications that require precision, like 3D printing (or a certain ball and plate desk-toy I could mention). However, that's only true if you use them right.
Because of how steppers are driven, they tend to be very weak compared to other motors of their size, and because they have to take so many steps in order to move, they also tend to be very slow. If you try to make a stepper spin too fast, or if you make it push too hard, it'll miss steps and lose its accuracy. Unless you have something that can sense the position of the motor shaft itself, all your subsequent steps will be one or two steps behind.
Now, that's not to say that stepper motors can't be used for applications requiring a lot of torque, and it's not to say other motors can't achieve the same level of accuracy that steppers do, but be smart about what motors you chose.
Step 18: That's It!
And that's it!
Of course there's more you can explore from here. There are more tricks you can do with stepper motors, such as microstepping, but this tutorial has covered more than enough of the basics to get you going!
So get stepping!
(See what I did there?)
We have a be nice policy.
Please be positive and constructive.