I'm using the ESP32's ADC1 (not ADC2, which conflicts with WiFi functionality) to capture some analog data received at IO36 (an ADC1 port).
As soon as I uncomment the WiFi.mode(WIFI_AP_STA)
line (even when the WiFi.begin()
line is still commented out), analog readings go crazy!
Some side notes:
- The hardware that processes the input signal to make it suitable for the ESP32 analog input uses the same power source as the ESP32 module.
- A 100 μF SMD capacitor is connected to the source line of the ESP32 module just beside it to lessen the impact of its power consumption ripples on other devices.
- I tried
adc1_get_raw
, which made no difference. - I tried this code on another ESP32 module; it also showed a huge difference in ADC1 readings before and after uncommenting
WiFi.mode(WIFI_AP_STA)
. - Using root APIs such as
esp_wifi_init
&esp_wifi_set_mode
&esp_wifi_start
instead of Arduino wrappers likeWiFi.mode
didn't help.
New clue: Apparently the issue is with the WiFi Access Point mode (i.e. WIFI_AP), because setting Wi-Fi to Station mode (i.e. WIFI_STA) doesn't cause this issue.
In general anything related to WiFi causes the ADC to get unstable. No matter which ESP32 board you use, you could simply serial plot any ADC1 channel before and after the WiFi initialization command, even with floating ADC1 pins you can see the difference.
#include <WiFi.h>
float R = 0;
void setup() {
Serial.begin(500000);
// WiFi.mode(WIFI_AP_STA);
// uncommenting this line analogread goes crazy, even while the following line is still commented out
// WiFi.begin();
analogSetAttenuation(ADC_0db);
}
void loop() {
R = analogRead(36);
Serial.println(R/12.21);
}