PyRasp

← All practice problems

Raspberry Pi Pico practice problem · Raspberry Pi Pico

Joystick → two servos

HardBudget $26MicroPython

A joystick is two potentiometers at right angles. Wire X on GP26, Y on GP27, both between 3V3 and GND. Two servos are on GP13 (X) and GP14 (Y), powered from 5 V (VBUS).

Read both ADCs and map 0–65535 to 0–180°, then set each servo's pulse:

pulse_us = 500 + angle / 180 * (2500 - 500)
pwm.duty_ns(int(pulse_us * 1000))

The test joystick is at 75 % on both axes, so both servos should settle near 135°.

More in Raspberry Pi Pico