Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By Bonzo
#80425 Nodemcu is the firmware not the hardware? But the board most people recognise as an Nodemcu when searching the web.

A few threads here recently about analogue input recently and it looks a minefield.
I am also interested in implementing a battery level recorder to email me when the battery starts to get low. Reading about the internal analogue input I thought I would be better off using an external ADC but if my supply voltage gets to low it could damage the external ADC.

I suppose some of the confusion may come as some posts are talking about the Nodemcu data and others the ESP8266?

Reading a lot of threads gives lots of different answers:
The Analogue input can be 1V on older boards and 3.3V on newer boards.
The Nodemcu has an internal voltage divider
The impedance of the voltage divider is not practical
The A0 impedance varies on one site to another from 100K to 2M
The input is 10bit but is actually equal to 7bit
I was told to have quite high value resistors for the voltage divider as it should have less current loss and if the R2 value was to close to the internal impedance the voltage divider would not be working properly.

Does anyone have any useful insights?

I think it would be useful to have the bits of knowledge in one thread.
User avatar
By btidey
#80431 NodeMCU refers to the board. It can come loaded with firmware e.g. lua, but can be flashed with any esp8266 compatible firmware.

The ADC of the esp8266 chip has a nominally a 0 -> 1.0V range. Modules like esp-12f expose this directly so have a 0-1.0V range. The input resistance of the pin does not seem to be specified but going on the leakage current it is high (> 10M).

Some modules like NodeMCU have a built in resistive divider (e.g 220K / 100K) to give a 0 - 3.2V range, although access to the raw ADC pin is also normally available, but the 100K to 0V sets the input resistance.

Whether the range is 0-1 or 0-3.2 is nothing to do with older / newer; it is just a characteristic of the module.

The internal converter does have 10 bits of precision but it is pretty noisy so only about the 7 msb are only good in any one reading. It is possible to average many readings to filter out some of the noise but its never going to be high precision.

The accuracy is also very variable from unit to unit of the order of +/- 5% probably due to the reference voltage. It can be calibrated for a particular unit and then is reasonably stable.

This all means that is only really good for applications where errors of ~1% are tolerable, particularly if it is calibrated. This could include battery level indicators, light sensors etc. For example a LIPO battery will go from about 4.2V full charge down to about 3.3V discharged . If this is divided down to match the range then it would give quite d decent indication of indication of battery state.

The resistors used in any potential divider are a choice depending on the application. Higher values will limit the loading of the source value, lower values may help reduce noise. As the ADC input is >10M then any divider should have source resistance of less than 220K to avoid any effect of the loading by the ADC. For LIPO measurement a 820K / 220K will work pretty well and not impose much extra drain on the battery.

I doubt whether any external ADC is going to be damaged by low battery voltage.
User avatar
By Bonzo
#80434 Thank you very much for the information btidey.

I had a hunch from what I was reading that the ESP8266 was only 1V and the Nodemcu was 3.3V ( 3.2V ) as I could not see any other reason for the voltage divider on the Nodemcu.

Speaking to a different electronics guy at work I need to take the internal divider into account with any external divider. R2 needs to be a lot smaller as it is in parallel with R2 on the Nodemcu. The formular he gave me was:
1/R2 ( my new resistor ) = 1/R2 ( my calculated divider ) + 1/R2 ( Nodemcu divider ) or use a potentiometer and calibrate the system with that!

I read that the problem with an external ADC was the voltage being read could not be more than something like 0.3V higher than the voltage suppling the ADC. My battery could be as you say anything from 4.2V down to 3.3V so it will be higher than the 3.3V I was going to use to power the board. My battery goes through a 3.3V LDO linear regulator.
User avatar
By schufti
#80439
Bonzo wrote:I read that the problem with an external ADC was the voltage being read could not be more than something like 0.3V higher than the voltage suppling the ADC. My battery could be as you say anything from 4.2V down to 3.3V so it will be higher than the 3.3V I was going to use to power the board. My battery goes through a 3.3V LDO linear regulator.

no problem, just use a voltage divider between your battery and the external ADC.
But just for monitoring your battery, the internal ADC should be ok.

btw: the impedance of the internal ADC is not even in the range of 10MOhm, there has been some effort to measure it but I can't find the reference...