3

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:

  1. 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.
  2. 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.
  3. I tried adc1_get_raw, which made no difference.
  4. 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).
  5. Using root APIs such as esp_wifi_init & esp_wifi_set_mode & esp_wifi_start instead of Arduino wrappers like WiFi.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.

Signal goes crazy even though there is a 100uF cap at ESP32 Power entrance

enter image description here

#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);
}
1
  • THANKS FOR ALL THOSE COMMENTS AND ELABORATIONS !!! I think I have found the answer HERE
    – AKTanara
    Commented Mar 19, 2022 at 19:44

1 Answer 1

1

I've just had the same problem. I just put all of the WIFI connecting code into a function, read the ADC2 data then called the function to send, ending with WIFI.mode(WIFI_OFF) to shut down the WIFI, read the data then started it all over again. I'm using ESPNOW so don't have to panic about hooking up to my network which would obviously take longer. With ESPNOW, the data is sent regardless and I have it sending every few seconds which is fine for me. I did try putting the connection code into loop, but it kept restarting the board. I've seen plenty of other stuff online about that. Putting it into a function seems to get around that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.