🛠 Gestion de batterie LiPo : jauge, charge et seuils bas
Objectives
The Boron includes everything needed for a single-cell LiPo: charger, battery connector, and status LED (on = charging, off = complete, 1 Hz blink = fault, fast blink = battery disconnected), plus a TI fuel gauge on I2C accessible via the FuelGauge API (getVCell, getSoC). This advanced tutorial sets up robust battery telemetry: periodic reading, cloud alert below threshold, and strategies to survive deep discharge — a flat LiPo has already "bricked" community card clouds (return to 10 SOS, DFU re-claim required).
Hardware
- 1× Particle Boron + 3.7 V LiPo (check the polarity of the JST connector: "not all LiPos follow the same convention," official datasheet warning)
- micro-USB cable for the charging phase
- Particle CLI + connected device
Complete code
// Boron — telemetrie batterie avec alerte de seuil
#include "Particle.h"
SYSTEM_THREAD(ENABLED);
FuelGauge fuel;
const float SEUIL_CRITIQUE = 20.0; // % de charge
const float SEUIL_BAS = 35.0;
uint32_t cycle = 0;
bool alerteEnvoyee = false;
void setup {
Serial.begin(9600);
Particle.variable("soc", cycle); // derniere valeur lue
}
void loop {
if (waitFor( => Cellular.ready, 30000)) {
float v = fuel.getVCell;
float soc = fuel.getSoC;
char msg[96];
snprintf(msg, sizeof(msg), "V=%.2f SoC=%.1f", v, soc);
Particle.publish("batterie", msg, PRIVATE);
if (soc < SEUIL_BAS && !alerteEnvoyee) {
snprintf(msg, sizeof(msg), "SOC=%.0f%% U=%.2fV", soc, v);
Particle.publish("batterie-alerte", msg, ALWAYS);
alerteEnvoyee = true;
}
if (soc > SEUIL_CRITIQUE + 20) alerteEnvoyee = false; // hysteresis
Serial.printf("%.2f V / %.1f %%\n", v, soc);
}
delay(60000); // 1 minute pour le test ; 1 h en production (+ sommeil)
}
If the charging LED blinks rapidly without a battery, disable charging persistently via SystemPowerFeature::DISABLE_CHARGING (Power Manager) rather than PMIC.disableCharging, which the Power Manager reapplies on reset.
Expected verification
Connected to USB with an empty LiPo: the charging LED is on, the percentage rises steadily, and batterie events follow. Unplug USB: the measured voltage corresponds to the LiPo's resting state. Simulate a low threshold (soc < 35): the batterie-alerte event is published only once thanks to anti-repetition, then rearms after recharging.
Common errors
- Inverted LiPo polarity on first connection: risk of immediate destruction; check the plug and cable before first power-up.
- Ignoring the 1 Hz blink (charging fault): the battery never reaches full charge and the advertised autonomy is incorrect.
- Letting the LiPo drop below ~3 V: deep discharge, cards observed in a 10 SOS loop requiring a DFU re-flash and device re-claim.
- Relying on
getSoCalone just after charging: the gauge recalibrates over a full charge-discharge cycle; cross-reference withgetVCell. - Charging via a 500 mA USB port with a 2G/3G model: the SARA-U201 peaks reach 1.8 A in 2G and cause voltage drops; these models require 2 A or a connected LiPo.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-evenement.inoArduinofonction-distance.inoArduinocapteur-dht.inoArduinoruban-neopixel.inoArduinopwm-respiration.inoArduino