batterie_lipo.ino

Arduino Nicla Sense ME · File : batterie_lipo.ino · Language : Arduino · Use case : Gérer la charge de la batterie LiPo

The Sense ME BQ25120 charger is a software-command tree: this sketch sets 100 mA charge current, disables the NTC sense when the LiPo lacks one, and prints cell voltage and percentage. The base of every battery application.

Hardware

An Arduino Nicla Sense ME (nRF52832, BLE only) with Bosch BHI260AP hub, BMM150, BMP390, BME688 sensors, RGB LED on an I2C driver and LiPo charger. A single-cell 3.7 V LiPo on the 3-pin ACH connector (J4) plus a USB or VIN 3.5-5.5 V source to charge.

Wiring

Cell + to ACH J4 (mind polarity!), 0 V to center. USB or VIN powers the board AND recharges the cell through the BQ25120.

How it works

nicla::begin unlocks the charger registers; enableCharging(100) caps current (safe 0.5C for 200 mAh); getBatteryVoltagePercentage estimates level from voltage. The NTC is optional on the cell.

Running it

Programmed from the Arduino IDE (ArduinoCore-mbed); Arduino_BHY2 and Nicla_System libraries; USB through a serial bridge.

Variants

Tune current to 0.5C of your cell, stop charging below 0 °C (a LiPo requirement), or deep-sleep between readings to chase the advertised 460 µA standby.

batterie_lipo.ino

// Le chargeur BQ25120 est un arbre à commandes logiciel (docs-db) :
// nicla:: pilote courant de charge, NTC, timer de sécurité.
// Alimenter en USB ou VIN pendant la charge.

#include "Nicla_System.h"

void setup() {
  Serial.begin(115200);
  nicla::begin();

  // LiPo sans sonde NTC : désactiver la lecture NTC sinon erreur
  nicla::setBatteryNTCEnabled(false);

  // 100 mA = ~0,5C pour une cellule 200+ mAh (valeur sûre)
  nicla::enableCharging(100);
}

void loop() {
  static unsigned long t = 0;
  if (millis() - t > 5000) {
    t = millis();

    int pct = nicla::getBatteryVoltagePercentage();
    float vbat = nicla::getCurrentBatteryVoltage();

    Serial.print("Batterie : ");
    Serial.print(pct); Serial.print(" %  ");
    Serial.print(vbat, 2); Serial.println(" V");

    if (pct < 10) {
      nicla::leds.begin();
      nicla::leds.setColor(red);   // alarme batterie critique
    }
  }
  delay(10);
}

← Back to the board