[][src]Crate dht11

Platform-agnostic Rust driver for the DHT11 temperature and humidity sensor, using embedded-hal traits.


An example for the STM32F407 microcontroller can be found in the source repository.

// Open drain pin compatibible with HAL
let pin = gpio.pe2.into_open_drain_output();

// SysTick-based HAL `Delay` on Cortex-M
let mut delay = Delay::new(cp.SYST, clocks);

let mut dht11 = Dht11::new(pin);

match dht11.perform_measurement(&mut delay) {
    Ok(meas) => hprintln!("Temp: {} Hum: {}", meas.temperature, meas.humidity).unwrap(),
    Err(e) => hprintln!("Error: {:?}", e).unwrap(),

Optional features


In applications with multiple, frequent interrupts being handled by the system, the traditional delay-based approach achievable using only traits provided by embedded-hal may lead to incorrect bit readings, and thus timeout and CRC errors.

Enabling this feature will cause the crate to use the DWT counter available on some ARM Cortex-M families to more accurately measure bit times, thus greatly reducing inaccuracies introduced by external interrupts.



A DHT11 device.


Results of a reading performed by the DHT11.



Error type for this crate.