rlogiacco / BatterySense

Arduino library to monitor battery consumption
GNU Lesser General Public License v3.0
416 stars 76 forks source link

Higher voltage than expected #43

Closed DansDesigns closed 2 years ago

DansDesigns commented 2 years ago

Discussed in https://github.com/rlogiacco/BatterySense/discussions/42

Originally posted by **Dans-Droids** December 6, 2021 Hi, thank you for making this brilliant library! I am finding that on my STM32F103C8, powered by a single Li-Po through a 5v3a regulator with the sense pin on PA1, the returned voltage is higher than it should be. I have found that with the value of 5000 in the following, the recorded voltage is around 7680: battery.begin(5000, 1.47, &sigmoidal); - if i change the 5000 to 3300, this causes the recorded voltage to be around 4850 . Do i need to reference the 1.1v Analog Voltage of the pins? I am planning to use the ADCTouchSensor library on pin PA6 - this requires the Analog Reference to be floating... Would this interfere with this BatterySense library?? Thank you for your help!
rlogiacco commented 2 years ago

I don't have much knowledge of the micro you are using, but I believe you are on a 3.3V micro (so you have to use the 3300 setup vale) and your PA1 pin is correctly reporting 4850mV (close enough to 5V). Can't say much on library interferences, I can only say the library doesn't use timers nor interrupts, so my best guess on interference is there should be none, unless those pins share the same analog multiplexer.

DansDesigns commented 2 years ago

Thank you for the response. I forgot to mention that the SensePin is directly connected to the Li-Po batterie's +ve... Am I correct in expecting the SensePin to be the same voltage as the Li-Po?

If this is the case, can you help me understand why the value would be close to 5v - when it should be 3.8-4.2V? Also I noticed that the value does not change as the battery drains - even though the code is in the loop in an otherwise empty sketch?

rlogiacco commented 2 years ago

Please attach a schematics of your circuit.

DansDesigns commented 2 years ago

it is exactly as pictured in the "lesser than 5v with voltage booster" https://github.com/rlogiacco/BatterySense#lesser-than-5v-with-voltage-booster

EDIT: with a BME280 over I2C and a nextion 2.4" Serial Display on Serial2.. all share the same 5V3A boosted power supply

rlogiacco commented 2 years ago

Is your device a 5V or a 3.3V device? Is the battery a single cell LiPo or a two cells LiPo?

Unless you are on a 5V device and a single cell LiPo I don't see how you can measure the battery voltage because it would be above the sensing limits.

The MCU you are referring to (STM32F103C8) is a 3.3V device, meaning the highest voltage it can sense is 3.3V and, if powered from a 5V source, such 5V is stepped down to 3.3V by an onboard regulator.

The LiPo you are measuring, assuming it is a single cell, has a voltage ranging from 3.7 to 4.2 and to measure it you need a voltage divider.

DansDesigns commented 2 years ago

Hi rlogiacco,

Sorry for the delay in responding, I have been working on other projects and see your reply..

Yes you are correct, it is a single cell LiPo giving 3.8V - 4.2V. This goes to a dc-dc converter that gives constant 5V3A output to power the STM32F103C8 and other devices..

I shall connect up a voltage divider and see what happens.

Thank you for your help