esp_hal::analog

Module adc

Source
Available on crate feature unstable only.
Expand description

§Analog to Digital Converter (ADC)

§Overview

The ADC is integrated on the chip, and is capable of measuring analog signals from specific analog I/O pins. One or more ADC units are available, depending on the device being used.

§Configuration

The ADC can be configured to measure analog signals from specific pins. The configuration includes the resolution of the ADC, the attenuation of the input signal, and the pins to be measured.

Some targets also support ADC calibration via different schemes like basic calibration, curve fitting or linear interpolation. The calibration schemes can be used to improve the accuracy of the ADC readings.

§Examples

§Read an analog signal from a pin

let analog_pin = peripherals.GPIO3;
let mut adc1_config = AdcConfig::new();
let mut pin = adc1_config.enable_pin(
    analog_pin,
    Attenuation::_11dB,
);
let mut adc1 = Adc::new(peripherals.ADC1, adc1_config);

let mut delay = Delay::new();

loop {
    let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut pin))?;

    delay.delay_millis(1500);
}

§Implementation State

Structs§

  • Analog-to-Digital Converter peripheral driver.
  • Configuration for the ADC.
  • An I/O pin which can be read using the ADC.

Enums§

Traits§

  • A trait abstracting over calibration methods.
  • A helper trait to get the ADC channel of a compatible GPIO pin.