Skip to content

Conflict Between Wifi & analogRead()? #102

@kherNI

Description

@kherNI

Is anyone seeing a conflict with analogRead() values when #include <WiFi.h> is included in a sketch? analogRead works great without WiFi.h included; however, if WiFi.h is included then the analogRead values returned are all maxed out (4096 values). Note I've tested on pins 12, 14, 26 & 27.

Activity

palomarcoder

palomarcoder commented on Jan 2, 2017

@palomarcoder

I found a note here that may be relevant: https://www.espressif.com/sites/default/files/documentation/esp32_hardware_design_guidelines_en.pdf

Pin1, Pin43 and Pin46 are the analog power supply pins. Pin3 and Pin4 are the power supply pins for the power amplifiers. It should be noted that the sudden increase in current draw, when ESP32 is in transmission mode, may cause a power rail collapse. Therefore, it is highly recommended to add another 0603 10 uF capacitor to the power trace, which can work in conjunction with the 0402 0.1 uF capacitor.

JeroenVanOort

JeroenVanOort commented on Jan 8, 2017

@JeroenVanOort

I've been having trouble with this as well. After a lot of trial and error I have found out that analogRead will work on some pins while using WiFi, 32 and 36 are examples of those pins. I hope this helps when trying to find out why this happens.

nissimzur

nissimzur commented on Apr 19, 2017

@nissimzur

Hi
It seems the ESP32 pin 32 is been used as SDO to flash. Are you sure you can use is as analogRead input?
Please call my Skype nissim.test

igrr

igrr commented on Apr 19, 2017

@igrr
Member

This happens because ADC2 pins can not be used when WiFi is used.

On the other hand, ADC1 pins can be used even when WiFi is enabled.

hkotkanen

hkotkanen commented on May 13, 2017

@hkotkanen

@JeroenVanOort thank you kindly, switched to a pin you indicated and got mine working.

@igrr many thanks for the information! Your statement is so casual and matter-of-fact, but this thread seems to be then only place that documents this ...feature. Was I supposed to have found it out from another source?

CarlosGS

CarlosGS commented on Sep 20, 2017

@CarlosGS

A few months ago I got around this issue by periodically soft-restarting the ESP32 to measure from ADC2; then turning on wifi to send the data.

Unfortunately this has been broken in latter updates, right now if you issue esp.restart() after turning on wifi, the ADC2 no longer works. Now it is needed to physically disconnect power.

Any thoughts on why esp.restart() doesn't restore all radio registers to their default state?

me-no-dev

me-no-dev commented on Sep 22, 2017

@me-no-dev
Member

There is a fix coming for ADC2 and WiFi soon :)

pieman64

pieman64 commented on Oct 16, 2017

@pieman64

@me-no-dev any news on the ADC2 fix?

JulienHai

JulienHai commented on Dec 6, 2017

@JulienHai

any news? when will adc2 be fixed?

palomarcoder

palomarcoder commented on Dec 27, 2017

@palomarcoder

Any estimated time? I was really hoping to use this in a project over the holiday.

88 remaining items

CarlosGS

CarlosGS commented on Jul 21, 2021

@CarlosGS

Would you be so kind to provide more details? (i.e. is our only alternative to keep using 1.0.3/1.0.4?)

Context: I would like to re-use many boards (update the software) instead of dropping them in the bin.

txf-

txf- commented on Jul 22, 2021

@txf-

Would the workaround still work with the latest SDK? I have a project that uses the workaround, which works well for my purposes, but would it break?

me-no-dev

me-no-dev commented on Jul 22, 2021

@me-no-dev
Member

why would many devices stop working? Did you design your boards based on that message from 4 years ago?

palomarcoder

palomarcoder commented on Jul 22, 2021

@palomarcoder

I certainly did. Why is that unreasonable? The esp32 was the chip of dreams - 18 ADC, built in wifi, and fast. I designed 3 projects around it. I assumed the features would work together, and I assumed the bugs would be fixed. I appreciate the community support, but what company releases a major SOC and assumes the community will find workarounds to all the problems? The boards still sit languishing on the bench. I'll end up throwing it all away and waiting for esp64, or maybe some day have time to redesign the projects for multiple esp32s.

Tobbera

Tobbera commented on Jan 8, 2022

@Tobbera

I can confirm that this is working as a workaround.

// Initiate Wifi with ADC2 on ESP32 workaround bellow:
#include "soc/sens_reg.h"    // needed for manipulating ADC2 control register
uint32_t adc_register;
uint32_t wifi_register;
// End initiation of Wifi with ADC2 on ESP32 workaround.

setup:
Serial.begin(115200);
  adc_register = READ_PERI_REG(SENS_SAR_READ_CTRL2_REG); // Wifi with ADC2 on ESP32 workaround.
*** Connect WiFi / Bluetooth stuff here ***
  wifi_register = READ_PERI_REG(SENS_SAR_READ_CTRL2_REG); // Wifi with ADC2 on ESP32 workaround.

loop:
  WRITE_PERI_REG(SENS_SAR_READ_CTRL2_REG, adc_register); // Wifi with ADC2 on ESP32 workaround.
  SET_PERI_REG_MASK(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_DATA_INV);// Wifi with ADC2 on ESP32 workaround.
*** Analog read stuff here***
  WRITE_PERI_REG(SENS_SAR_READ_CTRL2_REG, wifi_register); // Wifi with ADC2 on ESP32 workaround.

BUT, its broken in the newer version of ESP32 in arduino. This works on 1.0.3 at the moment. I cant understand why they took it away.

Tobbera

Tobbera commented on Jan 28, 2022

@Tobbera

Another follow up on this:

When using the workaround above the ADC reading reports approx 21mV higher value at 2500 mV compared to not running WiFi at all.

EDIT: And this offset seem to affect BOTH ADC channels, not only the ADC channel that is affected by the this issue. The ESP32 MCU is puzzling me more and more....

cyberman54

cyberman54 commented on Mar 2, 2022

@cyberman54
Contributor

@Tobbera i can confirm the ~21mV Diff, for BOTH adc channels.

janioanselmo

janioanselmo commented on May 6, 2022

@janioanselmo

Tobbera

Hello, I confirm your information! I've been migrating my project from version 1.0.4 to version 2.0.2 for a few weeks and unfortunately, without success so far. With information from Mr. @Tobbera we have had success up to v 1.0.4. For higher versions, I still can't get Wifi + analogRead() to work;

janioanselmo

janioanselmo commented on May 6, 2022

@janioanselmo

@Tobbera, another follow up on this:
I just did tests on the new version 2.0.3 and apparently the same thing, still doesn't work (Wifi + AnalogRead).

pdsmart

pdsmart commented on May 11, 2022

@pdsmart

I can add another issue I've been tracking the last few days, hi-speed digital signals on ADC2 inputs (configured as digital inputs) prevents WiFi Station from establishing a connection. WiFi Access Point has no such issues.

The only solution I have come up with at the moment is to temporarily set ADC2 ports to output (the design uses limiting resistors so this is possible), make a WiFi Station connect with router then reset ADC2 ports to input. Once the Station has a session with a router there are no further issues. (albeit I find enabling the WiFi causes false interrupts to trigger on a neighbouring ESP32 on IO33!!). Not strictly capturing analogue as mentioned in the OP post but all on the same theme, an issue regarding WiFi and ADC2.

I'm using IDF v4.4 with Arduino compatibility installed. SoC is an ESP32-S AI Thinker WROOM.

svdrummer

svdrummer commented on Jan 15, 2023

@svdrummer

Are these all Arduino wrapper issues or silicon issues?

NuclearManD

NuclearManD commented on Jan 19, 2023

@NuclearManD

I'm pretty sure they're silicon issues @svdrummer. Hopefully someone can correct me if I'm wrong.

added a commit that references this issue on Oct 22, 2024
74610a1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @beegee-tokyo@pierreh@sakurai-youhei@tablatronix@davidvilla

      Issue actions

        Conflict Between Wifi & analogRead()? · Issue #102 · espressif/arduino-esp32