Measure LiPol battery level
Measure LiPol battery level
I bought a ESP32 Thing from SparkFun. It is powered by LiPol battery (3.7V 2500 mAh) and can't figure out how can I measure the battery level using voltage divider. Can anybody help me? Thanks.
Re: Measure LiPol battery level
I use a 27 kOhm + 100 kOhm voltage divider to bring the 4.2 V maximum of a single cell LiPo battery down to 3.3 V, which is the reference voltage (AFAIK) of the ESP32 board I am using. I have the voltage divider connected to pin 34, and I read the pin as follows:
The ADC is 12-bit which is why the 3.3/4096 (ref voltage/max counts) conversion factor is in there. When the analog read returns 0, the battery voltage is 0, and when it returns 4095, the battery voltage is 4.2 V. The response of the ESP32 ADCs is apparently non-linear so you will have to calibrate the response and correct for maximum accuracy.
Code: Select all
float VBAT = (127.0f/100.0f) * 3.30f * float(analogRead(34)) / 4096.0f; // LiPo battery
Serial.print("Battery Voltage = "); Serial.print(VBAT, 2); Serial.println(" V");
The ADC is 12-bit which is why the 3.3/4096 (ref voltage/max counts) conversion factor is in there. When the analog read returns 0, the battery voltage is 0, and when it returns 4095, the battery voltage is 4.2 V. The response of the ESP32 ADCs is apparently non-linear so you will have to calibrate the response and correct for maximum accuracy.
Re: Measure LiPol battery level
onehorse wrote:
Code: Select all
float VBAT = (127.0f/100.0f) * 3.30f * float(analogRead(34)) / 4096.0f; // LiPo battery Serial.print("Battery Voltage = "); Serial.print(VBAT, 2); Serial.println(" V");
The ADC is 12-bit which is why the 3.3/4096 (ref voltage/max counts) conversion factor is in there. When the analog read returns 0, the battery voltage is 0, and when it returns 4095, the battery voltage is 4.2 V. The response of the ESP32 ADCs is apparently non-linear so you will have to calibrate the response and correct for maximum accuracy.
hi
wounder me to use better
ADC 12 Bit = 0b 1111 1111 1111 = 4095
3.3 / 4095 = 8,0586080586080586080586080586081e-4
if return 4095 (max RAW) :
4095 * 8,0586080586080586080586080586081e-4 = 3.3
if return 0:
0 * 8,0586080586080586080586080586081e-4 = 0
if return 2:
2 * 8,0586080586080586080586080586081e-4 = 0,00161172161172161172161172161172
---
3.3 / 4096 = 0,0008056640625
if return 4095 (max RAW):
4095 * 0,0008056640625 = 3,2991943359375 ( missing one part )
if return 0:
0 * 0,0008056640625 = 0
if return 2:
2 * 0,0008056640625 = 0,001611328125
btw:
4.2 Cell
4.2 / 4096 = 0,001025390625
Max RAW Return 4095 :
4095 * 0,001025390625 = 4,198974609375 ( missing one part )
4.2 Cell
4.2 / 4095 = 0,00102564102564102564102564102564
Max RAW Return 4095 :
4095 * 0,001025390625 = 4,2
Code: Select all
float VBAT = (127.0f/100.0f) * 3.30f * float(analogRead(34)) / 4095.0f; // LiPo battery
Serial.print("Battery Voltage = "); Serial.print(VBAT, 2); Serial.println(" V");
best wishes
rudi
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪
-
- Posts: 6
- Joined: Mon Jul 01, 2019 2:55 pm
Re: Measure LiPol battery level
is it internal adc reference voltage?onehorse wrote: ↑Fri Jan 06, 2017 2:33 amI use a 27 kOhm + 100 kOhm voltage divider to bring the 4.2 V maximum of a single cell LiPo battery down to 3.3 V, which is the reference voltage (AFAIK) of the ESP32 board I am using. I have the voltage divider connected to pin 34, and I read the pin as follows:
Code: Select all
float VBAT = (127.0f/100.0f) * 3.30f * float(analogRead(34)) / 4096.0f; // LiPo battery Serial.print("Battery Voltage = "); Serial.print(VBAT, 2); Serial.println(" V");
The ADC is 12-bit which is why the 3.3/4096 (ref voltage/max counts) conversion factor is in there. When the analog read returns 0, the battery voltage is 0, and when it returns 4095, the battery voltage is 4.2 V. The response of the ESP32 ADCs is apparently non-linear so you will have to calibrate the response and correct for maximum accuracy.
-
- Posts: 2
- Joined: Sun Jul 07, 2019 4:16 am
Re: Measure LiPol battery level
You really wont be able to measure the voltage over time on a 0-100% basis similar to your iphone if this is what you are looking to do. The drain of lipo batteries is non-linear and requires a separate circuit usually called a fuel gauge to read its drain output like such. The closest you'll be able to get with using the internal ADC is knowing when you have enough voltage and perhaps right before the battery is about to die, ie. some kind of low batt indication (but from my experience and knowledge it will die quickly after depending on the overall power draw but usually in under 10-15mins for low level indication). A board like the TP4056 can help handle this basic voltage sensing as well as the ability to recharge the lipo.
-
- Posts: 9
- Joined: Fri Jan 05, 2018 1:38 am
Re: Measure LiPol battery level
Your voltage divider calculation is wrong. If you have 2 resistors as a voltage divider, call the top resister R1 (the one that is connected to the voltage to be measured) and call the bottom resister R2. Use R1/(R1+R2). This will give you the correct divisor, or 1/divisor to give you the multiplier.
Re: Measure LiPol battery level
Hi
@wyattisawesome which fuel gauge chip/module can be used with ESP-IDF? Have you successfully used any fuel gauge with ESP32?
@wyattisawesome which fuel gauge chip/module can be used with ESP-IDF? Have you successfully used any fuel gauge with ESP32?
Who is online
Users browsing this forum: No registered users and 105 guests