-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Conflict Between Wifi & analogRead()? #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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. |
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. |
Hi |
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. |
@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? |
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? |
There is a fix coming for ADC2 and WiFi soon :) |
@me-no-dev any news on the ADC2 fix? |
any news? when will adc2 be fixed? |
Any estimated time? I was really hoping to use this in a project over the holiday. |
Hi, Thanks, |
GPIO33 should be ok to use, it is connected to ADC1. Check Wiki. Extract of my code to read an analog value from a LDR: int ldrPin = 33;
void setup() {
pinMode(ldrPin,INPUT);
adcAttachPin(ldrPin);
analogReadResolution(11);
analogSetAttenuation(ADC_6db);
}
void loop() {
Serial.println(analogRead(ldrPin));
delay(2000);
} |
Thank you @beegee-tokyo. I will try that. I was not using "adcAttachPin(ldrPin);", probably that is why I was unable to read the correct values. |
@beegee-tokyo A quick question. Do I have to use any libraries or header files to include analogSetAttenuation(ADC_6db); and adcAttachPin(ldrPin);? Thanks, |
You might need to include esp32-hal-adc.h |
@beegee-tokyo I am not getting stable values. They change and they don't make sense. Please check my code, int pin =33; void setup() { void loop() { } Am I doing something wrong? |
I tried your code and found no problems. Output:
Did you measure the voltage on GPIO19? Is it changing from 3.3V to 0V? |
"There is a fix coming for ADC2 and WiFi soon :)" any progress on this? we would need more than 6 analog inputs in our project. there is any workaround for this? thanks! |
Hi all! Any update on this? is there any fix already for ADC2 and WiFi support? Thanks in advance! |
I've tried turning off WIFI and then doing analogRead(A0), but it still read the wrong value. Why doesn't turning off WIFI work ? Is there something more to do than WiFi.mode(WIFI_OFF); ? |
Any progress on this issue? I am trying to use the pulse counter function along with Bluetooth but the counter hangs when BT starts up. I suspect the use of the same power rail is causing my problems too. |
@me-no-dev any news on the ADC2 and Wifi fix? |
For the record, resetting registers SENS_SAR_START_FORCE_REG and SENS_SAR_READ_CTRL2_REG to the old values they had before WiFi was turned seem to be a work around for this issue. And will allow you to use ADC2 again after you stop and deinitialize WiFI. An algorithm here would be something like: |
I forgot to include the SENS_SAR_MEAS_START2_REG register. This one is important too. |
For anyone struggling with the saving and restoring of register states method, I had the code working perfectly on my computer but then reinstalled windows and the ESP32 once again no longer worked with ADC2 readings. Turns out I'd installed an updated version of the esp32 boards within the Arduino IDE |
We won't fix this. We will implement diagnostic message in 2.0.0. |
I also tried the saving and restoring of register states method and it works on esp32 version 1.0.3. Is there any bug on 1.0.6? |
I never got it to do anything , ill test again one day and update what I find |
I can't get this to work on an esp32 cam (pin 14) @edstoica solution relies on "esp32-hal-adc.h" which doesn't seem to be available in the Arduino IDE? |
@me-no-dev we can use this Documentation link in Diagnostic message: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/adc.html#adc-limitations |
@VojtechBartoska done :) |
i don't understand. is it done improving the error message? what about the workaround proposed in this thread and the message (written in 2017) "There is a fix coming for ADC2 and WiFi soon :)"? |
@fkoteam unfortunately a stable solution was not found. That is why we resorted to better error message. |
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. |
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? |
why would many devices stop working? Did you design your boards based on that message from 4 years ago? |
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. |
I can confirm that this is working as a 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. |
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.... |
@Tobbera i can confirm the ~21mV Diff, for BOTH adc channels. |
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; |
@Tobbera, another follow up on this: |
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. |
Are these all Arduino wrapper issues or silicon issues? |
I'm pretty sure they're silicon issues @svdrummer. Hopefully someone can correct me if I'm wrong. |
Adding QT2040 Trinkey.
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.
The text was updated successfully, but these errors were encountered: