-
Notifications
You must be signed in to change notification settings - Fork 7.6k
ESP32-C3 cant read all analog values with analogRead() #5502
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 got the same problem too !! so what should I do to solve this issue? |
Same here. I tried to follow the code to see if it was a result of the IDF or if it was something in the Arduino code. I wasn't successful. I wanted to try just the IDF alone to check but have not yet found the time to do that. |
I later figured out a solution. You can use the #include <driver/adc.h> library (dont need to download it) and then use the folowing example code: setup: loop: |
Thanks ! I'll try it 😘 |
Thank you! I was able to make it work with this setup, ESP32 package 2.0.0: // Need to add this include
#include <driver/adc.h>
void setup() {
// ...
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_11);
adc1_config_channel_atten(ADC1_CHANNEL_3, ADC_ATTEN_DB_11);
adc1_config_channel_atten(ADC1_CHANNEL_4, ADC_ATTEN_DB_11);
}
void loop() {
int analogData0 = adc1_get_raw((adc1_channel_t)0);
int analogData3 = adc1_get_raw((adc1_channel_t)3);
int analogData4 = adc1_get_raw((adc1_channel_t)4);
} |
i have found this post at the arduino forum
so the missing peaces are some defines in something like
and
@me-no-dev could you add these? i have currently no idea how |
as my comment suggested.. |
@s-light ADC1 is fully useable. That ADC2 is conflicting with wifi is the same as for the ESP32. And yes it looks the mapping is not done/there. |
i know. my point was: i personally think it should be included. |
Ran today into the same error with unusuable GPIO5 (ADC2_0) after manufacturing my pcbs...
YES!!! |
@s-light const DRAM_ATTR esp32_gpioMux_t esp32_gpioMux[SOC_GPIO_PIN_COUNT]={ |
With this changes it does now work. Thx @mehulsharma21 |
Could something like this be added in next release?
I get this on WLED with arduino-esp32 2.0.2 because
|
@misery There was update to 2.0.2 5 days ago with some C3 updates. I didn't had time to check it in details, see yourself https://github.com/espressif/arduino-esp32/releases/tag/2.0.2 |
Thanks, I already tried 2.0.2 without success. I added the variable in my fork. It compiles fine. But not tested. |
The implementation of the ADC for the ESP32-C3 for the Arduino platform must be fixed to provide the same level of performance as the esp-idf implementation. What works in the IDF version can be seen with VScode and the /examples/peripherals/adc/single_read example code. Both ADC1 and ADC2 work. The returned values are with 1% of the actual values: the following table gives the results: Channels--Voltmeter---Arduino---Arduinodiff---diff%---VScode---VsCodediff---VsCode% Comparing the Arduino esp32-hal-adc.c code with the esp-idf single-read example shows that the calibration functionality for the esp32-C3 is not implemented in the Arduino code. This needs to be fixed. The issues of ADC2 -Adding the pin definitions for the ESP32-c3 as suggested in this post does not seem to change anything. assert failed: esp_efuse_rtc_calib_get_init_code esp_efuse_rtc_calib.c:22 (atten < 4) The first issue is getting the code to work. Eliminating ADc2 should not be considered. My project is a good example of the use of ADC2. It is a WiFi 6 channel ADC with an optional battery. In battery mode the ESP32-C3 must be put in deep sleep to conserve power, turning off the WiFi. After turning off the WiFi, the battery voltage can be measured with ADC2. The second issue is the conflict with the WiFi and how that impacts using ADC2.
There is a difference between the implementations of ADC1 and 2. ADC1 can be read any time by ADC1_get_raw and the results do no need to be qualified. |
it says you are using version 2.0.0? Have you tried with 2.0.2 or master? We have changed the driver to use ESP-IDF |
How do you know which version you have? |
I just tried 2.0.2. No improvement, values have not changed. I believe these 2 statements generate the error listed below:
` |
Anyone got this working?? |
I does work with actual github version. Core 2.0.2 is too old. GPIO refactoring was done after. Since the GPIO refactoring it is working. |
Is this the refactoring you are talking about? ` regards |
No, this one #6259 which completly changes gpio handling. If you use Platformio you can use my build (since Platformio has still no core 2.0.x support)
|
Hello Jason, I will be releasing my ESP32C3 ADC board on Amazon at the end of March. My customers will be using Arduino so I need the Arduino implementation. If someone is working to fix this issue, that is ok. The ADC works fine on VS code so a third development platform is not necessary. I looked at #6259 and it states it was merged with the master 10 days ago. I downloaded the master branch and istalled it. I still get the adc1_config_channel_atten(475) :ADCADC_NUM_1 channel error and a reboot with analogReadMilliVolts(5). PLEASE look at esp32-hal-adc.c all the best |
Does it work for you or not? VS code uses Platformio. I do not get what you mean with 3rd Platform? Edit: You are right calibration is only used for ESP32. So ADC is working without. |
I am on Linux and used PlarformIO with Atom for another project, I forgot it also works with VS code. |
I am disapointed having to resolve these issues myself. I have a temporary workaround to get ADC1 calibration working. I have found this library and modified it for the ESP32C3: https://github.com/madhephaestus/ESP32AnalogRead. |
There is nothing like being persistent. As I worked on this issue I finally realised that I can simply copy Vscode from ESP-IDF into Arduino and it will compile. |
Hello, can you please retest this on v2.0.3-RC1? |
Hello, I retested with V2.03-RC1 and it works. |
Thanks for testing, I'm closing the issue. |
Hello,
I am currently programing an ESP32 C3 devboard which has multiple ADC channels and i would like to read data from 3 different sensors.
The problem is that whenever i use analogRead() with any port it always only shows the measurment on GPIO1.
I have tried it on an ESP32C3-WRoom-02 and also on the ESP32-C3 devmodule 02 with the same result.
I simply connected an external power supply to the pins and when connected to GPIO0 it reads the correct value, but on any other pin it only shows an analog value of 700-900 (i.e. floating pin)
Someone on ESP forum has also reported the same issue
Hardware:
Board: ESP32C3 Dev Module
Core Installation version: 2.0.0. alpha1
IDE name: Arduino IDE
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Windows 10
Description:
When trying to read the analog value of any pin with analogRead(pin); it always reads only the value on GPIO0 (ADC1_CHANNAL0). I can can get any other analog-enabled pin to read the value
Sketch:
//Just a super basic analog read sketch
int sensorPin = 3;
int sensorValue = 0;
void setup() {
// declare the sensorPin as an input doesnt change anything:
Serial.begin(115200);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
delay(100);
}
Debug Messages:
it compiles and uploads perffectly
The text was updated successfully, but these errors were encountered: