Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rust embedded-hal based driver for the DHT11/DHT22 sensor

License

NotificationsYou must be signed in to change notification settings

michaelbeaumont/dht-sensor

Repository files navigation

crates.ioDocs

This library provides a platform-agnostic driver for theDHT11 and DHT22 sensors.

Use one of two functionsdht11::blocking::read anddht22::blocking::read to get a reading.

Usage

The only prerequisites are an embedded-hal implementation that provides:

  • DelayNs-implementing type, for example Cortex-M microcontrollers typically use theSysTick.
  • InputPin andOutputPin-implementing type, for example anOutput<OpenDrain> fromstm32f0xx_hal.

When initializing the pin as an output, the state of the pin might depend on the specific chipused. Some might pull the pin low by default causing the sensor to be confused when we actuallyread it for the first time. The same thing happens when the sensor is polled too quickly in succession.In both of those cases you will get aDhtError::Timeout.

To avoid this, you can pull the pin high when initializing it and polling the sensor with aninterval of at least 500ms (determined experimentally). Some sources state a refresh rate of 1 or even 2 seconds.

Example

See the following examples for how to use the library.

Blocking API

Async API

Release mode may be required

Compiling in debug mode may disturb the timing-sensitive parts of this crate and ultimately lead to failure.In this case, you will likely receive aTimeout error. Try compiling with--release instead.

Tests

To run the tests, use something likecargo test --lib --target x86_64-unknown-linux-gnu.

About

Rust embedded-hal based driver for the DHT11/DHT22 sensor

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors6


[8]ページ先頭

©2009-2025 Movatter.jp