Arduino – ESP32 – Read multiple analog inputs

analogarduinoesp32inputread

I need to read multiple analog inputs as fast as possible on a ESP32. With as fast as possible, i mean that ideally all inputs are read simultaneously.

Currently I simply read them one after the other with consecutive AnalogREAD() calls in my code, but it happens that I read a value on a Input where no current is applied. I have read somewhere some months ago that in these cases it is good to put a pause between Read calls to give it the time to switch to the proper input.

Is this true? What is a reasonable amount of time to put in there, keeping in mind that I would need to read tehm all (5 inputs) as quick as possible?

All inputs are on the ADC 1.

Best Answer

The fastest way would be to use two different ADCs so you can simultaneously sample and convert two analog inputs.

The second fastest way (according to the reference manual) would be to tell the ADC a list of channels which to sample and tell it to go sample the channels in the list, writes results to memory using DMA, and reports with a scan complete interrupt when it is done going through the list.

There is little benefit of delaying between taking ADC conversions, if it helps then it is a sign of the sampled signals having too high impedances to get a stable result, which could be also a sign of the ADC being incorrectly configured for the expected signal impedances, and just longer sampling period (or slower ADC clock) might fix it. Usually the switch between channels is done when the analog sampling circuit is not connected to the analog pin.