Arduino icon indicating copy to clipboard operation
Arduino copied to clipboard

ESP.getVcc() doesn't read exact values

Open luciancerbu opened this issue 11 years ago • 23 comments

So I have a wireless node sensor nodeMCU v1.0 with ESP12-E on it (http://www.aliexpress.com/item/2PCS-V3-NodeMcu-Lua-WIFI-development-board-based-ESP8266-LoLin-with-newest-firmware/32368521069.html). The problem is with the received values from the ADC, for power supply voltage I get the following : 3.739 3.702 3.708 3.711 3.755 3.721 3.761 3.764 3.732 3.734 3.737 3.741 3.744 3.745 3.753 3.793 all these values were from the same source, 1minute delay between them with deep sleep mode in that minute. It there any hardware thing I should do? to solder something on A0 pin?

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

luciancerbu avatar Aug 26 '15 08:08 luciancerbu

I doubt the accuracy spec for the part (if it has one) is better than 1%. Let's assume the "actual" voltage is 3.750. The readings you are seeing are +0.043 to -0.048. Let's say 0.05. Now 0.05/3.75 is 1.33%. Bottom line, you should only be looking at one digit past the radix (decimal) point, the rest is noise. If you want, you can take several readings at the same time and average them and perhaps get a little more information/stable number.

Frogmore42 avatar Sep 03 '15 00:09 Frogmore42

I get with my modules (ESP8266-01 and ESP826612) the same trash. The voltage is 3.3V but the output from the getVcc() function is every time 3.7V. This is much more than 1% deviation (round about 10%). Maybe there is a systematic error?

Have anyone the same problem?

Greets Kalle

pgollor avatar Sep 10 '15 08:09 pgollor

well, after some very poor results I decided to supply my esp directly from a li-ion battery.

for 4.05 volts on baterry it gives me from ADC value 3854

for me it works fine.

luciancerbu avatar Sep 10 '15 09:09 luciancerbu

Also i use vcc and adc , but my mac arrive to max 1000ma on usb and is enough . My advice is use a dc power supply when you use this type of sensor or many sensor or lcd .

On 10 set 2015, at 11:04, Luci [email protected] wrote:

well, after some very poor results I decided to supply my esp directly from a li-ion battery.

for 4.05 volts on baterry it gives me from ADC value 3854

for me it works fine.

— Reply to this email directly or view it on GitHub https://github.com/esp8266/Arduino/issues/721#issuecomment-139176240.

asetyde avatar Sep 10 '15 10:09 asetyde

I try different external power supplies and the best result is:

getVcc() Multimeter difference
3.5 V 3.3V 6%

With 6% difference it is not usable.

pgollor avatar Sep 10 '15 12:09 pgollor

I had problems getting reliable AD readings too. I had multiple devices available so I discovered that each esp gives different readings. Some ESPs are almost accurate but in general the value I was reading was always higher then when measured with a scope of multimeter.

A good thing was that at least each individual ESP gives consistent reading. So my solution was to apply a voltage that is known (in my case 4.2V of a full lipo battery) to calibrate each esp. With calibration it was quite accurate.

wizard23 avatar Apr 06 '16 17:04 wizard23

//1.- The range of operating voltage of ESP8266 is 1.8V~3.6V //2.- getVcc function (system_get_vdd33): is only available when TOUT pin17 is suspended (floating), this function measure the power voltage of VDD3P3 pin 3 and 4 (in the ESP8266 chip) //3.- RF must be enabled.

ADC_MODE(ADC_VCC);

float voltaje=0.00f;
voltaje = ESP.getVcc(); Serial.print(voltaje/1024.00f); Serial.println(" V");

:+1: image2 Image from: ESP8266 SDK Programming guide

lrmoreno007 avatar Apr 06 '16 19:04 lrmoreno007

Hi,

I use NodeMcu v2, and I have set:

  • [x] wifi client activated (RF enabled?)
  • [x] ADC_MODE(ADC_VCC); added
  • [x] ADC pin of NodeMcu is floating (nothing connected to it) -> is it equal to suspended TOUT pin?

I got this with my nodemcu v2:

2.68 V
2.68 V
2.68 V
2.68 V
2.68 V
2.68 V
2.68 V
2.68 V
2.68 V

Any thought?

I powered it from USB port, and measure it with my DMM, the voltage between 3.3v pin and GND is 3.29 volt. I'm on Arduino IDE 1.6.9 and esp8266 core version 2.3.0

minida28 avatar Feb 25 '17 10:02 minida28

I got the same values as minida28 for 3.3V 2716 2718 2718 2734 2718 2717 2718 2718 2736 2736 2736 2718

And values like this for 2.8V 2240 2328 2236 2232 2235 2320

jindrichsirucek avatar Mar 09 '17 22:03 jindrichsirucek

@jindrichsirucek Values reported by ESP are correct, you are probably not using a capacitor (close to VCC-GND). The voltage drop can be heavy without it. I just tried bare ESP-12E without capacitor: 3.3V -> 2.68V (similar values to yours). With 470uF -> 3.0V. 1000uF (or even more) will do the job.

r1me avatar Mar 14 '17 16:03 r1me

Ok thanks for the tip, Ill check that out.. I have Lolin nodemcu V3 board.. I think there is some capacitor - but I will try it.. But I think there is actuallly no reason to have this serious voltage drop when esp is not using a wifi..

jindrichsirucek avatar Mar 14 '17 17:03 jindrichsirucek

The caps does not solve the problem in this case. On nodemcu v3 and similar boards TOUT is connected to a 220k/100k divider, by datasheet vcc is only available when TOUT pin17 is suspended (floating), but that is not the case, on those board it is connected to GND by a 100k resistor.

davidegironi avatar Apr 25 '17 10:04 davidegironi

Yes @davidegironi you are right - its not about capacitor its because of voltage divider at nodemcu board.. thx..

jindrichsirucek avatar Apr 25 '17 11:04 jindrichsirucek

So to solve the problem, we have to remove the voltage divider resistors, any one have tried it? :)

~~Also I just know that Wemos Mini R1 TOUT pin is not connected to voltage divider, according to this schematic.~~

Edit: Sorry my mistake, I did not see there IS a voltage divider on the right of the schematic :)

minida28 avatar Apr 25 '17 11:04 minida28

With the voltage divider removed from one of my nodemcu v3 board it's 3.07V, caps once again does not make any difference. It's not yet like the plain ESP12E, cause ADC does not work properly, it works like this issue here: https://github.com/esp8266/Arduino/issues/3168 I don't get why on that board ADC works like this.

davidegironi avatar Apr 25 '17 12:04 davidegironi

@davidegironi Thanks for your test result, but what voltage did you get before you remove the voltage divider? I bet it should be lower with voltage divider in place, well,, at least according to jindrichsirucek and my test result above.

minida28 avatar Apr 25 '17 13:04 minida28

@minida28 Almost 2.7V, depending on the board tested. The voltage divider is 100k to GND, 220k from the A0 nodumcu PIN.

davidegironi avatar Apr 25 '17 13:04 davidegironi

Hello. I own LoLin module. If A0 is not connected ESP.getVcc() returns 2720 (mV). Vcc is 3.290V measured with multimeter. Difference is probably from interference on input resistor divider 220k/100k with internal divider. This is eliminating if just connecting A0 with Vcc (i use green dupont wire for this test video) and then ESP.getVcc() returns 3290 - exact as measured. Please anyone test with different ESP8266 module and/or different Vcc. For me ESP.getVcc() works fine. I use ESP8266 core v2.3.0 and Arduino IDE 1.6.11.

(I apologise for my english. I use Google translate.)

https://www.youtube.com/watch?v=diQNNNFjH1Q

flashko avatar Jul 29 '17 08:07 flashko

For WEMOS D1: The A0 pin is not directly connected to TOUT. If you connect 3.3V to A0 of the WEMOS module it will be divided so the following is true:

Solution:

  1. in you code do
ADC_MODE(ADC_VCC);
void loop() {
  // most exact output
  uint16_t v = ESP.getVcc();
  float_t v_cal = ((float)v/1024.0f);
  char v_str[10];
  dtostrf(v_cal, 5, 3, v_str);
  sprintf(v_str,"%s V", v_str);
  Serial.println(v_str);
}

or shorter but not that exact ("3.299 V" (above code) turns into "3.30" (this code))

  Serial.println((float)ESP.getVcc()/1024.0);
  1. connect A0 with VCC(3.3V)

Now you can read "3.300 V" on the console.

IMPORTANT: I read through the documentation of Expressifs ESP8266: Neither do I have to nor may I connect TOUT (for the Mode ADC_VCC) to 3.3V nor may we exceed 1.0V on the TOUT pin of ESP8266! So the above works with a WEMOS module and I did some tests with lower voltages and batteries, too.

DO THIS ON YOUR OWN RISC! It may damage your ESP8266.

Please Note: A0 and TOUT are different pins! I think some here mixed that up.

fah avatar Aug 26 '17 17:08 fah

Yesterday I discovered strange phenomenon. When measuring Vcc after 20 seconds of operation, it measures exact values. However, if I do the measurement few miliseconds after waking from deep sleep and connecting to wifi, I get erratic values with differences of -0.4V. Looks like there is some slowly charging capacitor on the Vcc pin or something. Needless to say, the Vcc is always 3V.

sanchosk avatar Sep 03 '17 07:09 sanchosk