| Crates.io | esp32_hal_dht11_driver |
| lib.rs | esp32_hal_dht11_driver |
| version | 0.2.2 |
| created_at | 2025-10-22 04:42:46.107339+00 |
| updated_at | 2025-10-31 00:56:18.307645+00 |
| description | A Rust crate that reads temperature and humidity data from the DHT11 sensors for esp32 series, updated to remove depancancy of the embedded_hal crate |
| homepage | https://github.com/eliperez-dev/esp32_hal_dht11_driver |
| repository | https://github.com/eliperez-dev/esp32_hal_dht11_driver |
| max_upload_size | |
| id | 1894969 |
| size | 74,880 |
A no_std Rust driver for the DHT11 temperature and humidity sensor designed for ESP32 microcontrollers.
esp-hal (v1.0.0-rc.1)Add to your Cargo.toml:
[dependencies]
esp32_hal_dht11_driver = "0.2.1"
use esp32_hal_dht11_driver::DHT11;
use esp_hal::delay::Delay;
use esp_hal::gpio::Flex;
fn main() {
let delay = Delay::new();
let mut dht11 = DHT11::new(delay);
// Configure your GPIO pin as a Flex GPIO
let mut pin = Flex::new(io.gpio2);
loop {
match dht11.read(&mut pin) {
Ok(reading) => {
println!("Temperature: {}°C", reading.temperature);
println!("Humidity: {}%", reading.humidity);
}
Err(error) => {
eprintln!("Sensor error: {:?}", error);
}
}
delay.delay_millis(2000);
}
}
DHT11::new(delay: Delay) -> Self
Creates a new DHT11 instance with a delay provider.
DHT11::read(&mut self, pin: &mut esp_hal::gpio::Flex) -> Result<Reading, SensorError>
Reads temperature and humidity data from the sensor.
Returns:
Ok(Reading) - Contains temperature (i8) in °C and humidity (u8) in %Err(SensorError) - One of: Timeout, ChecksumMismatch, or PinErrorThe driver may return the following errors:
SensorError::Timeout - Communication timeout with sensorSensorError::ChecksumMismatch - Data integrity check failedSensorError::PinError - GPIO operation failedImplement proper error handling in your application for robust operation.
This library is forked from esp32-dht11-rs and updated to:
embedded_hal crateesp-hal v1.0.0-rc.1MIT License
