A rough estimate of how fast each of the read methods are is easy to get:
from machine import ADC,Pin
import time
adc = ADC(Pin(32),atten=ADC.ATTN_11DB)
t = time.ticks_us()
for i in range(10000):
pass
print(time.ticks_diff(time.ticks_us(), t)/10000)
t = time.ticks_us()
for i in range(10000):
m=adc.read()
print(time.ticks_diff(time.ticks_us(), t)/10000)
t = time.ticks_us()
for i in range(10000):
m=adc.read_u16()
print(time.ticks_diff(time.ticks_us(), t)/10000)
t = time.ticks_us()
for i in range(10000):
m=adc.read_uv()
print(time.ticks_diff(time.ticks_us(), t)/10000)
The two raw read methods take about 49μs and the calibrated method read_uv takes about 50μs which puts the maximum sampling rate at about 20kHz. Reducing the accuracy to 9-bits reduces the time taken by about 1μs.
In Chapter but not in this extract
The Hall Effect Sensor
Internal Temperature Sensor
Digital to Analog
Touch Sensors
Summary
The ESP32 has two 12-bit ADCs, but only one is available for general use and it provides six easy-to-use channels.
The calibration voltage is available as a value stored in the eFuse memory. MicroPython makes use of this to correct the measurement.
The read_uv method is corrected and at around 50μs per sample isn’t much slower than the alternatives.
An onboard Hall effect sensor uses two of the ADC inputs.
The onboard temperature sensor has its own analog input and is really only useful for measuring the processor temperature.
There are two 8-bit ADC channels which use GPIO25 and GPIO26.
Using a lookup table you can generate wave forms at 400Hz to 10kHz, depending on resolution.
The ADC class doesn’t support many of the more advanced features of the ADC hardware but you can use the sine wave generator directly.
There are also ten touch sensors. These are capacitive sensors and do not require contact with the GPIO line.