🛠 Sommeil profond du SAMD21 pour nœud sur batterie
Objectives
Put the SAMD21 to sleep (deep sleep) and wake it up via RTC for a battery-powered node. Note: the 1300 does not have a Li-Po charger (unlike the 1310) — battery power is external. >
Hardware
- 1 Arduino MKR WAN 1300
- External 3.3/5 V power supply (Li-Po + regulator, no onboard charger)
- RTCZero library
- Multimeter in microampere mode for validation
Complete code
#include <RTCZero.h>
RTCZero rtc;
const uint8_t LED = 6;
volatile bool reveille = false;
void onAlarme { reveille = true; }
void setup {
pinMode(LED, OUTPUT);
rtc.begin;
rtc.setAlarmTime(0, 0, 0); // hh:mm:ss
rtc.enableAlarm(rtc.MATCH_SS); // toutes les minutes
rtc.attachInterrupt(onAlarme);
}
void loop {
// 1) Reveil : faire le travail radio (uplink LoRaWAN, cf. tutos precedents)
digitalWrite(LED, HIGH); // placeholder : acquisition + send
digitalWrite(LED, LOW);
// 2) Sommeil profond : STOP + WFI, le RTC reste seul actif
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
__DSB; // evite la course reveil/sommeil
__WFI;
}
Expected verification
The RTC alarm wakes the board every minute (brief LED flash); between alarms, the multimeter in series with the power supply drops significantly below the normal operating level. The LoRa module must also be put back to sleep via AT commands between transmissions.
Common errors
- Forgetting __DSB: the board may miss an alarm arriving just before the WFI.
- The radio module remains active: without a module sleep command, the power savings are minimal.
- Relying on the battery without a charger: the 1300 has no charging circuit, so an external module is required.
- USB connected: the host keeps the board awake; measure on battery power.
Other tutorials for this board
Code examples for this board
emission-p2p.inoArduinoreception-p2p.inoArduinoreglage-sp.inoArduinometeo-lora.inoArduinotrame-crc.inoArduinorelais-radio.inoArduino