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:
- 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?
- 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.