Closed shanemmattner closed 1 year ago
Try putting dht11_pin into open_drain_output mode:
let dht11_pin = peripherals.pins.gpio23.into_open_drain_output();
Thank you @kolemikko , that was the correct solution. Here is the working code with the latest esp-idf-hal crate:
use dht11::Dht11;
use esp_idf_hal::{
delay::{Ets, FreeRtos},
gpio::*,
prelude::Peripherals,
};
fn main() {
esp_idf_sys::link_patches();
let peripherals = Peripherals::take().unwrap();
let dht11_pin = PinDriver::input_output_od(peripherals.pins.gpio5.downgrade()).unwrap();
let mut dht11 = Dht11::new(dht11_pin);
loop {
let mut dht11_delay = Ets;
match dht11.perform_measurement(&mut dht11_delay) {
Ok(measurement) => println!(
"temp: {}C, humidity: {}%",
(measurement.temperature as f32 / 10.0),
(measurement.humidity as f32 / 10.0)
),
Err(e) => println!("{:?}", e),
}
FreeRtos::delay_ms(2000);
}
}
Cargo.toml
:
[package]
name = "dht11"
version = "0.1.0"
authors = ["Shane <shanemmattner@gmail.com>"]
edition = "2021"
resolver = "2"
[profile.release]
opt-level = "s"
[profile.dev]
debug = true # Symbols are nice and they don't increase the size on Flash
opt-level = "z"
[features]
pio = ["esp-idf-sys/pio"]
[dependencies]
esp-idf-hal = "0.40"
esp-idf-sys = { version = "0.32", features = ["binstart"] }
dht11 = "0.3.1"
[build-dependencies]
embuild = "0.30.4"
I'm trying to use this library with the ESP32 and running into problems with the
gpio
declaration. Any help would be appreciated.Error messages on
cargo build
:main.rs
Cargo.toml