🛠 Lire l'ADC 12 bits et le capteur de température interne du RP2350
Objectives
The RP2350 features a 12-bit SAR ADC, 500 kSPS, with 4 channels on the RP2350A / 8 on the RP2350B, plus an internal temperature channel — but no DAC (RP2350 datasheet). Official SDK examples map ADC channels 0..3 to GP26..GP28. This tutorial covers reading an external voltage with a potentiometer, reading the core temperature, and properly handling the RP2350 ADC's 12-bit scale (0..4095).
Hardware
- 1 × generic RP2350 board + MicroPython rp2 (RP2350 firmware)
- 1 × 10 kΩ potentiometer: pin 1 → 3V3, pin 3 → GND, wiper → GP26
- 3 × wires; no resistor needed (the ADC accepts the source directly)
- For temperature: just place your finger on the chip 😉
Full Code
# adc_temp.py — ADC0 (GP26) + canal température interne
from machine import ADC, Pin
import time
# Canal 4 = capteur thermique interne (comme sur RP2040)
sense = ADC(4)
# ADC0 : sur le port rp2, ADC(0) cible l'entrée analogique ADC0 = GP26
pot = ADC(0)
REF = 3.3 # pleine échelle = alimentation IO, ici 3,3 V
FULL = 4095 # l'ADC du RP2350 est nativement 12 bits
def tension(adc):
return adc.read * REF / FULL # read = valeur brute 12 bits
def temperature:
v = tension(sense)
# formule datasheet famille RP2 : 0,706 V à 27 °C, pente -1,721 mV/°C
return 27.0 - (v - 0.706) / 0.001721
while True:
print('pot: %4d %.3f V coeur: %.1f C'
% (pot.read, tension(pot), temperature))
time.sleep_ms(500)
Expected Verification
Turn the potentiometer: the raw value follows 0 → 4095 and the voltage 0 → 3.3 V linearly. Place your finger on the RP2350: the core temperature rises by a few degrees in a few seconds, then drops back down. The formula 27.0 - (v - 0.706) / 0.001721 is the one for the RP2 family (sensor voltage 0.706 V at 27 °C, slope 1.721 mV/°C) — it gives the core temperature (internal diode), not the ambient temperature: 30–35 °C when held in hand is normal.
Common Errors
- Confusing
read(raw, 0..4095 on this 12-bit chip) andread_u16(rescaled to 16 bits by MicroPython): choose ONE scale and divide by the correct full scale — a factor of 16 error isn't always obvious. - Measuring the temperature channel as a normal input: the internal channel is not linear with input voltage, use the dedicated formula.
- Using ADC0 on a pin other than GP26: ADC channels are fixed to the analog pins (GP26..GP28 according to SDK examples), unlike UART/SPI/I2C which can be routed anywhere.
- IO supply at 1.8 V: the ADC full scale follows the IO supply — if your setup uses 1.8 V IOVDD, adjust
REF. - Source impedance too high (> 10 kΩ): the internal sampler discharges, values become noisy — the 10 kΩ potentiometer is a reasonable upper limit.
- Expecting an analog output: the RP2350 has no DAC; for a variable voltage, use PWM + an RC filter (the RP2350's 8/12 PWM slices will do the job).
- Targeting channels 4..7 on an RP2350A board: the 8 channels only exist on the 48-GPIO silicon (RP2350B) — check the chip variant, not just the module format.
- Leaving inputs floating: on A2 chips, a floating input can drift towards 2.2 V due to Bank 0 leakage (errata E9) — connect or configure your unused pins.
Other tutorials for this board
- Flasher MicroPython sur une carte RP2350 générique et faire clignoter la première LED
- Console série sur RP2350 : USB CDC natif et UART0 de secours
- Exploiter les 3 blocs PIO et 12 machines d'état du RP2350 (avec IRQ dédiées)
- Pico SDK 2.x sur une carte RP2350 générique : CMake, board header et PICO_BOARD
- Basculer les cœurs de Arm Cortex-M33 à Hazard3 RISC-V avec ARCHSEL
- Secure boot et TrustZone-M sur RP2350 : signer son firmware sans se faire avoir
Code examples for this board
clignotante.pyPythonbouton-interruption.pyPythonpwm-servo.pyPythonlecture-adc.pyPythonneopixel.pyPythonoled-i2c.pyPython