Thanks TS-Mark!
You are right… just looking at voltage is not the right way to go.
After some trial and error, looking at different ways of doing it, I converged on the following, which works very well (see test below). This is inspired by this excellent video:
https://www.youtube.com/watch?v=3yHRrPDczK4
Hardware:
-
Get a Fuel Gauge circuit (FG: got the Sparkfun TOL-10617). This is a bit of money, but it will save you a lot of headaches. It is based around the MAX 17043 fuel gauge, which is I2C accessible.
-
I use a ESP32 WROOM (ESP: but I don’t think the type matters much)
-
Connect the VBAT and ground of the ESP to the + and - of the FG (respectively)
-
Connect the SDA (pin23) and SCL (pin 22) of the ESP to the SDA and SCL pins of the FG (respectively)
-
Connect the ground of the FG to the ground of the ESP
Software:
Download/Install the I2C MAX 17043 library from Github as a ZIP file
https://github.com/lucadentella/ArduinoLib_MAX17043
(but see also https://github.com/awelters/LiPoFuelGauge)
using the Arduino IDE install it (Sketch>Include Library > Add .ZIP Library)
and as far as code, basically, you need the following:
…
#include “MAX17043.h” // fuel gauge
#include “Wire.h”
MAX17043 batteryMonitor;
…
setup(){
…
Wire.begin(); // Fuel Gauge
batteryMonitor.reset();
batteryMonitor.quickStart();
…
}
loop(){
…
float soc = batteryMonitor.getSoC();
float voltage= batteryMonitor.getVCell();
Serial.printf(“%d: BatteryTest SOC=%.1f %%, Voltage=%.1f V\n”, idx,soc, voltage);
delay(10000);
}
Here is a battery run-down test. For this I used one ESP32WROOM wifi connected using painless mesh to a ESP32 Thing. The WROOM is sending a LiPo battery (DTP603450, 3.7V 1000mAh) readout every 10 seconds to the ESP32Thing which sends it through its COM link to a Labview program that stores the readout in an Excel spreadsheet (part of a larger program, not important here). You can see the discharge, then the WROOM stops working (overnight run), then the charge rate (plugged the WROOM into the USB in the morning).
Conclusions: In this particular setup: no need to query the battery more than 1/minute (every 2 minutes is fine), alert the user at 30% and critical at 20%. Time to recharge:~3.3hours.
Hope this is useful to everyone!
Comments/improvement welcome… Please post here.
BatteryTest.pdf (406 KB)