Skip to content

Instantly share code, notes, and snippets.

@chaeplin
Created November 28, 2015 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chaeplin/ca1cf67f25135ee7075f to your computer and use it in GitHub Desktop.
Save chaeplin/ca1cf67f25135ee7075f to your computer and use it in GitHub Desktop.
esp8266 analogRead
int sampleI;
int Number_of_Samples;
int sumI;
void setup()
{
Serial.begin(115200);
sampleI = 0;
sumI = 0;
Number_of_Samples = 1000;
}
void loop()
{
long start_adc_now = micros();
for (unsigned int n = 0; n < Number_of_Samples; n++)
{
sampleI = analogRead(A0);
sumI += sampleI;
}
long stop_adc_now = micros();
Serial.print("total delay in adc : ");
Serial.print((stop_adc_now - start_adc_now) / 1000);
Serial.print(" ms ---> each analogRead : ");
Serial.print((stop_adc_now - start_adc_now) / Number_of_Samples );
Serial.print(" micros ---> analogRead : ");
Serial.println(sumI / Number_of_Samples);
sumI = 0;
//delayMicroseconds(10);
delay (1000);
}
@chaeplin
Copy link
Author

total delay in adc : 384 ms ---> each analogRead : 384 micros ---> analogRead : 299
total delay in adc : 40 ms ---> each analogRead : 40 micros ---> analogRead : 305
total delay in adc : 384 ms ---> each analogRead : 384 micros ---> analogRead : 299
total delay in adc : 384 ms ---> each analogRead : 384 micros ---> analogRead : 299
total delay in adc : 40 ms ---> each analogRead : 40 micros ---> analogRead : 305
total delay in adc : 40 ms ---> each analogRead : 40 micros ---> analogRead : 305
total delay in adc : 40 ms ---> each analogRead : 40 micros ---> analogRead : 305
total delay in adc : 384 ms ---> each analogRead : 384 micros ---> analogRead : 299
total delay in adc : 384 ms ---> each analogRead : 384 micros ---> analogRead : 299
total delay in adc : 384 ms ---> each analogRead : 384 micros ---> analogRead : 299
total delay in adc : 384 ms ---> each analogRead : 384 micros ---> analogRead : 299
total delay in adc : 384 ms ---> each analogRead : 384 micros ---> analogRead : 299
total delay in adc : 40 ms ---> each analogRead : 40 micros ---> analogRead : 305
total delay in adc : 40 ms ---> each analogRead : 40 micros ---> analogRead : 305
total delay in adc : 384 ms ---> each analogRead : 384 micros ---> analogRead : 299
total delay in adc : 40 ms ---> each analogRead : 40 micros ---> analogRead : 305

@chaeplin
Copy link
Author

from espressif.com

In station-only mode, ESP8266 will enter light sleep automatically. In light sleep mode, the TX is still running, it will be faster the meature ADC, and because of the low-current in light sleep, it will affect the result of meaturing ADC, but we have tested it, it will be less than 0.05V.

In other mode, ESP8266 will not enter any sleep mode automatically, so the system_adc_read will not be affected by sleep mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment