{"id":15064147,"url":"https://github.com/rust-dd/embedded-dht-rs","last_synced_at":"2025-04-10T11:50:46.205Z","repository":{"id":256484642,"uuid":"850812863","full_name":"rust-dd/embedded-dht-rs","owner":"rust-dd","description":"A Rust library that provides full support for DHT11, DHT22, and DHT20 (AHT20) temperature and humidity sensors.","archived":false,"fork":false,"pushed_at":"2025-01-04T22:00:28.000Z","size":3953,"stargazers_count":17,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T10:38:52.340Z","etag":null,"topics":["aht20","dht11","dht20","dht22","esp32","rust"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/embedded-dht-rs","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rust-dd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-01T21:04:54.000Z","updated_at":"2025-03-03T21:46:10.000Z","dependencies_parsed_at":"2024-10-25T01:36:41.791Z","dependency_job_id":"975368a2-e8cc-43db-b370-688e66dd0561","html_url":"https://github.com/rust-dd/embedded-dht-rs","commit_stats":{"total_commits":40,"total_committers":3,"mean_commits":"13.333333333333334","dds":0.275,"last_synced_commit":"b864c237ca2473615f904f3b47f65c50db2d2ea8"},"previous_names":["rust-dd/embedded-dht-rs"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-dd%2Fembedded-dht-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-dd%2Fembedded-dht-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-dd%2Fembedded-dht-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-dd%2Fembedded-dht-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rust-dd","download_url":"https://codeload.github.com/rust-dd/embedded-dht-rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248215192,"owners_count":21066619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aht20","dht11","dht20","dht22","esp32","rust"],"created_at":"2024-09-25T00:12:17.984Z","updated_at":"2025-04-10T11:50:46.188Z","avatar_url":"https://github.com/rust-dd.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"![build workflow](https://github.com/rust-dd/embedded-dht-rs/actions/workflows/rust.yml/badge.svg)\n[![Crates.io](https://img.shields.io/crates/v/embedded-dht-rs?style=flat-square)](https://crates.io/crates/embedded-dht-rs)\n![Crates.io](https://img.shields.io/crates/l/embedded-dht-rs?style=flat-square)\n[![API](https://docs.rs/embedded-dht-rs/badge.svg)](https://docs.rs/embedded-dht-rs)\n\n# embedded-dht-rs\n\n`embedded-dht-rs` is a Rust library designed to simplify interfacing with DHT sensors in embedded systems.\n\nThis library is `#![no_std]` and depends only on `embedded_hal`, making it versatile and compatible with virtually any microcontroller.\n\n**Support for DHT11, DHT20, and DHT22 Sensors**: All three sensors are fully implemented and ready for use.\n\nThe library has been tested with the ESP32-WROOM, and a detailed example is provided below to help you get started.\n\n## Getting Started\n\n### Tutorials\n\nHere are some general tutorials that provide brief introductions to embedded programming:\n\n- **Part 1 (Introduction)** - [Introduction to Embedded Systems with Rust: A Beginner's Guide Using ESP32](https://rust-dd.com/post/introduction-to-embedded-systems-with-rust-a-beginner-s-guide-using-esp32)\n- **Part 2 (LED + Button)** - [Building a Simple LED and Button Interface with Rust on ESP32](https://rust-dd.com/post/building-a-simple-led-and-button-interface-with-rust-on-esp32)\n- **Part 3 (DHT11 Library)** - [Building a Rust library for DHT11 sensor](https://rust-dd.com/post/building-a-rust-library-for-dht11-sensor-a-step-by-step-guide)\n\n\n### Install\n\n\nTo include the `dht11` feature:\n\n```rust\ncargo add embedded-dht-rs --features \"dht11\"\n```\n\nTo include all features (`dht11`, `dht20`, and `dht22`):\n\n```rust\ncargo add embedded-dht-rs --features \"dht11,dht20,dht22\"\n```\n\n### Example - ESP32\n\nYou can find the full example in the [examples](./examples) folder.\n\n```rust\n#![no_std]\n#![no_main]\n\nuse embedded_dht_rs::{dht11::Dht11, dht20::Dht20, dht22::Dht22};\nuse esp_backtrace as _;\nuse esp_hal::{\n    clock::ClockControl, delay::Delay, gpio::{Io, Level, OutputOpenDrain, Pull}, i2c::I2C, peripherals::Peripherals, prelude::*, system::SystemControl\n};\nuse fugit::HertzU32;\n\n#[entry]\nfn main() -\u003e ! {\n    let peripherals = Peripherals::take();\n    let system = SystemControl::new(peripherals.SYSTEM);\n    let clocks = ClockControl::boot_defaults(system.clock_control).freeze();\n    let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);\n\n    esp_println::logger::init_logger_from_env();\n\n    let delay = Delay::new(\u0026clocks);\n\n    let od_for_dht11 = OutputOpenDrain::new(io.pins.gpio4, Level::High, Pull::None);\n    let od_for_dht22 = OutputOpenDrain::new(io.pins.gpio5, Level::High, Pull::None);\n    let i2c_for_dht20 = I2C::new(\n        peripherals.I2C0, \n        io.pins.gpio21,\n        io.pins.gpio22, \n        HertzU32::kHz(400),\n        \u0026clocks\n    );\n\n    let mut dht11 = Dht11::new(od_for_dht11, delay);\n    let mut dht22 = Dht22::new(od_for_dht22, delay);\n    let mut dht20 = Dht20::new(i2c_for_dht20, delay);\n\n    loop {\n        delay.delay(5000.millis());\n\n        match dht11.read() {\n            Ok(sensor_reading) =\u003e log::info!(\n                \"DHT 11 Sensor - Temperature: {} °C, humidity: {} %\",\n                sensor_reading.temperature,\n                sensor_reading.humidity\n            ),\n            Err(error) =\u003e log::error!(\"An error occurred while trying to read sensor: {:?}\", error),\n        }\n\n        match dht22.read() {\n            Ok(sensor_reading) =\u003e log::info!(\n                \"DHT 22 Sensor - Temperature: {} °C, humidity: {} %\",\n                sensor_reading.temperature,\n                sensor_reading.humidity\n            ),\n            Err(error) =\u003e log::error!(\"An error occurred while trying to read sensor: {:?}\", error),\n        }\n\n        match dht20.read() {\n            Ok(sensor_reading) =\u003e log::info!(\n                \"DHT 20 Sensor - Temperature: {} °C, humidity: {} %\",\n                sensor_reading.temperature,\n                sensor_reading.humidity\n            ),\n            Err(error) =\u003e log::error!(\"An error occurred while trying to read sensor: {:?}\", error),\n        }\n\n        log::info!(\"-----\");\n    }\n}\n```\n\n![running](https://raw.githubusercontent.com/rust-dd/embedded-dht-rs/refs/heads/main/docs/example_esp32_dht_running.png)\n\n\n## Implementation Specification\n\nWe have gathered all the information you need to understand in order to implement a library like this. Additionally, we’ve included a few comments in the code for those curious about the details, based on the following specification.\n\nThe DHT20 differs from the DHT11 and DHT22 because it uses the I2C communication protocol, while both the DHT11 and DHT22 rely on a single-wire signal for data transmission.\n\n\n- [DHT11 and DHT22 Documentation](https://github.com/rust-dd/embedded-dht-rs/blob/main/docs/dht11_22.md)\n- [DHT20 Documentation](https://github.com/rust-dd/embedded-dht-rs/blob/main/docs/dht20.md)\n\n\n\n## Comparison of DHT11, DHT20, and DHT22 40-Bit Data Formats\n\n| Feature               | DHT11                                              | DHT20                                                  | DHT22                                                   |\n|-----------------------|----------------------------------------------------|--------------------------------------------------------|---------------------------------------------------------|\n| **Data Structure**     | - Byte 1: Humidity Int\u003cbr\u003e- Byte 2: Humidity Dec (0)\u003cbr\u003e- Byte 3: Temp Int\u003cbr\u003e- Byte 4: Temp Dec (0)\u003cbr\u003e- Byte 5: Checksum | - Byte 1: Humidity High\u003cbr\u003e- Byte 2: Humidity Low\u003cbr\u003e- Byte 3: Temp High\u003cbr\u003e- Byte 4: Temp Low\u003cbr\u003e- Byte 5: CRC | - Byte 1: Humidity High\u003cbr\u003e- Byte 2: Humidity Low\u003cbr\u003e- Byte 3: Temp High\u003cbr\u003e- Byte 4: Temp Low\u003cbr\u003e- Byte 5: Checksum |\n| **Precision**          | Integer only                                      | Higher precision with decimals                         | Higher precision with decimals                           |\n| **Example Temp**       | 25°C                                              | 25.6°C                                                 | 25.6°C                                                   |\n| **Example Humidity**   | 60%                                               | 60.5%                                                  | 60.5%                                                    |\n| **Example Data Bytes** | `60, 0, 25, 0, 85`                                | `2, 93, 1, 0, CRC`                                     | `2, 93, 1, 0, 96`                                        |\n| **Range**              | Temp: 0–50°C\u003cbr\u003eHum: 20–90%                       | Temp: -40–80°C\u003cbr\u003eHum: 10–90%                          | Temp: -40–80°C\u003cbr\u003eHum: 0–100%                            |\n\n## Example Schematic\n\n| ![Schematic](https://raw.githubusercontent.com/rust-dd/embedded-dht-rs/refs/heads/main/docs/example_esp32_schematic.png) [Click to zoom](https://raw.githubusercontent.com/rust-dd/embedded-dht-rs/refs/heads/main/docs/example_esp32_schematic.png) | ![Running](https://raw.githubusercontent.com/rust-dd/embedded-dht-rs/refs/heads/main/docs/example_esp32_wired.jpg) [Click to zoom](https://raw.githubusercontent.com/rust-dd/embedded-dht-rs/refs/heads/main/docs/example_esp32_wired.jpg) |\n|:--:|:--:|\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-dd%2Fembedded-dht-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frust-dd%2Fembedded-dht-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-dd%2Fembedded-dht-rs/lists"}