enter image description hereI am trying to read analog values from multiple sensors using both the ESP32-C3 devmodule 02 and the ESP32-C3-WROOM-02 module. In both cases I use the basic Arduino analogRead example code:
#define InPin 3
int x ;
void setup() {
Serial.begin(115200);
}
void loop()
{
delay(100);
x = analogRead(InPin);
Serial.println( x );
delay(100);
}
No matter what pin I set to read the analog value from, it always only reads the value from GPIO0 (ADC1 channel 0.)
My guess is that I have to change the ADC channel that it reads, but I have not been able to find out how.
1 Answer 1
If you look at the esp32c3 data sheet ( https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf ) you will see that the esp32c3 implements only GPIO2, 3, 8, 9, 18, & 19. https://github.com/espressif/esp-idf/blob/v4.3.1/components/driver/include/driver/adc_common.h , shows that the only adc channels available are adc1, channels 2 & 3.
I have used the following code to read analog voltage using esp32c3, Arduino IDE v 1.8.19
#include "driver/adc.h"
adc1_channel_t channel = ADC1_CHANNEL_2;
adc_atten_t atten = ADC_ATTEN_DB_2_5;
void setup() {
Serial.begin(115200);
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(channel, atten);
}
void loop() {
int read_value = adc1_get_raw(channel);
Serial.println(read_value);
delay(1000);
}
#define InPin 3
is a comment so InPin is defaulting to 0, is it not? \$\endgroup\$