Arduino Sketch
1 2 3 4 5 6 7 8 9 10 11 12 13 | // Source: https://github.com/esp8266/Arduino/issues/3800 ADC_MODE(ADC_VCC); void setup() { Serial.begin(115200); } void loop() { int vcc = ESP.getVcc(); Serial.println(vcc); delay(1000); } |
Serial Monitor Output - Running on NodeMCU
Serial Monitor Output - Running on ESP-12 module (not NodeMCU)
The difference in readings is caused by the NodeMCU board has A0 connected to a voltage divider (see below schematic). In order to use getVdd, A0 needs to be floating.
NodeMCU Schematic
Here is a bigger, more clear version of the schematic.
https://raw.githubusercontent.com/nodemcu/nodemcu-devkit/master/Documents/NODEMCU_DEVKIT_SCH.png
Pure ESP-12 Schematic
The A0 pin (ADC) is floating in the schematic below.
Ref.: https://www.esp8266.com/viewtopic.php?f=160&t=14561
References:
vcc = ESP.getVcc() inaccurate in 2.4.0-rc2 version?
https://github.com/esp8266/Arduino/issues/3800
ESP.getVcc() doesn't read exact values
https://github.com/esp8266/Arduino/issues/721
No comments:
Post a Comment