ESP32-H2-DevKit-Lipo - Battery measures

Started by lmerckx, October 12, 2025, 07:27:57 PM

Previous topic - Next topic

lmerckx

Hello,

I have the Olimex ESP32-H2-DevKit-Lipo and a battery 3.7V 1400mAh (JA-803450P) and try to measure the voltage of the battery to compute the percentage of the battery but I receive strange results.

I soldered jumpers BAT_SENSE_E and PWR_SENSE_E1 as explained in the manual and tried the example code to read pins 25 (POWER_SENSE) and 2 (BATTERY).

It works perfectly for the POWER_SENSE: testing with USB connection or battery only, it returns me the expected result.
But I have issues when trying to read the battery voltage.
- when connecting USB only: I always receive the analog value 652 or 653 (so 3716.40 mV or 3722,10 mV after multiplying by 5.7).
- when connecting both USB and battery: most of the time, I receive the same value but once on 10 measures I receive another value: 667 or 668 (so 3801.90 mV or 3807.60 mV). -> I suppose this to be the real measure of the battery because the value slightly increase with time.
- when connecting with battery only: again, I think I receive only the value 652 or 653. To be honest, I'm still not sure of that because I don't have the serial connection to debug and must rely only on my Zigbee report.

Is it the normal behavior of the pin ? I check my solder twice with multimeter and it seems quite good.
Any idea ?

Thanks in advance.

LubOlimex

Seems fine to me. It just takes a lot of time to fully charge and discharge. The board is set to charge with only 100mA. Let it charge for a couple of hours and compare the value again. The JA-803450P should go up to 4.2V when fully charged. Alternatively let your software run only on battery and check the progress without connecting the USB to it.
Technical support and documentation manager at Olimex

lmerckx

Thanks for the answer.
I will try a longer charge and check values.

Thanks.

LubOlimex

Notice that when you have both USB and a battery attached, the battery measurement will not be correct, it will be influenced by the battery charger. The battery measurement is only correct when there is only battery powering the board. Hence it is helpful to utilize the External Power Sense and only measure the battery when there is no external power applied.
Technical support and documentation manager at Olimex

lmerckx

Hello,

I tested further like this:
- longer charge of the battery
- use 100 measures of the battery voltage (each 10 ms) and use the average as final value

And indeed, the battery voltage increased slowly as expected until a peak.
But now that this peak is reached, analogReadMilliVolts always returns 667 or 668. So, 3801.90 or 3807.60 mV (after multiplying by 5.7). I expected (like you above) to reach +/- 4200 mV for my battery.
My code for one measurement is simply: analogReadMilliVolts(BATTERY_VOLTAGE_PIN) * 5.7f
as explained in the documentation.
Have you an idea ?

About your last comment, is it possible that the influence of the charger on battery measurement only happens when battery is low ?
Because I noticed it at the beginning but no more now.
Now, I measure the same voltage if the battery and USB are both connected or if it is only the battery.

Sorry for all these questions. And thanks for your support.

LubOlimex

Did you measure the voltage of the battery with external tool to compare with the software readings?
Technical support and documentation manager at Olimex

lmerckx

No. I suppose I can test it with a simple multimeter between the red and black wires ?
I will try.

Thanks.

LubOlimex

#7
Yes, just set in voltage measurement mode and measure between + and - of battery to see what is the real voltage of the battery and if there is huge difference between the software report.

Meanwhile I also got one board to test here. This is my Arduino code:

#define POWER_SENSE 25
#define BATTERY 2

void setup()
{
  Serial.begin (115200);
  pinMode (POWER_SENSE, INPUT);
  pinMode (BATTERY, INPUT);
}

void loop()
{
  Serial.print ("External power sense: ");
  Serial.println (digitalRead (POWER_SENSE));

  Serial.print ("Battery measurement: ");
  Serial.print (analogReadMilliVolts (BATTERY)*5.7);
  Serial.println (" mV");

  Serial.println ();

  delay (2000);
}

So far the software shows that my battery is 4058.40 mV and the measurement via voltage meter is pretty close at 4060. The charge current is around 75mA, this is expected since after 3.7V DC the charger charges with lower current than the maximum allowed (which is 100mA).
Technical support and documentation manager at Olimex

lmerckx

Hello LubOlimex,

Thank you again for your help.

My code is exactly the same for getting the voltage of the battery. Except that now, I also compute an average of 100 values to get a stable value.
Here is a sample of trace:
Voltage: avg = 3804.69 mV - min = 3801.90 mV - max = 3807.60 mV
Voltage: avg = 3804.81 mV - min = 3801.90 mV - max = 3807.60 mV
Voltage: avg = 3804.75 mV - min = 3801.90 mV - max = 3807.60 mV
Voltage: avg = 3805.03 mV - min = 3801.90 mV - max = 3807.60 mV
Voltage: avg = 3804.64 mV - min = 3801.90 mV - max = 3807.60 mV
We can see that minimum and maximum measures are very closed.

The interesting point of your proposal is the results I got with my multimeter.
Measure from the Olimex card: 3804 mV (with or without the USB cable); measure from my multimeter: 3,95 V
I tried to charge the battery for one hour more and made a new measure after:
Measure from the Olimex card: 3804 mV (with or without the USB cable); measure from my multimeter: 3,97 V

It makes me think of a peak reached in the measure that cannot be exceeded.
Can it be a problem with the card ? Or a calibration to do ?

LubOlimex

It is not perfect here either. The battery seems to be fully charged, the yellow LED turned off (this is indication it is no longer charging) and I get 4143.90 mV ~ 4.14V from the software.

If I measure just the battery it is 4.21V. So the ADC is definitely not perfect.
Technical support and documentation manager at Olimex

lmerckx

Indeed, I think the problem is due to the ADC reliability.
I persisted in charging the battery and finally it was full after several hours.

What I didn't understand is that the voltage returned by the ADC is not linear.
It grows fast until a plateau. Then, the ADC returns the same value for a very long period, then it grows again fast until another plateau, etc.
For my battery, these plateau's are around 667 (+/- 3800 mV), 683 (+/- 3890 mV) and 699 (+/- 3990 mV).
When my battery was finally charged and the LED turned off, the value returned by the ADC was 716 (4081.20 mV). But when I checked with the multimeter, the real value was indeed 4,19 V.

So, perhaps I was simply not patient enough and the ADC behavior perturbed me.

Just a last question: to correct the value returned by the ADC and approximately match the real voltage of the battery, can I multiply by 5.87 instead of 5.7. Or is there a better solution for that ?

Thanks again.