🛠 Sommeil bas courant et réveil sur interruption
Objectives
Approach the documented floor of 104 µA for the MKR WAN 1310 (board-level, official store) by sleeping between two events: the core compiles this board with -DVERY_LOW_POWER, the Murata module drops to 1.40–1.65 µA in Stop/Standby (STM32L0 + SX1276 Sleep), and the SAMD21 offers deep modes with wake-up via external interrupt on pins 0, 1, 4, 5, 6, 7, 8, 16/A1, or 17/A2.
Hardware
- 1 MKR WAN 1310 board + Li-Ion/Li-Po battery (1024 mAh minimum, 2-pin JST PH connector) — the BQ24195L charger handles charging
- 1 button on pin 16/A1 to GND (EINT-compatible pin)
- A nano-ammeter or a switching regulator to measure the actual current
Complete code
// Sommeil profond + reveil bouton — MKR WAN 1310 (SAMD21)
// >
// l'approche EINT + attachInterrupt est documentee, pas le courant mesure.
volatile bool reveille = false;
const int REVEIL = 16; // A1 : broche a interruption externe (EINT)
const int LED = 6;
void onReveil { reveille = true; }
void setup {
pinMode(REVEIL, INPUT_PULLUP);
pinMode(LED, OUTPUT);
Serial.begin(115200);
attachInterrupt(digitalPinToInterrupt(REVEIL), onReveil, FALLING);
}
void loop {
if (reveilles) {
reveille = false;
digitalWrite(LED, HIGH);
Serial.println("Reveille !"); // ici : mesure + uplink LoRaWAN
digitalWrite(LED, LOW);
}
dormir; // entre deux evenements
}
bool reveilles { return reveille; }
void dormir {
noInterrupts;
// Mettre le module LoRa en faible conso (AT+MODE/PSM selon firmware),
// couper la LED, puis entrer en sommeil SAMD21 (mode Standby du core
// ArduinoCore-samd compile avec VERY_LOW_POWER ; voir exemples Sleep.h).
interrupts;
// >
// le bouton reveille bien le sketch avant de compter sur l'autonomie.
__WFI; // attend l'interruption : approx. la porte du sommeil
}
Expected verification
Between two presses, the measured current drops significantly (documented target: 104 µA for the entire board, 1.4–1.65 µA for the module alone); a press on A1 wakes up the sketch, which prints and can transmit. The ON LED remains off on battery, which is normal: it follows the 5 V rail.
Common errors
- Relying on
delayto save power: the SAMD21 remains active; you need a real sleep mode (WFI/Standby) and to disable peripherals. - Choosing a pin without EINT for wake-up: only pins 0, 1, 4, 5, 6, 7, 8, 16/A1, and 17/A2 wake up via external interrupt.
- Forgetting that the LoRa module also consumes power: place it in low-power mode (the AT firmware manages 1.4–1.65 µA modes) before sleeping.
- Aiming for 104 µA with USB connected: the SAMD21 in USB mode and the ON LED mask the gains; measure on battery only.
- Sleep API not finalized: >
- Battery below 1024 mAh or poorly crimped JST PH connector: the BQ24195L limits charging and autonomy collapses.
Other tutorials for this board
Code examples for this board
join-otaa.inoArduinouplink-confirme.inoArduinodownlink.inoArduinoactivation-abp.inoArduinosuivi-adr.inoArduinoclasse-c.inoArduino