ESP32-Lipo measure battery voltage

Started by spynappels, December 04, 2020, 09:36:54 am

Previous topic - Next topic

spynappels

Hi All,

I'm looking for some guidance on measuring the battery voltage on a Rev C ESP32-DevKit-Lipo.

I know I have to bridge the jumper on the back of the board beside GPIO39 to enable this, but once this is done is it just a case of doing an analog read of GPIO39? Has anyone published some sample code for this, as I'm not sure what it references the analog read value against to get a valid comparison.

Essentially, I am using this device as a Bluetooth HID and want to see the battery state on the laptop as you can do with any bluetoothLE device. The code to do this is not a problem, once I am able to get a read from the battery voltage.

Thanks for any help you can give me.
Stefan

spynappels

I've been looking at this some more, and the hardware schematics seems to contradict the info on the pinout diagram.

If I've read the hardware schematic correctly, GPIO39 is actually the external power sense pin, not the battery voltage sense. GPIO35 is the one which according to the schematic measures the output of the battery through a voltage divider. It looks like the voltage divider has 2 x 470k resistors, meaning the pin will sense between 2.1v at fully charged and 1.5v at fully depleted.

So can someone from Olimex please confirm whether the pinout page is correct or whether the hardware schematic is correct and which GPIO pin actually can be used to measure voltage from the battery through the voltage divider?

spynappels

In addition, can you please confirm whether both BAT_PWR_E1 and BAT_SENS_E1 jumpers need to be bridged to sense battery voltage? again, the schematics seem to suggest so, but the GPIO guide suggests that only the BAT_SENS_E1 jumper needs to be bridged.

Is the Hardware schematic the one to follow in this case?

spynappels

After more trial and error, it looks like the schematics are correct.
Both the BAT_PWR_E1 and BAT_SENS_E1 jumpers need to be bridged, and GPIO35 is the correct one to use for the analogRead() call.
The voltage on that pin is half of the actual Vbat, so perfectly fine for using to monitor the battery percentage left to report to the laptop via BLE.

How would I go about raising a documentation bug against the ESP32-Devkit-Lipo GPIOMap document?

spynappels

Quote from: spynappels on December 05, 2020, 05:17:27 pmHow would I go about raising a documentation bug against the ESP32-Devkit-Lipo GPIOMap document?
@LubOlimex ?

LubOlimex

There is an option to enable battery measurement and external power detection.

There is battery measurement circuitry lead to a GPIO pin, but it requires closing two SMT jumpers (soldering pads of each jumper together). Refer to the schematic that I will link below and search for BAT_PWR_E1 and BAT_SENS_E1, top part of the schematic, in the middle. There is also option to enable external power detection on another pin (if you close jumper PWR_SENS_E1).

https://github.com/OLIMEX/ESP32-DevKit-LiPo/blob/master/HARDWARE/ESP32-DevKit-LiPo-Rev.C/ESP32-DevKit-Lipo_Rev_C.pdf
Technical support and documentation manager at Olimex