Olimex Support Forum

Microcontrollers => ESP32 => Topic started by: smith on July 27, 2024, 01:41:01 PM

Title: Reading as accurate as possible voltage with ESP32 dev kit lipo
Post by: smith on July 27, 2024, 01:41:01 PM
I have DevKit-Lipo Rev_C, connected to a single 18650 LiPo cell.
I've soldered BAT_PWR_E1, BAT_SENS_E1 and PWR_SENS_E jumpers.

I read the pins like this:

const int GPI_VOLTAGE_SENS = 39;
const int GPI_POWER_SENS = 36;
....
pinMode(GPI_VOLTAGE_SENS, INPUT);
pinMode(GPI_POWER_SENS, INPUT);
....
const int voltage_sensor_reading = analogReadRaw(voltageSnesorPin);
const int power_present_reading = analogRead (powerSensorPin);

The readings I get are:
If charging:
voltage is between 3000 and 4095
power present is between 200 and 400
If discharging:
voltage is between 310 and 270
power present is 0, occasionally making a single jump to 200

All these numbers vary on different boards.
My question is - what is your recommendation to translate these numbers into as accurate as possible voltage?
Title: Re: Reading as accurate as possible voltage with ESP32 dev kit lipo
Post by: LubOlimex on July 29, 2024, 10:32:06 AM
Maybe try the demo we tested for ESP32-POE, just put your pins:

https://github.com/OLIMEX/ESP32-POE/blob/master/SOFTWARE/ARDUINO/ESP32_PoE_PowerReading/ESP32_PoE_PowerReading.ino

Let me know how it goes.
Title: Re: Reading as accurate as possible voltage with ESP32 dev kit lipo
Post by: smith on July 29, 2024, 11:41:12 AM
Ok, It seems that I've been reading the wrong pins.
Apparently for 'DevKitLipo Rev C' voltage pin is 35 and power present pin is 39, I could not figure this out after reading the documentation, thank you for your help.
Title: Re: Reading as accurate as possible voltage with ESP32 dev kit lipo
Post by: LubOlimex on July 29, 2024, 11:56:22 AM
Glad you got it working. It is visible in this part of the schematic:

https://imgur.com/a/cOkqJE8
Title: Re: Reading as accurate as possible voltage with ESP32 dev kit lipo
Post by: smith on July 29, 2024, 03:02:16 PM
Yes, but also this image:
https://www.olimex.com/Products/IoT/ESP32/ESP32-DevKit-LiPo/resources/ESP32-DevKit-Lipo-GPIOs.png

So I tested several configurations and got confused eventually.
Anyway - thanks for the help, works great now.
Title: Re: Reading as accurate as possible voltage with ESP32 dev kit lipo
Post by: LubOlimex on July 30, 2024, 01:59:14 PM
This image looks wrong, better trust the schematic, I will see if I can remake in future since I can't find the source at the moment.