ESP32 ADC not working

Any bugs you encounter with Flowcode should be discussed here.
simisv
Posts: 6
http://meble-kuchenne.info.pl
Joined: Wed Oct 19, 2022 7:54 am
Been thanked: 1 time

Flowcode v10 ESP32 ADC not working

Post by simisv »

Hi
I don't know if this is a bug or missing something . Tried today to use 8 ADC inputs in a new project and only 4 are working , the other ones ( GPIO-04 / 25 / 26 / 27 / 14 / 12 / 13 / 15 / 02 ) are resetting the ESP32 in an infinite loop , start -run program until reaches ADC (for example ADC GPIO-04) -then reset and is starting again . GPIO-33 / 32 / 35 / 34 are working fine . Tested with ESP32 wroom32 and ESP32S .
I hade the same problem in Arduino when by mistake I set up an input pin as output .
Don't know how to solve this .
I hope there is a solution for this .
Thank you guys
Attachments
ESP32S_ADC_Fail_and_LCD_SPI.fcfx
(20.33 KiB) Downloaded 11 times

mnfisher
Valued Contributor
Posts: 1514
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 725 times

Re: ESP32 ADC not working

Post by mnfisher »

With esp32 - it's always worth opening a COM port using PuTTY or other terminal program and checking the output - there is often a clue as to what is going wrong.

Are you getting something like this (an invalid ADC channel)
E (7482) adc_oneshot: adc_oneshot_config_channel(150): invalid channel
ESP_ERROR_CHECK failed: esp_err_t 0x102 (ESP_ERR_INVALID_ARG) at 0x400d6a5d
file: "C:\ProgramData\MatrixTSL\FlowcodeV10\CAL\ESP\ESP_CAL_ADC.c" line 109
func: FC_CAL_ADC_Enable_1
expression: adc_oneshot_config_channel(adc_handle, Channel, &config)

abort() was called at PC 0x400879db on core 0
or something like:
E (86032) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
E (86032) task_wdt: - IDLE0 (CPU 0)
E (86032) task_wdt: Tasks currently running:
E (86032) task_wdt: CPU 0: main
E (86032) task_wdt: CPU 1: IDLE1
E (86032) task_wdt: Print CPU 0 (current core) backtrace


You'll need to add a delay to the loop in main (10ms or more) to avoid WDT errors.

Martin

simisv
Posts: 6
Joined: Wed Oct 19, 2022 7:54 am
Been thanked: 1 time

Re: ESP32 ADC not working

Post by simisv »

Hi Martin

Thank you for your reply .
Makes no difference if I use a delay .
The error from ESP is this :
[0;31mE (7973) adc_oneshot: adc_oneshot_config_channel(150): invalid channel[0m
ESP_ERROR_CHECK failed: esp_err_t 0x102 (ESP_ERR_INVALID_ARG) at 0x400d69fd
file: "C:\ProgramData\MatrixTSL\FlowcodeV10\CAL\ESP\ESP_CAL_ADC.c" line 109
func: FC_CAL_ADC_Enable_1
expression: adc_oneshot_config_channel(adc_handle, Channel, &config)


Definitely is wrong setup on ADC pins and is over my power to fix it .
Thanks

Simi
Attachments
terminal_log.txt
(7.53 KiB) Downloaded 8 times
err.txt
(334 Bytes) Downloaded 9 times
compiler_msg.txt
(16.25 KiB) Downloaded 10 times

mnfisher
Valued Contributor
Posts: 1514
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 725 times

Re: ESP32 ADC not working

Post by mnfisher »

Something not right - I can't compile the code at all today (errors in SPI) - so stripped the display out.

However - at a first look at the ESP_CAL_ADC.c file:
#warning "ADC channels 32 and greater require the use of ADC peripheral 2 which is not available when WIFI or BT is enabled"
However according to the docs:
These channels are supported:

ADC1:
8 channels: GPIO32 - GPIO39

ADC2:
10 channels: GPIO0, GPIO2, GPIO4, GPIO12 - GPIO15, GOIO25 - GPIO27
Which is the opposite - however swapping the logic in the CAL file doesn't solve anything :-(

Martin

mnfisher
Valued Contributor
Posts: 1514
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 725 times

Re: ESP32 ADC not working

Post by mnfisher »

It isn't too hard to set up and use the ADC 'manually' - so tried this as an experiment.

So far only one pin (gpio_35) tested - but the raw values printed look sensible (connecting to bench PSU and varying the voltage - don't go > 3.3v or bad things will happen). I've set attenuation to DB_12 and ignore calibration - which would complicate matters some.

Probably needs a wee bit more work before using it in the real world - but it hopefully would be a start....

Martin
Attachments
esp_adc2.fcfx
(17.01 KiB) Downloaded 7 times

mnfisher
Valued Contributor
Posts: 1514
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 725 times

Re: ESP32 ADC not working

Post by mnfisher »

I extended my test to set up 8 ADC channels (4 on ADC1 and 4 on ADC2) - note that there are restrictions on the pins you can use (for example with wifi)

The pins 'seem' to set up correctly. From the UART output:
I (379) ADC Test: GPIO 35 maps to ADC Unit: 0, Channel: 7
I (379) ADC Test: Initializing ADC Unit 1
I (379) ADC Test: Successfully configured GPIO 35 (ADC0_CH7)
I (379) ADC Test: GPIO 33 maps to ADC Unit: 0, Channel: 5
I (389) ADC Test: Successfully configured GPIO 33 (ADC0_CH5)
I (389) ADC Test: GPIO 34 maps to ADC Unit: 0, Channel: 6
I (399) ADC Test: Successfully configured GPIO 34 (ADC0_CH6)
I (409) ADC Test: GPIO 32 maps to ADC Unit: 0, Channel: 4
I (409) ADC Test: Successfully configured GPIO 32 (ADC0_CH4)
I (419) ADC Test: GPIO 12 maps to ADC Unit: 1, Channel: 5
I (429) ADC Test: Initializing ADC Unit 2
I (429) ADC Test: Successfully configured GPIO 12 (ADC1_CH5)
I (439) ADC Test: GPIO 15 maps to ADC Unit: 1, Channel: 3
I (439) ADC Test: Successfully configured GPIO 15 (ADC1_CH3)
I (449) ADC Test: GPIO 25 maps to ADC Unit: 1, Channel: 8
I (459) ADC Test: Successfully configured GPIO 25 (ADC1_CH8)
I (459) ADC Test: GPIO 27 maps to ADC Unit: 1, Channel: 7
I (469) ADC Test: Successfully configured GPIO 27 (ADC1_CH7)
0) 2957
However - reading the pins gives 'random' values - if I just set and read one pin then it is correct - I'm guessing / hoping that this is because I have the pins floating (apart from gpio_35) - so will wire some extras to ground / test+ (pins read upto 2450mV) and see how that works.

Martin

mnfisher
Valued Contributor
Posts: 1514
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 725 times

Re: ESP32 ADC not working

Post by mnfisher »

Fixed it - silly mistake had 0 instead of index into the random selection of (ADC allowable) pins...

I have pins[0] to 2.4v and pins[1] to gnd and results look good :-)
Attachments
esp_adc2.fcfx
(18.82 KiB) Downloaded 10 times

mnfisher
Valued Contributor
Posts: 1514
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 725 times

Re: ESP32 ADC not working

Post by mnfisher »

Note - I used a random selection of pins, and not all are actually available on the board I am using. Others will be more careful.

Floating pins give random(ish) values.

I would probably alter the OneShot_Setup macro to return a 'success' result and pass both of the pointers (long ints) as reference values - and, of course, check the return!

This is only scratching the surface of the ADC functionality - there is also a continuous mode available.


Martin

simisv
Posts: 6
Joined: Wed Oct 19, 2022 7:54 am
Been thanked: 1 time

Re: ESP32 ADC not working

Post by simisv »

Hi Martin

I've already swapped the board with one using ESP32-S3 which I tested already using 8 ADC and works ok and have more GPIO's and is better for my project .
Thank you very much for your effort . I tested your code and works fine .

Read 0 = ADC1_7 GPIO-35 = read ok
Read 1 = ADC1_4 GPIO-32 = read ok
Read 2 = ADC1_6 GPIO-34 = read ok
Read 3 = ADC1_5 GPIO-33 = read ok
Read 4 = ADC2_5 GPIO-12 = read ok
Read 5 = ADC2_3 GPIO-15 = read ok
Read 6 = ADC2_8 GPIO-25 = read ok
Read 7 = ADC2_7 GPIO-27 = read ok

I will stay with ESP32-S3 this time , is much easy for me at the moment .
Again many many thanks .

Simi

mnfisher
Valued Contributor
Posts: 1514
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 725 times

Re: ESP32 ADC not working

Post by mnfisher »

Glad all is running.

If you use BT or wifi - you might need to alter your pin selection. There are a couple of pins that are involved in the 'boot' process too - so check the datasheet if you get unexpected results.

Martin

Post Reply