Always reading same battery voltage
-
Thanks for the reply.
But I can't really understand what is going on. When I have the USB connected and the battery with attenuation on 1. I am always reading 4095. When I have the USB connected and the battery with attenuation on 3. I am reading 1503, 1508, 1533 etc.
What does these values mean? How is it related to the battery?
What does attenuation even mean? How can I determine the value of that?When reading the value with the multimeter it is saying 3.90V. Which I totally understand.
Is this correct?
100.00% 4.2
90 4.13
80 4.06
70 3.99
60 3.92
50 3.85
40 3.78
30 3.71
20 3.64
10 3.57
0.00% 3.5 -
@mmarkvoort I'm wondering whether you use the expansion board or not.
The basic range of the adc is 0..1V. With 3 db attenuation it is:
attn 1 = 3db: 10**(3/20) * 1 -> 0.. 1.41
attn 2 = 6db: 10**(6/20) * 1 -> 0.. 1.995
attn 3 = 11 db: 10**(11/20) * 1 -> 0..3.548
The expansion board has a voltage divider between battery and P16, consisting of a 56k/100k resistor, reducing the battery voltage by 56/(56+100) = 0.359.
So the 3.9 V of the battery are seen at P16 as 1.4 V. At attn 3 that should give a reading of 1.4/3.548 * 4096 = 1616. Since your value are different, I assume that the voltage divider has a different set of resistors. You could take the voltage directly at P16 to verify, and then you know the compensation factor.
Update, since my board's values differ from the documentation.
The capacity of the battery does not follow linear to the voltage. It's a kind of lying ' S' kind shape. http://www.thedroneinfo.com/2015/05/13/how-to-care-and-feeding-of-your-lipo-battery/ -
Thanks again for your repley.
I have a LoPy and a Expansion board.When I measure on pin 16:
With only USB I get: 1.4 V
With USB and Battery I get: 1.3 V
With only Battery I get: 1.2 VWhen I measure battery directly I get: 3.79 V
When I use attn 3 and the code from the post I get:
Mean of ADC readings (0-4096) = 1581.0400009155273
Mean of ADC readings (0-1400 mV) = 540.3944969177246When I use attn3 and the code from the post with (meanADC * 3548/4096) instead of (meanADC*1400/4096) I get:
Mean of ADC readings = 1401.6300201416015
Mean of ADC readings = 1214.1072750091552Which one is good? Is it even good? I am a bit lost what to do.
-
@mmarkvoort There are two factors top be considered.
a) the resistor divider. You said that with bettery only you have 1.2 V at P16. Could you measure the battery directly in that mode, connected to lopy and running. Then this ratio, Vp16/Vbat = R is known, and the battery voltage can for attn = 3 be calculated as:Vmeas = (ADCmean /4096) * 3.548 /R
Example:
ADCmean = 1401
R = 1.2/3.79 = 0.316
Vmeas = (1581/4096) * 3.548 / 0.316 = 3.804 -
Wow wait a minute...
I used 3548 instead of 3.548 in my code :')
Now when I read the val of pin 16 I get 1439.
So this means it is 1439*3.548/4096 = 1.246477
Measure pin 16 directly with multimeter gives me: 1.25This is good right??
But how can I get the voltage of the battery? I can't because I dont know R right?
-
@mmarkvoort R is the ratio:
Voltage_at_P16 / Voltage_at_battery
According to the schematics, it is 0.3275, which gives ~3.8 V = 1.246/ 0..3275 at the battery, but better check. -
But you can't get the Voltage_at_battery through code, right?
Thanks a lot by the way, you helped me a lot! :)
-
@mmarkvoort Yes, you can. Since R is a fixed value, you can get determine the Voltage at P16 by code and calculate the battery voltage as:
Voltage_at_P16/R -
But doesn't the value of R changes everytime?
You said R = Voltage_at_P16 / Voltage_at_battery, but how can you get Voltage_at_battery in the code.
Or in other words, how did you get the 0.3275 as a value?
EDIT: 0.3275 seems to be a good value indeed.
-
@mmarkvoort No, R is defined by the circuitry of the expansion board, and is fixed. The schematics show a voltage divider consisting of two resistors, one 56k, the other 115k, and so R can be calculated as:
R = 56 / (56 + 115)
If you want to find R by measuring, you have to take a Voltmeter and measure the real values at the battery and at P16, while the device is running from battery.
-
Robert thank you very much for your help.
I finally get it! -
Just some questions.
Is it a good idea to put a capacitor between battery and LoPy to reduce noise?
Now when I am reading the battery value it really fluctuates.Also sometimes when connecting the battery it is always reading low value. When move the connector a bit it is changing. What can this be? Is it the startup that needs a bit more?
And lastly, does it make a difference if I have a sensor connected?
-
@mmarkvoort The ADC of the esp32 is known to be very bad. If if you apply a perfectly good signal (stable, low impedance), the reading will fluctuate a lot. That's why in the sample code the average is used.
A capacitor will only help if placed directly at P16. and it must be a low impedance capacitor (ceramic, short leads). -
Aha, so it isn't me :)
Thanks, I thaught I did something wrong.Does it matter if you have sensors connected to the LoPy?
-
@mmarkvoort Other sensors do not hurt. When USB is connected, the battery voltage is higher, since it will be charged at that time.
And yes, if the voltage changes when you touch the connector, then you have a bad connector. By maybe that was just coincidence with the other fluctuations. -
Oke, will make a test program.
When USB is connected it indeed has a higher voltage :').
That was another mistake/issue I had :).Thanks a lot, again!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login