Video summary

Micropython - controlling a servo

Main summary

Key takeaways

Technology

Micropython servo control tutorial

What the video covers

  • Introduction to hobby servos: small motors with a limited range (typically about 180°) used for short-range motion. A hobby servo contains a motor, a small microcontroller and a potentiometer for closed‑loop position feedback.
  • Control method: servos are driven with a PWM (pulse‑width modulation) control pulse. The MicroPython servo module converts desired angles into the appropriate PWM/duty values (the library handles the angle→PWM mapping).

Hardware / wiring

  • Power
    • Connect the servo red wire to VBUS (5 V) on the Raspberry Pi Pico — do NOT use 3.3 V for reliable operation.
  • Ground
    • Connect the brown (or black) wire to GND.
  • Signal
    • Connect the control wire (usually white/orange/yellow) to a GPIO pin (the demo uses pin 16).
  • Note: powering the servo from 5 V is recommended for better torque and motion.

Warning: be careful with VBUS connections to avoid damaging other parts. When using multiple servos, test wiring incrementally and consider a dedicated power supply or proper decoupling to avoid brownouts and noise on the Pico.

Software / workflow (MicroPython on a Raspberry Pi Pico)

  1. Copy the provided MicroPython servo module (from the raw link shown in the video) onto the Pico and save it as servo.py (lowercase).
  2. Create a test script, e.g. servo_test.py, and import the module:
    • from servo import Servo
  3. Instantiate a servo object:
    • s = Servo(pin=16)
    • Optional constructor parameters: frequency, min_us, max_us, and degrees to match specific servo ranges.
  4. Basic commands
    • Move to endpoints: s.write(0) and s.write(180) (include time.sleep() between commands to allow motion).
    • Sweep example:
import time
from servo import Servo

s = Servo(pin=16)

# sweep from 0 to 179
for i in range(180):
    s.write(i)
    time.sleep(0.02)   # adjust delay as needed

# sweep back
for i in reversed(range(180)):
    s.write(i)
    time.sleep(0.02)
  • Timing notes: too-short delays may prevent the servo from reaching target positions. Adjust sleep values (e.g., 0.01 s to 0.1 s per step) and include longer pauses as needed.

Implementation notes / tips

  • The servo module handles the angle → PWM duty calculation, so you do not need to compute PWM duty cycles manually.
  • Tweak frequency, min_us, max_us, and degrees in the Servo constructor to match different servo models and achieve accurate endpoint positions.
  • Test wiring and delays incrementally.
  • For multiple servos, pay attention to power supply capability and decoupling to prevent voltage drops or noise that can affect the Pico and servos.

Resources / files used

  • Servo MicroPython module (copied from a raw link into the Pico as servo.py).
  • servo_test.py example created on the Pico to demonstrate write and sweep operations.

Main speaker / source

  • The video presenter/tutorial author demonstrating the procedure on a Raspberry Pi Pico running MicroPython.

Original video