🛠 Sommeil profond et réveil programmé ou sur broche
Objectives
Powering the Pico 2 W on battery requires sleeping: putting the RP2350 to sleep between readings, waking it at fixed times using hardware alarms (1 timer + 4 alarms) or on a GPIO edge, and measuring the gain. Note: the CYW43 must turn off its radio part, and the specific currents for the Pico 2 W (including radio) are not published in the datasheet.
Hardware
- Pico 2 W powered via VSYS (LiPo battery via the documented charger pattern)
- Button on GP15 for wake-up on edge
- pico-sdk (header pico/sleep.h)
Complete code
// main.c - cycle : reveil -> releve -> dormant -> alarme 30 s plus tard
#include "pico/stdlib.h"
#include "pico/sleep.h"
#define BOUTON_REVEIL 15
int main(void) {
stdio_init_all;
sleep_init_runsleep_and_sleep_mode(
SLEEP_MODE_DORMANT,
WAKE_ON_GPIO | WAKE_ON_ALARM_0 | WAKE_ON_RP2350_DORMANT_WAKEUP_SOURCE_GPIO);
gpio_init(BOUTON_REVEIL);
gpio_set_dir(BOUTON_REVEIL, GPIO_IN);
gpio_pull_up(BOUTON_REVEIL);
while (true) {
printf("Releve : je travaille\n"); // tache utile ici
sleep_run_when_both_cores; // les deux coeurs doivent dormir
sleep_goto_dormant_until_timer_alarm_absolute(
make_timeout_time_ms(30000)); // ou : bouton sur GP15
printf("Reveille !\n");
}
}
Expected verification
The board prints a Reading every 30 seconds in alarm mode, and immediately when pressing GP15 in GPIO wake-up mode. An ammeter in series with the battery shows a clear drop in current during sleep (Pico 2 P1.x order of magnitude: 148-233 microamperes, radio off).
Common errors
- Forgetting to put BOTH cores to sleep (sleep_run_when_both_cores on RP2350): the board never truly sleeps.
- Leaving the CYW43 powered and connected to Wi-Fi: the radio consumes power in beaconing mode; turn off cyw43_arch before sleeping.
- Reading VSYS (GP29) upon wake-up while the radio is resuming: the line is shared with the CYW43 SPI; give priority using cyw43_thread_enter/exit.
- Waiting for printf while sleeping: the serial console is cut off; prepare a flag to be printed upon wake-up.
Other tutorials for this board
Code examples for this board
clignotante.pyPythonbouton-interruption.pyPythonpwm-servo.pyPythonlecture-adc.pyPythonneopixel.pyPythonoled-i2c.pyPython