ESP32 V3 Read Battery Voltage Questions

Hi,

I have read many different threads about measuring lithium battery voltage with both the V2 and V3 ESP32, but I am yet to find a code that works for me (with a V3 board), nor really a single uniform solution that most people seem to be happy with. Therefore, I am starting this thread to hopefully manage to find a solution once and for all.

The main problem that I am facing is that I cannot just connect the battery output to an ADC pin, as this would destroy it, because the battery voltage can be as high as 4.2V, which is much beyond the safe limit of 3.3V for the ADC. A simple “stupid” fix would of course be to add a resistor voltage divider to reduce the output voltage, but looking at the schematic of the board, there already seems to be an internal voltage divider at GPIO1 (VBAT_Read) to reduce the battery output voltage to a safe range:

Regarding that, I have two questions:

  1. It would not be smart to use an external voltage divider between the battery output and any ADC pins, as this would result in a constant load for the battery, reducing its lifetime. Would the internal divider also be constantly loading the battery, or is there a way to switch the connection off when not reading the voltage?
  2. How can the internal voltage divider be used? I have tried a few codes from other threads on a similar issue, but none of them seem to have worked so far, as I always get a reading of 4095 (when the battery voltage has been 3.2-4.2V), indicating that the internal voltage divider has not been used. I have noticed, that I might have to play around with GPIO37 (ADC_Ctrl) for it to work but I haven’t figured out what to do. Do I have to write something in code, do I have to wire it to some other pin, or do I have to do both?

I hope that someone smarter than I can help me figure this out, and that this thread could hopefully also help other people like me, who are facing the same problems - which there seems to be plenty of.

Many thanks to anyone that can help. Any other tips and trick are also very welcome.

This is a link to a page I wrote about this recently, following all the discussion I’d read in various threads in this Forum. It includes a discussion of the circuitry you could use for a ‘MOSFET-switched’ voltage divider that would not drain the battery when not in use followed by descriptions of the similarly ‘MOSFET-switched’ battery measurement circuits on the various Heltec boards that I’ve used. The page also includes code that I have used on the relevant boards.

1 Like

Thank you very much, I will read it and try out the learnings today.

It may be a very dumb question, but would I have to physically connect GPIO1 to battery output? Otherwise the post you made was very comprehensive and a good overview, thanks.

No, that connection is already made internally (as is, I believe—I can’t say I’ve checked every one—the case for all of the pins with functions identified, in the pinout diagram, in purple boxes).