read different analog values?

aleskramzar
Posts: 5
Joined: Wed Jul 14, 2021 12:43 pm

read different analog values?

Postby aleskramzar » Wed Aug 04, 2021 1:19 pm

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.
My question is how do i switch the current used ADC channel in arduino?

rbrakhya
Posts: 8
Joined: Sat May 08, 2021 10:09 am

Re: read different analog values?

Postby rbrakhya » Thu Aug 05, 2021 9:05 am

I have posted the same question, but didn't get an answer. Tested with two boards, both only connected to gpio1 regardless of the analogRead setting.

aleskramzar
Posts: 5
Joined: Wed Jul 14, 2021 12:43 pm

Re: read different analog values?

Postby aleskramzar » Mon Aug 09, 2021 7:19 am

I have found a solution after much serching.

Instead of analogRead(pin);
you can use:
adc1_get_raw((adc1_channel_t)ADC1_CHANNEL_xxx); with xxx being the pin with the wanted adc channel.

This is for using ADC channel 1, if you want to use channel 2 (which isnt recomended since apperently it is used by wifi) you just replace it with adc2_get_raw((adc2_channel_t)ADC2_CHANNEL_xxx);

Who is online

Users browsing this forum: Google [Bot] and 62 guests