Expand description

Analog-Digital Converter (ADC)

See Chapter 4 Section 9 of the datasheet for more details

Usage

Capture ADC reading from a pin

use embedded_hal::adc::OneShot;
use rp2040_hal::{adc::Adc, gpio::Pins, pac, Sio};
let mut peripherals = pac::Peripherals::take().unwrap();
let sio = Sio::new(peripherals.SIO);
let pins = Pins::new(peripherals.IO_BANK0, peripherals.PADS_BANK0, sio.gpio_bank0, &mut peripherals.RESETS);
// Enable adc
let mut adc = Adc::new(peripherals.ADC, &mut peripherals.RESETS);
// Configure one of the pins as an ADC input
let mut adc_pin_0 = pins.gpio26.into_floating_input();
// Read the ADC counts from the ADC channel
let pin_adc_counts: u16 = adc.read(&mut adc_pin_0).unwrap();

Capture ADC reading from temperature sensor. Note that this needs conversion to be a real-world temperature.

use embedded_hal::adc::OneShot;
use rp2040_hal::{adc::Adc, gpio::Pins, pac, Sio};
let mut peripherals = pac::Peripherals::take().unwrap();
let sio = Sio::new(peripherals.SIO);
let pins = Pins::new(peripherals.IO_BANK0, peripherals.PADS_BANK0, sio.gpio_bank0, &mut peripherals.RESETS);
// Enable adc
let mut adc = Adc::new(peripherals.ADC, &mut peripherals.RESETS);
// Enable the temperature sensor
let mut temperature_sensor = adc.enable_temp_sensor();
// Read the ADC counts from the ADC channel
let temperature_adc_counts: u16 = adc.read(&mut temperature_sensor).unwrap();

See examples/adc.rs and pimoroni_pico_explorer_showcase.rs for more complete examples

Structs

Adc

Internal temperature sensor type