🛠 Fonctionnement sur batterie LiPo et sommeil profond
Objectives
Power the Nicla Vision autonomously via a LiPo battery and extend battery life by putting the STM32H747 into deep sleep between events, with wake-up triggered by a button.
Hardware
- Arduino Nicla Vision + LiPo battery on the battery pads/JST connector (“can also be battery powered making it standalone” — official docs)
- >
- Button on D0 (wake-up), green LED as wake-up indicator
- Battery warning: Charge only via the dedicated pads, never apply 5 V directly to VBAT without a charging circuit.
Full code
// Sommeil profond STM32H747 via Mbed, reveil par EXTI sur bouton D0
// >
#include "mbed.h"
const pin_t BUTTON = D0;
volatile bool reveille = false;
void onReveil { reveille = true; }
void setup {
pinMode(LED_BUILTIN, OUTPUT);
attachInterrupt(digitalPinToInterrupt(BUTTON), onReveil, FALLING);
}
void loop {
// 1) tache breve : signal d vie
digitalWrite(LED_BUILTIN, LOW); delay(50);
digitalWrite(LED_BUILTIN, HIGH);
// 2) extinction des peripheriques inutiles pendant le sommeil
// (couper camera, radio si initialises : les debrancher explicitement)
// 3) sommeil profond : M7 et horloges principales a l arret
reveille = false;
while (!reveille) {
sleep_deeplow; // retourne au premier evenement EXTI
delayMicroseconds(200); // anti-rebond grossier
}
delay(300); // laisse le temps au rebond de retomber
}
Expected verification
Between two presses, the LED remains off and the measurable current drops significantly. Each press produces a 50 ms flash. The millis clock continues via the ticker, but the original RTC runs on LSI: the MCUboot is compiled with lse_available=false and re-clocks the RTC from the external LSE to the LSI on every hard reset — the calendar is therefore lost upon reflashing, which must be taken into account for log timestamping.
Common errors
- Forgetting to cut power to the camera/radio: The GC2145 and the ESP32 module remain powered and consume tens of mA; MCU sleep then serves no purpose — turn off rails/peripherals before sleep_deeplow.
- Wake-up loop: A button without a proper pull-up or a bouncing signal causes continuous wake-ups from sleep; add the debounce delay mentioned above.
- Confusing sleep and sleep_deeplow: sleep (STOP) keeps low-power clocks active; only sleep_deeplow (STOP2/STANDBY depending on config) achieves minimal current.
- Losing timestamps: Without saving to the 4 KiB of backup SRAM or without a maintained RTC, the time resets to zero; log relative durations rather than absolute dates if only LSI is available.
Other tutorials for this board
Code examples for this board
led_rgb.inoArduinoimu_lsm6dsox.inoArduinotof_distance.inoArduinomicro_pdm.inoArduinocamera_capture.inoArduinowifi_scan.inoArduino