Analog Read Accuracy

Happy Hippo
Posts: 1
Joined: Mon Nov 11, 2019 4:25 am

Analog Read Accuracy

Postby Happy Hippo » Mon Nov 11, 2019 4:58 am

I just started dabbling in ESP32 with both MicroPython and Arduino IDE. I have a few different boards but the one I'm looking at now has an OLED and an 18650 LiIon battery. So I thought I'd start with something simple: display time from the internet (to test the wifi part of the board) and display the battery voltage, to test the board pins. Since the battery can get up to 4.2 V, I made a voltage divider so that the input pin would see less than 3.3 V, since that is the limitation. So after I built everything, I see the actual battery voltage is 4.08 V. The analog input is 3.187 V (divided by 100/128). But the ESP32 is telling me the pin is at 4095 (it should have been 3955). I spent about 30 minutes checking my setup and everything checked out. Then I started searching on the internet. In this forum, and other places, it is well known that the ADC is non-linear. So I have a couple of questions.

1) Is it still the case for the non-linearity? No firmware fixes or such? It seems odd that such a glaring problem would be allowed to remain.
2) I'll have to make a different voltage divider (and I was so proud of the one I already made :(). What design point do I use? 3.05 V maximum? That is to say, when the battery reaches 4.2 V, the input to the ESP32 pin will be 3.05 V. So it would be a 100/138 division?
3) Does this issue also exist in the ESP8266? I bought some of those boards to play with as well.

I think I'll also rig up a variable resistor with a 3.3 voltage source and check the accuracy. But I was wondering what others are doing and if there is any additional advice.

By the way, if someone is going to redesign the board to include a battery, it seems like they should have made a provision to monitor the voltage/current. But that is a battle for another day. I think the board was about $8, not including the battery.

Thanks,

HH

lbernstone
Posts: 829
Joined: Mon Jul 22, 2019 3:20 pm

Re: Analog Read Accuracy

Postby lbernstone » Mon Nov 18, 2019 5:13 pm

This is a good read, and includes some examples of calibration. https://github.com/espressif/arduino-esp32/issues/1804
SAR is always going to be biased towards the ends of the scale, and the esp32 seems particularly insensitive there.

rodmcm
Posts: 65
Joined: Sat Sep 02, 2017 3:31 am

Re: Analog Read Accuracy

Postby rodmcm » Wed Nov 20, 2019 7:19 pm

Search this on UTUBE
He gives a polynomial to linearise the analogs..
The best series of tutorials on the ESP32 I have come across


Tech Note 069 - Using the ESP32 ADC and some of its more advanced functions

Haldi4803
Posts: 9
Joined: Thu Nov 21, 2019 1:09 am

Re: Analog Read Accuracy

Postby Haldi4803 » Sat Nov 23, 2019 4:55 pm

The start and end of ADC are not entirely accurate :(

Image
https://randomnerdtutorials.com/esp32-a ... duino-ide/

Happy Hippo wrote:
Mon Nov 11, 2019 4:58 am
By the way, if someone is going to redesign the board to include a battery, it seems like they should have made a provision to monitor the voltage/current. But that is a battle for another day. I think the board was about $8, not including the battery.
Lolin did... on the D32 you can read Battery on Pin35
https://youtu.be/yZjpYmWVLh8?t=81

zasilom
Posts: 3
Joined: Sun Dec 01, 2019 5:02 pm

Re: Analog Read Accuracy

Postby zasilom » Sun Dec 01, 2019 6:57 pm

the upper and lower end of analog input never seems to work for me either, i had a similar problem and I was able to get around it by changing my voltage divider to max out at 3v instead of 3.3. you will also have this problem on the low end, so try not to go under .3v,

R1 470ohm and R2 1kohm will give you 2.85v with a 4.2v source.

Haldi4803
Posts: 9
Joined: Thu Nov 21, 2019 1:09 am

Re: Analog Read Accuracy

Postby Haldi4803 » Wed Feb 17, 2021 9:24 pm

This guy seems to have found a way around that.

https://qiita.com/fumi38g/items/bb728a0ee6f9094db4b9

Who is online

Users browsing this forum: No registered users and 122 guests