🛠 Gestion de batterie LiPo : jauge, charge et seuils bas

Particle Boron · avance · Schéma : IMG-particle-boron-avance-2-boron-gestion-batterie.svg — Boron reliée à une LiPo avec chargeur intégré, LED de statut de charge, jauges tension et pourcentage lues par FuelGauge.

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials