A Pico as the Pi's ADC
A Raspberry Pi cannot read a voltage: its GPIOs are only high or low, so a potentiometer or a light sensor normally needs an ADC chip. A Pico has a 12-bit ADC on GP26–GP28, so a Pico on the same board can be the Pi's analog input. Here the Pico reads a potentiometer and the Pi dims an LED to match.
This board has two controllers. See Several boards for how programs and consoles work with more than one.
Parts: a Pi, a Pico, a potentiometer, a 330 Ω resistor and an LED.
The circuit
The knob sits across the Pico's 3.3 V supply with its wiper on GP26 (ADC0). The two boards share a UART and a ground, and the LED hangs off the Pi's GPIO18 so the Pi can dim it with PWM.
# circuit.py
from wiring import *
pi = Pi()
pico = Pico(label="pico")
pi.TXD >> pico.GP1 # Pi asks
pico.GP0 >> pi.RXD # Pico answers
pi.GND >> pico.GND
knob = Potentiometer(10000)
pico.V3_3 >> knob.pin3
knob.pin1 >> pico.GND
knob.wiper >> pico.GP26 # ADC0
pi.GPIO18 >> Resistor(330) >> LED("yellow") >> pi.GND
The Pi's program: main.py
The Pi asks for a reading with READ, gets back a number from 0 to 65535, and turns it into an LED brightness between 0 and 1.
# main.py — runs on the Pi, in Python
import serial, time
from gpiozero import PWMLED
port = serial.Serial("/dev/serial0", 9600, timeout=1)
lamp = PWMLED(18)
def read_knob():
"""The Pico's ADC0 reading, 0–65535, or None if it did not answer."""
port.write(b"READ\n")
words = port.readline().decode(errors="ignore").split()
return int(words[1]) if len(words) == 2 and words[0] == "ADC" and words[1].isdigit() else None
while True:
value = read_knob()
if value is not None:
lamp.value = value / 65535
print(f"knob {value:5d} -> {value * 3.3 / 65535:.2f} V, LED {lamp.value:.2f}")
time.sleep(0.5)
The Pico's program: pico/main.py
# pico/main.py — runs on the Pico, in MicroPython
from machine import UART, Pin, ADC
import utime
uart = UART(0, baudrate=9600, tx=Pin(0), rx=Pin(1))
knob = ADC(26)
while True:
line = uart.readline()
if line and line.strip() == b"READ":
uart.write(b"ADC %d\n" % knob.read_u16())
else:
utime.sleep_ms(5)
Press Run, then click the potentiometer and turn it: the pi console tab follows the knob and the LED dims and brightens.
Going deeper
- Why
read_u16()? The RP2040's ADC is 12 bits (0–4095); MicroPython scales every board's ADC to 0–65535 so code works across boards. The Pi side never needs to know which. - The ADC's reference is 3.3 V, so 65535 means 3.3 V. Never put more than 3.3 V on GP26–GP28: a 5 V sensor needs a voltage divider first.
- Compared with an MCP3008: the chip is cheaper and the Pi talks to it over SPI; a Pico costs a little more but brings its own processor, so it can average, filter or watch thresholds and only tell the Pi when something changes.