10. Output devices
Overview of week 10 assignment
- Group assignment
- measure the power consumption of an output device
- Individual assignment
- add an output device to a microcontroller board you’ve designed, and program it to do something
1. Group assignment
For more information, see the Week 10: Group assignment page.
2. Individual assignment
The final project uses a stepper motor, so I used a stepper motor in week 04, but this time I tried using a different type of stepper motor, unipolar stepper motor.
A. Basics of stepper motor
- A stepper motor consists of a stator with coils and a rotor with permanent magnets.
- Unlike brushed DC motors, stepper motors have no brushes to change the direction of the current and reverse the magnetic field.
- An electronic circuit switches the current flowing through the coils to rotate the motor.
- Which also makes it possible to precisely control the angle and direction of rotation.
- This electronic circuit is called a motor driver. There are several types of stepper motors, depending on the method of switching the flow of current.
a. Unipolar vs. Bipolar stepper motor
Feature | Unipolar Stepper Motor | Bipolar Stepper Motor |
---|---|---|
Wiring | 5 or 6 wires (center tap on each coil) | 4 wires (no center tap) |
Driving Complexity | Easier to drive (can use simpler drivers like ULN2003) | Requires H-bridge driver (e.g., A4988, DRV8825) |
Current Flow | Current flows through half of the coil at a time | Current flows through the entire coil |
Torque | Lower torque due to partial coil use | Higher torque as the full coil is utilized |
Efficiency | Less efficient due to center tap limiting power | More efficient since all winding power is used |
Step Control | Simpler control logic | More complex control but more precise movement |
Common Examples | 28BYJ-48 stepper motor | NEMA 17 stepper motor |
B. Unipolar stepper motor: 28BYJ-48
I tried using the 28BYJ-48 unipolar stepper motor and ULN2003 driver (Akizuki Denshi). Below are the specifications from the datasheet:
Specification | 28BYJ-48 Stepper Motor |
---|---|
Operating Voltage | 5V DC |
Operating Current | 240mA (typical) |
Number of Phases | 4 |
Gear Reduction Ratio | 64:1 |
Step Angle | 5.625°/64 (≈0.0879° per step) |
Steps per Revolution | 2048 |
Frequency | 100Hz |
In-traction Torque | >34.3 mN.m (120Hz) |
Self-positioning Torque | >34.3 mN.m |
Friction Torque | 600-1200 gf.cm |
Pull-in Torque | 300 gf.cm |
Specification | ULN2003 Stepper Driver |
---|---|
Operating Voltage | 5V – 12V |
Max Output Current | 500mA per channel |
Number of Channels | 4 |
Control Inputs | IN1, IN2, IN3, IN4 |
a. Wiring
I wired the 28BYJ-48 and ULN2003 to my development board following Control 28BYJ-48 Stepper Motor with ULN2003 Driver & Arduino.
The example uses Arduino board, so I rewired it to RP2040 development board as follows:
ULN2003 Driver | RP2040 |
---|---|
IN1 | 26 |
IN2 | 27 |
IN3 | 28 |
IN4 | 29 |
The GND and VCC of the ULN2003 were connected to the Power Supply DP100 and set to constant voltage output mode (CV) and 5.0V. Initially, I forgot to wire the GND on RP2040 board, so I used a breadboard to add a GND wire connected to the GND of the power supply (I forgot to take a picture).
b. Programming
This sample code is based on the above site and will rotate 360 degrees slowly clockwise, then rotate 360 degrees counterclockwise quickly, then repeat.
First, I installed the library "Stepper" by Arduino:
Tools > Manage Libraries > Library Manager > Search "Stepper" and install it
There are 2 interesting lines:
- Defining steps per revolution:
const int stepsPerRevolution = 2048;
Total number of steps needed for the motor to complete 360° rotation. In this case, it's 2048. - Creating a stepper motor instance:
Stepper myStepper = Stepper(stepsPerRevolution, 26, 28, 27, 29);
stepsPerRevolution
is difined as above.- The four numbers
26, 28, 27, 29
specify which pins control the four stepper motor coil wires. This library is for stepper motors in general and not specifically for unipolar stepper motors, so the pin order is not in numerical order.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
Check components carefully!
I struggled twice because of the components I tried.
- I first picked a 28BYJ-48, although I felt a slight vibration, the motor did not rotate. This is because the rated voltage was 12V instead of 5V. They look identical, but it is noted on the back of the motor.
- The second motor I chose worked, but it didn't change direction as expected, it rotated once clockwise, once counterclockwise, and then continued to rotate counterclockwise. This is because the motor had been modified (the cover had been opened and the 5V trace had been disconnected, probably to use it as a bipolar stepper motor).
Again, I forgot to take video but it worked...
C. Bipolar stepper motor: Nema17 (17HS4023)
This is a schematic diagram of a bipolar stepper motor using an H-bridge. You can see that the H-bridge drives the motor by changing the direction of the current passing through the two coils. I could find out more details on the following sites.
In week 04, I tried using a Nema17 with an RP2040 and a 5V power supply without using the Stepper library. This time I was planning to use the Stepper library and microstepping...
a. Wiring
Wiring is almost the same as the week 04, but I connected MS1, 2, 3 to RP2040 to try micro stepping. Please visit week 04 for components I used.
Pin/Function | Description | RP2040 / Nema17 |
---|---|---|
ENABLE | LOW = enabled, HIGH = disabled | - |
MS1, MS2, MS3 | Set step mode | P28, P29, P6 |
RESET | LOW = resets input to translator, ignores signals until HIGH | connected to SLEEP |
SLEEP | LOW = sleep mode (minimizes power consumption) | connected to RESET |
STEP | Controls motor rotation by inputting pulse signals | P27 |
DIR | Sets rotation direction | P26 |
VMOT | Motor power supply (8-35V, up to 35V) | 9V power supply |
A1, A2, B1, B2 | Stepper motor connections | Nema17 (XH2.54 4-pin connector) |
VDD | Logic power supply (3-5.5V, supports 3.3V & 5V) | 5V |
GND | Ground | GND |
Since the motor was sourced by disassembling an old 3D printer and had no color coding applied. I found out that this connector is called XH2.54 4-pin connector, meaning XH series, 2.54mm pitch, 4-pin.
b. Programming
First I tried using the same program as before to do a quick test to see if it would work, and it didn't.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
D. Troubleshooting
I suspect many possible problems and also searched for solutions on the web.
- Wiring mistakes
- Incorrect wiring of the Nema 17 connector to A4988
- Programming errors of pin numbers
- A4988 output current limit
- Jump wire disconnection
- A4988 ENABLE pin
- Insufficient power supply voltage (5V, not 9 ~ 24V)
- Component failure (A4988, Nema 17)
References:
- How to control a stepper motor with Arduino and A4988 (Japanese)
- Control Stepper Motor with A4988 Driver Module & Arduino.
1. Wiring mistakes
The four-pin connector (XH2.54-4 pins) on the stepper motor was not color-coded, so I couldn't figure out which wires should connect to the four pins (A1, A2, B1, B2) on the A4988. There are some ways to determine using LED, following this YouTube: How to wire Nema stepper motor correctly (YouTube):
- Choose 2 wires and connect them to a LED
- Turn the motor by hand
- If the two wires are connected to a same coil, the LED will light up (the 2 wires are A1, A2 or B1, B2)
2. A4988 output current limit
The A4988 limits the maximum current through the stepper coils so that it does not exceed the rated current of the motor. The A4988 driver includes a potentiometer to set the current limit.
Before, I omitted this step but I tried setting it.
- Measure VREF:
- Connect the multimeter’s black lead to GND
- Connect the red lead to the potentiometer top
- Initially, VREF was set to 0.6V.
- Formula: I_limit = V_REF / 8 * R_SENSE
- R_SENSE (Current sense resistor) = 0.068Ω for A4988
- Browse the datasheet of this Nema17 and check rated current...
- Adjust the potentiometer until the voltage on the multimeter reaches your target
- Clockwise to increase the current and counterclockwise to decrease it (as a test, I set it as 0.8V)
3. Jump wire disconnection
I checked continuity of the all wires using the multimeter continuity mode. Beep.
4. A4988 ENABLE pin
Although examples I referenced omit this pin, ENABLE pin should be LOW (0V) to activate the driver. It can be tested by measuring voltage between ENABLE and GND.
- If HIGH (3.3V or 5V) > A4988 is disabled. Pull it LOW.
3. Files
No files this week, code in the text.
Afterthoughts
- Don't panic!