-
Notifications
You must be signed in to change notification settings - Fork 7.6k
ESP32-S2 analogRead function not returning correct value #5691
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
Hello @brentru do you know which GPIO corresponds to A3? I am only seeing A0 to A2 looking at the FunHouse pinout. Some analog inputs share the same ADC module with WiFi and fail to work when WiFi is turned on at the same time. Have a look here. That said, have you tried to turn off WiFi? Have you tried with a different analog input? Thanks |
@felmue - looking at the board variant (https://github.com/espressif/arduino-esp32/blob/master/variants/adafruit_funhouse_esp32s2/pins_arduino.h#L53), it'd be GPIO18.
We've had success reading the analog input using the same code, prior to the v2.0.0 BSP update.
We've also tried reading the value of a pot. with analog pin A0.
I'm not sure how to turn off the ESP32's WiFi via the Arduino IDE.. The sketch attached with the issue doesn't perform a network setup. |
Hello @brentru understood, afaik some WiFi stuff has been changed in v2.0.0 and now it can interfere with reading analog inputs. Well, A0 and A3 are both using the same ADC module (ADC2) as WiFi so I'd expect it to fail as well. Could you try A1 or A2? If in the past you've ran a sketch using WiFi there is a chance it is still running (in the background) even though your current sketch isn't using WiFi. You can try to stop WiFi using this: Thanks |
@felmue WiFi and ADC is only a problem on the ESP32 and not ESP32-S2/ESP32-C3 chips. |
According to Adafruit FunHouse schematic A3 (GPIO18) is connected to a light sensor output pin with a 10k pull-down resistor. Based on this, it would make sense that you are receiving a zero value for analogRead(). |
Hello @atanisoft but the light sensor should be able to pull it above 0 when it catches some light, wouldn't it? And according to @brentru it worked with an earlier version of Arduino, e.g. before v2.0.0. Thanks |
Depends on the sensor, it also couldn't have worked in v1.0.x as the S2 wasn't supported in that version. Since I don't have the board I can't do any testing. |
@felmue @atanisoft do you have other ESP32-S2 boards that you can test analog input with? |
@ladyada I haven't tested ADC on the S2 in a while but last I checked it was working with the Saola and WROVER modules that I have. There have also been a few issues filed about ADC attenuation defaults not working correctly and the ADC returning 4095 (max value). But in this case it is returning zero which indicates that either the wrong pin is being read or it is remaining at GND. |
@atanisoft ok - did you try analog input with 2.0.0? if not, is there someone who can try to replicate this bug so it can be assigned? |
Yes, i can confirm there is at least 1 bug. By default it is setup 12 bit width, but:
and i am getting this error:
EDIT |
Hello guys I ran some tests with an ESP32-S2-Kaluga-1 board and can confirm that the issue seems to be related to the analog resolution. The only resolution working for GPIOs using ADC2 seems to be 13. Unfortunately
However I was able to read the analog value from GPIO18 with the following code. Inspired by the ESP-IDF adc2 example.
Thanks |
Resolution is 13 bits, but value to pas is 4:
|
Hello @chegewara thank you for the information. According to the description That said I actually tried to pass both values (13 and 4) to Thanks |
I tested by myself, before ive been told about this issue already opened: All i had to do is to change this value to 4: EDIT and maybe set pin mode |
Hello @chegewara yes, I concur, modifying the Thanks |
hihi @me-no-dev do you need a PR to fix? |
@ladyada it will be greatly appreciated and will save some time :) |
@chegewara @felmue can either of you submit a PR for the one-line change you made so @me-no-dev can merge the fix in |
@ladyada There is few espressif employes working on arduino-esp32 and i believe they can do such simple PR. |
Since this seems to be related to #5658 it likely can be closed as duplicate and then use that issue instead for tracking. It has a code diff in it but it will break ESP32-C3, so that will need to be covered in any PR for this. |
@me-no-dev hiya there are now multiple PRs! |
as there is a PR which didn't sync. I'm closing this manually, if needed you can reopen this. Thanks! |
Hardware:
Board: Adafruit FunHouse ESP32-S2
Core Installation version: 2.0.0
IDE name: Arduino IDE
Flash Frequency: 80Mhz
PSRAM enabled: Yes
Upload Speed: 115200
Computer OS: macOS and Ubuntu
Description:
Calls to Arduino's
analogRead
(https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/) function are not working on BSP v2.0.0. It seems to always return a value of0
, instead of the correct value from the ADC. This functionality was working prior to 2.0.0.Sketch: (leave the backquotes for code formatting)
The text was updated successfully, but these errors were encountered: