Module esp32_hal::adc

source ·
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:

ChannelADC1ADC2
0GPIO36 (SENSOR_VP)GPIO4
1GPIO37 (SENSOR_CAPP)GPIO0
2GPIO38 (SENSOR_CAPN)GPIO2
3GPIO39 (SENSOR_VN)GPIO15 (MTDO)
4GPIO33 (32K_XP)GPIO13 (MTCK)
5GPIO32 (32K_XN)GPIO12 (MTDI)
6GPIO34 (VDET_1)GPIO14 (MTMS)
7GPIO35 (VDET_2)GPIO27
8GPIO25
9GPIO26

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

Traits