🛠 Fonctionner sur batterie LiPo et économiser l'énergie
Objectives
Power the MKR WiFi 1010 with a single-cell 3.7 V LiPo (JST connector, ≥1024 mAh recommended) using the onboard charger — the PMIC is the TI BQ24195L (enable with the flag -DUSE_BQ24195L_PMIC) — and build an energy-efficient cycle: measure, transmit a WiFi burst, and sleep (__WFI) until an external interrupt. Critical reminders: the ON LED stays off when running on battery (5 V rail) and VIN accepts only regulated 5–6 V, not the raw 6–12 V used by Arduino AVR boards.
Hardware
- 1 × Arduino MKR WiFi 1010
- 1 × single-cell 3.7 V LiPo battery (JST PH 2-pin, respect +/− polarity)
- Button on an external interrupt pin (e.g., A1, pin 16) for wake-up
- Multimeter for the energy budget
- >
Complete code
#include <WiFiNINA.h>
const uint8_t PIN_WAKE = A1; // pin 16, interruption externe possible
void setup {
Serial.begin(115200);
pinMode(PIN_WAKE, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(PIN_WAKE), reveil, FALLING);
}
void reveil { /* reveille le SAMD21 via __WFI */ }
void loop {
// 1) Rafale : lecture capteur + envoi rapide
Serial.println("mesure...");
// ... lecture ADC, connexion WiFi, envoi, WiFi.end ...
WiFi.disconnect;
WiFi.end; // coupe la radio NINA, gros gain
// 2) Sommeil : le CPU attend l'interruption (broche 0,1,4,5,6,7,8,9,
// 16/A1, 17/A2 supportent les interruptions externes).
noInterrupts;
if (digitalRead(PIN_WAKE) == HIGH) { // pas d'appui deja en cours
__WFI;
}
interrupts;
delay(100);
}
Expected verification
On battery, the board works even though the ON LED is off (normal behavior, official FAQ). The button wakes the board: the monitor (if USB is connected for testing) displays a new measurement. When unplugging USB, the measurable current drops after WiFi.end — the radio is the primary power consumer.
Common errors
- Panicking when seeing the ON LED off on battery: it is wired to the 5 V rail, not the battery — this is intended.
- Injecting 9 V or unregulated voltage into VIN: input is regulated 5–6 V only; exceeding this damages the regulator.
- Forgetting
WiFi.endbefore sleeping: the NINA module consumes heavily as long as the radio remains active. - Wake-up not working: not all pins support external interrupts (list: 0, 1, 4, 5, 6, 7, 8, 9, 16/A1, 17/A2) and you must re-arm
attachInterruptafter certain wake-up paths. - >
- Battery stored discharged below the PMIC recharge threshold: the board will not power on; recharge it on a bench charger.
Other tutorials for this board
Code examples for this board
scan-wifi.inoArduinoconnexion-wpa2.inoArduinohttp-get.inoArduinoserveur-web-led.inoArduinohorloge-ntp.inoArduinoudp-diffusion.inoArduino