🛠 Sommeil profond et réveil programmé ou sur broche

Raspberry Pi Pico 2 W · avance · Schéma : IMG-pico-2-w-avance-8-pico2w-sommeil-reveil.svg — Pico 2 W sur batterie avec convertisseur RT6154, chronomètre d'alarme, réveil par GPIO et courant de veille en µA.

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials