Expand description
Analog to digital (ADC) conversion support.
Overview
The ADC
module in the analog
driver enables users to perform
analog-to-digital conversions, allowing them to measure real-world
analog signals with high accuracy.
This module provides functions for reading analog values from the
analog to digital converter available on the ESP32: ADC1
and ADC2
.
The following pins can be configured for analog readout:
Channel | ADC1 | ADC2 |
---|---|---|
0 | GPIO36 (SENSOR_VP) | GPIO4 |
1 | GPIO37 (SENSOR_CAPP) | GPIO0 |
2 | GPIO38 (SENSOR_CAPN) | GPIO2 |
3 | GPIO39 (SENSOR_VN) | GPIO15 (MTDO) |
4 | GPIO33 (32K_XP) | GPIO13 (MTCK) |
5 | GPIO32 (32K_XN) | GPIO12 (MTDI) |
6 | GPIO34 (VDET_1) | GPIO14 (MTMS) |
7 | GPIO35 (VDET_2) | GPIO27 |
8 | GPIO25 | |
9 | GPIO26 |
Example
ADC on Xtensa architecture
// Create ADC instances
let analog = peripherals.SENS.split();
let mut adc1_config = AdcConfig::new();
let mut pin3 =
adc1_config.enable_pin(io.pins.gpio3.into_analog(), Attenuation::Attenuation11dB);
let mut adc1 = ADC::<ADC1>::adc(analog.adc1, adc1_config).unwrap();
let mut delay = Delay::new(&clocks);
loop {
let pin3_value: u16 = nb::block!(adc1.read(&mut pin3)).unwrap();
println!("PIN3 ADC reading = {}", pin3_value);
delay.delay_ms(1500u32);
}
Structs
Enums
- The sampling/readout resolution of the ADC