B4R Question ESP8266 How to read the ADC value?

Yasen

New Member
Licensed User
Please help. I am trying to read the Analog value from AD0 of the ESP8266.
So far not working

must be?
ADC.Initialize(6,ADC.MODE_INPUT)
test=ADC.AnalogRead

Tryed ESP.getVcc - gives strange result (native)
Tryed system_adc_read() (native)
 

janderkan

Well-Known Member
Licensed User
Longtime User
To get the correct value each ESP must be calibrated and some ESP dont even have the A0 connected.
I have stopped using this and use an external adc converter.
 
Upvote 0

Yasen

New Member
Licensed User
test defined as UInt

ADC.Initialize(ADC.A0, ADC.MODE_INPUT)
test=ADC.AnalogRead
log(test)

gives 65535 (-1)

#if C
ADC_MODE(ADC_VCC);
void GetVCC (B4R::Object* o) {
b4r_main::_vccx = system_adc_read();
}
#End if
vccx reads the same 65535

but

#if C
ADC_MODE(ADC_VCC);
void GetVCC (B4R::Object* o) {
b4r_main::_vcc = ESP.getVcc();
}
#End if
vcc reads different values accoreding to the A0 input - and the results are 0<vcc<3040
What I am doing wrong?

I am usind this https://github.com/nodemcu/nodemcu-devkit-v1.0 board
I know that A0 connected to a resistor devider - and that the range of the input of the Esp8266 is from 0V to 1V and that the development board input range if from 0V to 3.3V... But my question is what I am doing wrong as a software.
 
Upvote 0

Yasen

New Member
Licensed User
I 've found my problem:

After using ADC_MODE(ADC_VCC); the ESP8266 will meusre the supply voltage internaly and the A0 will give annormal readings.

I have to use
ADC_MODE(ADC_TOUT);

And then every thing worked fine:

The native
#if C
ADC_MODE(ADC_TOUT);
void GetVCC (B4R::Object* o) {
b4r_main::_vccx = system_adc_read();
}
#End if

and after using ADC_MODE(ADC_TOUT) for one time - the B4R

ADC.AnalogRead
started to work correctly too

Thank you Erel for this link: https://www.b4x.com/android/forum/t...atus-battery-and-recharge.104730/#post-656259
 
Upvote 0
Top