General area when it fits no where else

Moderator: Mmiscool

User avatar
By NicoF
#69175 Hi
I need to monitor the battery voltage with the on chip ADC , pin 6 on the ESP8266.
The basic command value = io(ai) works fine to get a value of the voltage on the pin .

From the datasheet the ADC can be connected to pin 3/4 and in that case it will provide the value of the chip supply voltage , else the analog value will be from outside .

Is there a way to switch between the 2 options , I notice it is part of the startup sequence so not possible while program is running i would think.

The other problem is the reference voltage / value that is used to get the ADC value.
In a quick test with the supply voltage at 3.315V I did a few readings :
1.06v 1023 count any higher input and it stay at 1024
1.0 v 966
0.9v 865
0.8v 772
0.7v 675
0.6v 579
0.5v 481
0.4v 387
0.3v 292
0.2v 195
0.1v 95
0.05v 49

The above readings change if the supply voltage changes.
The chip datasheet also mention a 2.5V default value that can be selected for RF Calibration and optimization . How to select it , will it help ?

I do not want to use an external adc due to space problems.

Any ideas how to get stable adc readings ?
User avatar
By Electroguard
#69617
Any ideas how to get stable adc readings ?

Only just noticed your question...

You haven't mentioned some crucial info, so I'll have to make some assumptions:
Presumably the battery voltage you wish to measure is the supply to the esp device, and presumably the battery is supplying the esp 3.3v via a stabiliser... if not, it should be.

Assuming the battery is suitable for supplying the esp, the voltage stabiliser input may vary, but the stabiliser output should remain stable... especially if it has a 100uF to 1000uF reservoir cap (bigger is better).
Likewise you can put a 0.1uF smoothing cap from ADC to ground to stop it 'fluttering'.
The adc pin should give max 1024 reading at 1v - that makes it very easy for calculating voltage divider resistance values... if you assume a 1K resistor to drop that 'lower' 1v from ADC to ground, then you can assume 1K times the excess battery voltage that needs dropping across the 'upper' supply resistor - eg: a 1v supply needs no resistor (0K), 5v needs 4K to drop 4v, 9v needs 8K to drop 8v.

In practice it's not necessary for the ADC to show max reading at max volts, so you can simply use a resister that equates to the supply voltage x 1K, which will give sensible over-voltage readings when being charged.
Eg: use 4.7K for a Lipo battery, and 15K for a 12v vehicle (which can charge at over 14v).
User avatar
By rudy
#69618 The ESP8266 ADC have some significant noise issues. I Averaging doesn't help because the noise is not symmetrical. I consider the ADC mostly useless for anything other than very crude measurements.
User avatar
By Barnabybear
#69637
rudy wrote:The ESP8266 ADC have some significant noise issues. I Averaging doesn't help because the noise is not symmetrical. I consider the ADC mostly useless for anything other than very crude measurements.


Hi, I found this made a big difference:
Code: Select allextern "C" {
#include <user_interface.h>
}

  wifi_set_sleep_type(NONE_SLEEP_T);