Output devices¶
Group Assignment¶
We spent this week diving into power measurement of output devices—specifically DC motors and LED strips—with a hands-on group assignment.
Using our Instek GPD‑3303D power supply and a precise multimeter setup, we took multiple measurements across different components. Testing the LED strip, we saw it start glowing around 6 V (drawing ~0.07 A, so ~0.42 W) and reach about 1.22 A (~14.6 W) at 12 V. It was satisfying to see real data backing up the theory.
With the DC motor, we tested it under a free-spin (0.06 A → 0.72 W), under load (0.59 A → 7.08 W), and stalled (1.46 A → 17.5 W) . Those differences really highlighted how power consumption spikes with mechanical resistance.
We also explored startup behavior and used PWM via a MOSFET to smooth out motor activation. By implementing a “software starter” (high initial pulse, then lower PWM), we could get reliable motor spins even at low sustained power
You can check all work that we did here
Individual Assignment¶
For my final project I decided to use stepper motors, to rotate guitar tuning pegs.
I found small stepper motor in DVD drive, it moves laser module that reads disc information.
As you can see, it has 4 pins, which means that it is 2 phase stepper motor.
2 of 4 pins are one coil called A, and ther others are for coil B. So pins are called A+,A-,B+,B-
The logic of the stepper motor movement is shown on this picture
But, the voltage value for “1” state is over 9V for this motor, So I can’t give it direct from microcontroller.
Microcontroller pins has Voltage and Current limits. Typically it is 3,3V or 5V for voltage and 10-20mA for current. So the output pins are mostly used for logic pins, or connected to very low power devices, such as LEDs.
To control stepper motor I must use Motor Driver.
I choosed DRV8825 stepper motor driver
Wiring¶
So, started by soldering breadboard friendly wires to stepper motor.
Then I checked my motor driver datasheet
to connect stepper motor with driver there is no need in giving 4 different phase signals to each motor pin from microcontroller. The driver is controling by only 2 pins. STEP and DIR (Direction). The state of DIR pin sets direction of movement, and every pulse on STEP pin moves motor by one step. The angle of one step is typically 1.8°, there are 3 control types - full step, half step and micro step. To set the mode that you need, there is 3 pins on stepper motor driver called M0,M1,M2.
Step Mode | MODE0 | MODE1 | MODE2 |
---|---|---|---|
Full Step | Low | Low | Low |
Half Step | High | Low | Low |
1/4 Step | Low | High | Low |
1/8 Step | High | High | Low |
1/16 Step | High | Low | High |
1/32 Step | High | High | High |
NOTE! The more precision you want, the less torque you get.
So I am using full step control to have maximum torque to hold strings on guitar.
I connected everything to bread board
Programming¶
I started to write program in CubeIDE.
Firstly I defined 2 GPIO pins as Step pin and Dir pin.
And then wrote 3 basic functions, that are moving motor by ine step, and seting direction Clockwise or Counter Clockwise
in my main loop i have only two commands CW(); or CCW(); to set direction, and then moving by one step. (The speed of rotation depends on HAL_Delay() duration in Stepper_Step function)
Experiment and troubleshooting¶
After that I powered driver from power power source with 10V and ..... nothing happens. It was not moving.
I took osciloscope and checked driver pins.
It is signal on STEP_Pin. everything is good.
and then I found that I accidently connected Enable pin of driver to 3.3V pin of STM32, instead of GND. (Most of drivers work when enable is in state (0))
After everything is done, I runned program and…
Everything works well and I tried to change delay value on program and move it with different speed
OLED on Raspberry PI Pico 2W¶
I writed program to display Guitar string name frequency range on an OLED screen on my board. This allowed for real-time visualization directly on the hardware.
Below is the code I used:
import time
from machine import Pin, SPI
from ssd1306 import SSD1306_SPI
These lines import necessary modules for time delays, controlling pins and SPI communication, and using the OLED display.
spi = SPI(0, 100000, mosi=Pin(19), sck=Pin(18))
oled = SSD1306_SPI(128, 64, spi, Pin(17), Pin(20), Pin(16))
oled.poweron()
This initializes the SPI interface and connects it to a 128x64 OLED display, then powers it on.
min_x = 10
max_x = 118
slider_y = 29
slider_height = 20
slider_x = min_x
direction = 1
These variables define the boundaries and initial position of the vertical slider line.
def main():
global slider_x, direction
Defines the main function and allows the function to modify the slider position and direction.
while True:
Starts an infinite loop to continuously update the display.
oled.fill(0)
Clears the OLED screen before drawing new content. Which you can see in final video.
oled.text("|---|--|--|---|", 3, 35, 1)
oled.text("-10", 0, 55, 1)
oled.text("-5", 27, 55, 1)
oled.text("0", 59, 55, 1)
oled.text("5", 83, 55, 1)
oled.text("10", 110, 55, 1)
Draws a fixed reference scale and labels on the bottom of the display.
oled.text('A', 57, 15, 1)
Displays the letter “A” above the scale (placeholder or label). The OLED library I used (ssd1306) supports only one built-in font, which means the font size cannot be changed. This limits the ability to customize text appearance or highlight certain values with larger characters.
oled.vline(slider_x, slider_y, slider_height, 1)
Draws a vertical line (slider) at the current slider_x position.
oled.show()
Renders the current frame buffer contents to the OLED display.
slider_x += direction
Moves the slider one pixel to the right or left depending on the direction.
if slider_x >= max_x or slider_x <= min_x:
direction *= -1
Reverses the direction of movement if the slider reaches either end.
time.sleep(0.02)
Waits for 20 milliseconds to slow down the slider movement.
main()
Calls the main() function to start the animation loop.
Running Issue¶
While running the OLED display program, I encountered an error in Thonny indicating that the ssd1306 library was not defined. This happened because the library was not included by default in the MicroPython environment.
To fix this,I installed the ssd1306.py library manually
To do this I downloaded .py file
Opened it in Thonny IDE
After opening the ssd1306.py file in Thonny, I saved it directly to the Raspberry Pi Pico 2 W. This resolved the missing library error, and the OLED display began working as expected.
Result¶
Here is the final setup running successfully. The OLED displays the frequency range as intended
I also added an additional custom font to make the letter “A” larger for better emphasis.
Conclusion¶
Working with stepper motors is very interesting. They are used in many devises to get presisious movement and high torque. Their control is really not hard)) Using OLED is not that hard too. You can display anything you want, there are many libraries that can help you with that ;) Also I used two different IDEs and languages (CubeIDE with C, ThonnyIDE with micropython)
Program File¶
OLED with raspberry pi pico 2w file