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

User avatar
By pomelo
#40015 Thank you very much, unfortunately it does not work.
However i assume that when returned 1024 == 1v right?

Code: Select allIn file included from /Users/pablo/Library/Arduino15/packages/esp8266/hardware/esp8266/2.0.0/cores/esp8266/Arduino.h:248:0,
                 from sketch/sketch_jan30b.ino.cpp:1:
/Users/pablo/Documents/Arduino/sketch_jan30b/sketch_jan30b.ino: In function 'void setup()':
/Users/pablo/Library/Arduino15/packages/esp8266/hardware/esp8266/2.0.0/cores/esp8266/Esp.h:74:31: error: expected unqualified-id before string constant
 #define ADC_MODE(mode) extern "C" int __get_adc_mode(void) { return (int) (mode); }
                               ^
/Users/pablo/Documents/Arduino/sketch_jan30b/sketch_jan30b.ino:3:1: note: in expansion of macro 'ADC_MODE'
 ADC_MODE(ADC_TOUT);
 ^
exit status 1
Error compiling.
User avatar
By martinayotte
#40077 You're right about ADC_MODE(), it seems someone broke ESP core recently.
For now simply comment it ! It seems that fortunately, the ADC_TOUT mode is the default at power up, so we are lucky that analogRead(A0); is working.
Yes, the 0-1023 is corresponding to 0-1V !
User avatar
By martinayotte
#40194 @pomelo, I think I figure out the things under the hood about ADC_MODE() ...

According to the doc :

This line has to appear outside of any functions, for instance right after the #include lines of your sketch.


So, it is normal that if we put the ADC_MODE(ADC_TOUT) inside any function, it doesn't compile. It should be placed on the top of the sketch since it is only redefining a function which is probably called by SDK itself while doing the analogRead(A0); and therefore make sur it is the the TOUT that we want. if it is defined as ADC_VCC, then it will be the system 3.3V.

The strange thing I found is that this mechanism is a bit ugly, because if we want to switch between mode, we have to make thing even more ugly :

Code: Select alluint8_t adc_what_I_want = ADC_TOUT;
ADC_MODE(adc_what_I_want);
[...]
loop() {
    [...]
    adc_what_I_want = ADC_TOUT;
    Serial.printf("TOUT = %d", analogRead(A0));
    [...]
    adc_what_I_want = ADC_VCC;
    Serial.printf("VCC = %d", analogRead(A0));
}


Ugly, right ? ;) :ugeek: