🛠 Bouton et potentiomètre sans marcher sur le sans-fil (GPIO libres & ADC)

Raspberry Pi Pico W · debutant · Schéma : IMG-pico-w-debutant-3-picow-gpio-libres.svg — Pico W sur breadboard, bouton poussoir sur GP2 vers GND et potentiomètre sur GP26 (ADC0), broches GP23 à GP25 et GP29 barrées en rouge avec étiquette reserve radio, console serie affichant les valeurs 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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials