Arduino and QtPy ESP32-C3 Analog inputs

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
alpierce
 
Posts: 207
Joined: Mon May 13, 2013 2:44 am

Arduino and QtPy ESP32-C3 Analog inputs

Post by alpierce »

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);

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Arduino and QtPy ESP32-C3 Analog inputs

Post by mikeysklar »

Which ESP32 core package are you using?

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);
}
https://github.com/espressif/arduino-es ... -947150159

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”