dht-embedded
dht-embedded is a Rust crate that reads temperature and humidity data
from the DHT11 and DHT22 sensors.
Prerequisites
- You've connected the DHT sensor to your device (such as a Raspberry Pi or ESP32) using a GPIO pin.
Usage
Add the following to your Cargo.toml:
[]
= "=0.1.0-alpha.1"
Note that this crate currently tracks the 1.0.0 alpha releases of
embedded-hal, so things can change & break often, and your platform's
embedded-hal implementation may not have trait impls for 1.0.0 alphas
at all, let alone the current one this crate supports.
You will need to use an embedded-hal implementation for your hardware.
Here's a simple one using linux-embedded-hal and `gpio-cdev, which
could be used on a Rasperry Pi.
use ;
use ;
use ;
use ;
(To be fair, the Linux kernel includes a driver for DHT sensors, and honestly it's probably better to use that driver, since kernel space can disable interrupts and get much more precise timing than we can.)
Why
A search of crates.io might yield several different implementations of this driver. I wrote this because none of the others worked for me, and, upon examination of their code, I found they used a completely different protocols for reading from the sensor, protocols I couldn't find documented anywhere as what's supposed to work. This crate implements one of the simpler protocols that doesn't require access to a system clock, but still seems to work most of the time.