Has anyone tried using the analog inputs on the QtPy ESP32-C3?
I'm not having much success and would appreciate an example or some pointers.
The readings on all channels, A0-A3, are not at all accurate and I'm thinking I'm missing some setup code or other configuration info.
From searching around I found this, but it doesn't help.
#include <driver/adc.h>
and under 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);
Arduino and QtPy ESP32-C3 Analog inputs
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Arduino and QtPy ESP32-C3 Analog inputs
Which ESP32 core package are you using?
Based on report using ESP32 package 2.0.0 or later and this example code can work:
https://github.com/espressif/arduino-es ... -947150159
Based on report using ESP32 package 2.0.0 or later and this example code can work:
Code: Select all
// 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);
}
Please be positive and constructive with your questions and comments.