🛠 Sommeil basse consommation et réveil sur interruption

Arduino Nicla Sense ME · avance · Schéma : IMG-nicla-sense-me-avance-1-niclasense-sommeil-bas-courant.svg — Nicla Sense ME sur batterie LiPo avec microampèremètre en série sur l'alimentation, croissant de lune au-dessus de la carte et flèche de réveil vers la broche d'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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials