🛠 Bouton et potentiomètre sans marcher sur le sans-fil (GPIO libres & ADC)
Objectives
The Pico W inherits the entire microcontroller part of the RP2040: 2× UART, 2× SPI, 2× I²C, 16 PWM channels, 12-bit 500 ksps SAR ADC, 8 PIO state machines… But the wireless module has consumed part of the pinout: only GP0–GP22 and GP26–GP28 are freely usable (26 pads, including 3 analog inputs). This tutorial teaches you how to wire a button and a potentiometer without ever touching the reserved pins, and how to read the ADC correctly on a board that has its pitfalls.
Hardware
- 1 × Raspberry Pi Pico W + micro-USB data cable
- 1 × push button (GP2 → GND, internal pull-up)
- 1 × 10 kΩ potentiometer: ends connected to 3V3 and GND, wiper connected to GP26 (ADC0)
- USB serial console at 115200 bauds
- Voltage reminder: fixed 3.3 V, no 5 V tolerance
Complete code
# gpio_adc.py — bouton GP2 + potentiomètre GP26/ADC0 (MicroPython Pico W)
from machine import Pin, ADC
import time
btn = Pin(2, Pin.IN, Pin.PULL_UP) # bouton GP2 -> GND, actif à 0
pot = ADC(26) # GP26 = ADC0 (GP26..GP28 seules
# entrées ADC sorties sur la Pico W)
while True:
raw = pot.read_u16 # 16 bits MicroPython (0..65535)
mv = raw * 3300 // 65535
etat = 'APPUIE' if not btn.value else 'repos'
print(f'adc={raw:5d} ~{mv} mV bouton={etat}')
time.sleep_ms(200)
# > NE PAS UTILISER : GP23 (power-on radio), GP24 (SPI data/IRQ),
# GP25 (SPI CS), GP29 (SPI CLK radio, partagé ADC3=VSYS/3).
Expected verification
When turning the potentiometer, the value follows 0 → 65535 and the calculated mV follow 0 → 3.3 V; pressing the button toggles the displayed state. Two ADC pitfalls documented in the Pico W datasheet: (1) ADC_VREF is filtered from the 3V3 rail via a 200 Ω resistor, which creates an inherent offset of approximately 30 mV; (2) reading VSYS/3 (ADC3) is corrupted during Wi-Fi SPI transactions — and GP29 is precisely the SPI clock of the CYW43439, so do not rely on it with the radio active.
Common errors
- Reattaching a shield or metal case to the board edge: the antenna keep-out zone (14 × 9 mm) must remain clear, otherwise Wi-Fi performance degrades even if the GPIO works.
- Using GP25 "as on the Pico": here it is the radio SPI chip-select — your code "works" superficially but breaks Wi-Fi.
- Measuring more than 3.3 V on a pin: the ADC does not tolerate more than its supply voltage; moreover, GP26–GP29 have an internal reverse diode to the 3.3 V rail: injecting current into the board when powered off erroneously powers the rail (back-powering).
- Forgetting the ADC offset of approximately 30 mV: for fine measurements, subtract the reading of a grounded channel, or power ADC_VREF with a clean external reference.
- Confusing physical pin and GPx number: always code GPx, not the connector position.
Other tutorials for this board
- Faire clignoter la LED embarquée (elle est derrière la puce Wi-Fi !)
- Se connecter à un réseau Wi-Fi (station, WPA2/WPA3)
- Servir une page web depuis la Pico W (socket TCP + HTTP)
- Client HTTP : consommer une API depuis la Pico W
- Heure exacte via NTP : l'horloge temps réel des projets connectés
- Client MQTT : télémétrie IoT légère sur la Pico W
Code examples for this board
clignotante.pyPythonbouton-interruption.pyPythonpwm-servo.pyPythonlecture-adc.pyPythonneopixel.pyPythonoled-i2c.pyPython