Jeroen Swart

.NET Architect

Netduino - Getting Started with steppermotors

Working with steppermotors is a bit more complex then working with regular DC motors. Apply a voltage to a DC motor and it will rotate. With stepper motors, you need to apply that voltage in a specific pattern.

Instead of using a single coil, as in a DC motor, most steppermotors use two coils. The number of steps is determined by the number of magnetic poles on the rotor. Two common types of steppermotors are unipolar and bipolar steppermotors.

Bipolar & unipolar

A bipolar steppermotor is controlled by reversing the polarity of each coil in the right order. A more detailed description of how a bipolar steppermotor works can be found here.

In a unipolar steppermotor the two coils each have a wire connected to their center. It is controlled by providing power between the center and one of the ends. The center of the coils is always connected to ground. Applying a positive voltage to one or the other end of a coil has the same effect as reversing the voltage on a coil in a bipolar motor. A more detailed description of unipolar steppermotors can be found here.

Wikipedia provides a nice article on steppermotors, which also shows an animation of a steppermotor.

The picture below shows some steppermotors. These are all unipolar. The left and right motors are the same type.

Below are two more pictures of the insides of the steppermotor.



Since it takes some power to control motors, microcontrollers normally can’t control motors directly. Transistors are up for this job, as I explained before. To be able to provide some extra power, darlington transistors are often used with motors instead of single transistors. A darlington transistor is a set of two transistors that function as one, but can provide a much higher current gain than each transistor by themselves. The image below shows the symbol of a darlington transistor. You can read more information about them on Wikipedia.

Steppermotors are controlled by applying voltage to the ends of each coil (the center taps of a unipolar steppermotor are connected to ground), so you’ll need four (darlington) transistors. Such a set of transistors is called an H-bridge. You can make an H-bridge yourself or you can use an H-bridge chip. There are a lot of H-bridge chips available, like the L293D (handles 600mA), the L298 (handles up to 4A) or the ULN2004 (handles 500mA) to name a few.

Of course, you can also pick one of the motor shields available from stores like Adafruit or Sparkfun. I started with the motorshield from Adafruit. It consists of two L293D’s and can control 2 steppermotors (or 4 DC motors). It uses a serial/parallel shift register (74HC595N) to control the L293D’s with the least amount of I/O pins from the microcontroller. This is a nifty trick, although it makes the software a little bit more complex. It also takes more time to control the L293D’s. Each bit of the shift register (8 in total) must be set on a single data-pin and each data-bit is moved into the shift register using a pulse from a clock-pin; finally the result is made available on the parallel outputs of the register using a latch-pin, resulting in a total of 25 I/O-actions. This does not have to be a bad thing, but it does take more time and therefore limits the maximum speed of the motor.

The image below shows the motorshield, stacked on a Netduino, with a stepper motor connected. Since the USB connection can’t provide the power, I'm using an external power adapter.


Adafruit provides an Arduino library for the motorshield. I found a Micro .NET port of this library on the Netduino forums, but it wasn’t working properly. You can download my version here. The microstep step-type (see below) still isn’t working, my motor just wiggles. I don’t think I’ll need microstepping myself, so I’m not really in a hurry to get it working :-). If you do need it, let me know and I’ll be glad to help. I also haven’t tested the DC motor part of the library.

The library provides four types of step-behavior: single, double, interleave and microstep. The single step-type activates a single coil at a time; this is also referred to as ‘wave drive’. The double step-type activates both coils at the same time; also referred to as ‘full step drive’. Double stepping uses twice the power and provides more torque, although not twice the torque. The interleave step-type combines both the single and the double step-type, activating one coil, then two coils, then one coil again and so on; this is also referred to as ‘half stepping’. Since each activation only makes a half step, this step-type requires twice the amount of steps to make the same rotation as the single or double step-type. The microstep step-type uses PWM (explained here) to have a finer control over the power supplied to the coils. Instead of simply switching a coil on or off, microstepping provides a sine waveform to each coil. This provides smoother rotation, but reduces the accuracy of the steps. As I mentioned, it’s currently not working in the library.

The sample program in the solution initializes a stepper motor with 200 steps per revolution (or 1.8 degrees per step) and then repeats a few forward and reverse 360 degree rotations for each (working) step-type. Below is a short example of how to initialize a motor and move it forward.

Stepper stepper = new Stepper(StepperPorts.M3_M4, 200);
stepper.Step(200, MotorDirection.Forward, StepType.Single);

I feel the shift register is limiting the speed of the steppermotor too much. So next, I will try to control the H-bridge directly, without the shift register.

Next: working with steppermotors, without the shield.

Comments (1) -

  • electric motor rewinds

    6/1/2012 3:52:49 AM |

    I would need to study the circuity even further. A lot of new models feature copper wirings.

Pingbacks and trackbacks (3)+

Comments are closed