May 13, 2015

Using the ADC on NodeMCU (ESP8266)

The ADC on ESP8266 is poorly documented. It is note even mentioned in the datasheet. I did some measurements with a variable power supply to understand how it works. The experiments are done with the NodeMCU firmware 0.95. File: nodemcu_20150213.bin (link)

What pin is the ADC input?
TOUT on an ESP8266 module.
A0 on a NodeMCU Devkit.

What is the range of the NodeMCU ADC input?
Measured range: 0 - Vdd. (About 3.1 V in this case)
Number of bits: 10 bit (Codes: 0-1024)

Note that the NodeMCU board has a voltage divider on the ADC input. The ESP8266 module it self has 0 - 1.0 V input range.

Readings are done with the command: print(adc.read(0))
0.5 V => 167
1.0 V => 330
1.5 V => 498
2.0 V => 666
2.5 V => 828
3.0 V => 995
3.1 V => 1024 (saturated)

I did a plot of the values and it looks linear.
Do I need to power down WiFi before using the ADC?
There seems that it at least has been a problem in earlier versions of the SDK but I did not have any problems with interference when using WiFi and the ADC at the same time. If you see any issues try to power down the radio with:
wifi.sleeptype(wifi.MODEM_SLEEP)

Can I measure the supply voltage?
It is possible to read the supply voltage. It is done internaly in the chip so thre is no need to connect it to the ADC input. Use the NodeMCU command:
print(node.readvdd33())
for later versions og NodeMCU firmware use:
print(adc.readvdd33())

It returns a value in mV. I got 3123. Be careful to use this call since it is buggy and will cause reboots quite often when called!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.