🛠 Sommeil basse consommation et réveil sur interruption
Objectives
Extend the autonomy of a node running on a 3.7 V LiPo battery (3-pin J4 connector, minimum recommended capacity 200 mAh, BQ25120 charger controlled by nicla::enableCharging(mA)). The only board-level consumption points documented are: 460 µA typical in standby, 960 µA for the blink sketch, 2.5 mA during BLE advertising + sensor polling at 1 Hz, and 1.15 mA during advertising + one poll per hour. The strategy here is to put the Cortex-M4F core to sleep using __WFI between measurements and wake it up via an external interrupt. Note that this topic is under-documented by Arduino: to date, no dedicated deep-sleep API has been published for this board.
Hardware
- Arduino Nicla Sense ME board (ABX00050) + single-cell LiPo battery on the J4 connector
- Button or detector connected to a digital pin for wake-up (pin-to-ground, internal pull-up)
- Adjustable power supply or battery + microammeter in series to measure actual current
- > tious with sub-mA promises.
Full Code
#include "Nicla_System.h"
#include "Arduino_BHY2.h"
volatile bool reveille = false;
const uint8_t BROCHE_REVEIL = 3;
void onReveil { reveille = true; }
void setup {
Serial.begin(115200);
nicla::begin;
nicla::enableCharging(20); // courant de charge doux (defaut materiel : 40 mA)
BHY2.begin;
BHY2.setLDOTimeout(600000); // evite la coupure LDO apres 1 min sans activite
pinMode(BROCHE_REVEIL, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(BROCHE_REVEIL), onReveil, FALLING);
}
void loop {
BHY2.update;
delay(1000);
Serial.print("Tension batterie : ");
Serial.println(nicla::getCurrentBatteryVoltage);
Serial.flush;
reveille = false;
__WFI; // le CPU s'arrete, attend une interruption
while (!reveille); // sortie de veille
Serial.println("Reveil par interruption");
}
Expected Verification
The sketch prints the battery voltage and then freezes; pressing the button connected to pin 3 triggers the display of "Wake up by interrupt" and resumes the cycle. By inserting a microammeter in series with the power supply, you should observe a drop in current during the waiting phase compared to the active cycle; compare this with the datasheet table (460 µA in standby) to contextualize your measurement.
Common Errors
- Relying on a giant
delayas sleep: the CPU continues to run at 64 MHz, and the current hardly drops;__WFIis essential to stop the core clock. - Leaving peripherals awake: BLE, LEDs, and sensors at their maximum throughput consume more than the sleeping CPU; turn off the LEDs (
nicla::leds.setColor(off)) and limit sensor throughput before sleeping. - LDO cutoff after one minute of ESLOV inactivity: a design behavior that "turns off" peripherals during a long sleep; adjust
BHY2.setLDOTimeoutaccordingly. - Ghost interrupt on a floating pin: always enable a pull-up and wire the button to ground, otherwise the wake-up triggers continuously.
- >
Other tutorials for this board
Code examples for this board
led_rgb.inoArduinoimu_bhi260.inoArduinorotation_fusion.inoArduinopression_bmp390.inoArduinonose_electronique.inoArduinoboussole_bmm150.inoArduino