# Battery Example This example shows how to use `espp::BatteryLion` (`espp::Battery` with a Li-ion cell curve) to estimate a pack's state of charge from its voltage and charge current. It needs no hardware: it simulates a 2S, 2000 mAh Li-ion pack (rest voltage from the cell curve, plus I x R and a polarization that settles over a minute) on a 1 A CC / 8.4 V CV charger. Every 10 minutes it prints: - the true SoC; - what the rest curve alone gives for the voltage under charge; - the estimate. ## How to use example ### Hardware Required Any ESP32 dev board: the pack and the charger are simulated. ### Build and Flash Build the project and flash it to the board, then run monitor tool to view serial output: ``` idf.py -p PORT flash monitor ``` (Replace PORT with the name of the serial port to use.) (To exit the serial monitor, type ``Ctrl-]``.) See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. ## Example Output The voltage-only figure reads 66-95 % in the constant-current stage, for a pack at 55-80 %. It reads 100 % in the constant-voltage stage from 88 %. The estimate stays within 0.3 points in the constant-current stage, runs at most ~1.5 points ahead in the constant-voltage stage, and reads 100 % once the charger's current has tapered off: ``` at rest: 7.67 V -> 55.0 % charging a pack at 55 % (CC 1 A, CV 8.4 V), then resting: min | true SoC | voltage | current | voltage only | estimate 0 | 55.0% | 7.82 V | 1000 mA | 65.7% | 55.0% 10 | 63.3% | 8.04 V | 1000 mA | 79.8% | 63.3% 20 | 71.7% | 8.16 V | 1000 mA | 87.3% | 71.5% 30 | 80.0% | 8.29 V | 1000 mA | 95.0% | 79.7% 40 | 88.2% | 8.40 V | 894 mA | 100.0% | 88.0% 50 | 93.9% | 8.40 V | 503 mA | 100.0% | 94.7% 60 | 97.1% | 8.40 V | 280 mA | 100.0% | 98.5% 70 | 98.9% | 8.40 V | 156 mA | 100.0% | 99.8% 80 | 99.7% | 8.38 V | 0 mA | 99.7% | 100.0% (full) 90 | 99.7% | 8.37 V | 0 mA | 99.7% | 100.0% (full) 100 | 99.7% | 8.37 V | 0 mA | 99.7% | 100.0% (full) 110 | 99.7% | 8.37 V | 0 mA | 99.7% | 100.0% (full) 120 | 99.7% | 8.37 V | 0 mA | 99.7% | 100.0% (full) 150 | 99.7% | 8.37 V | 0 mA | 99.7% | 100.0% (full) 180 | 99.7% | 8.37 V | 0 mA | 99.7% | 100.0% (full) Battery example complete ```
To create a project from this example, run:
idf.py create-project-from-example "espp/battery=1.5.0:example"