dht-mmap-rust 0.1.0

Simple access to DHT11 and DHT22 sensors for the Raspberry PI
Documentation
  • Coverage
  • 66.67%
    12 out of 18 items documented0 out of 9 items with examples
  • Size
  • Source code size: 20.11 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 397.01 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • krusema/dht-mmap-rust
    4 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • krusema

dht-mmap-rust

...is a library to read DHT11/DHT22 sensors on raspberry pi.

This library enables simple reading of DHT11 and DHT22 temperature+humidity sensors using the GPIO pins on a Raspberry PI.
In order to achieve sufficiently fast memory access, this library directly accesses the memory registers for pin control.
I wrote this library because the other libraries I tried did not work on my PI. This library should work out of the box.

Usage

The file /dev/gpiomem needs to be accessible, so the program either needs to be run as root or have group-based access to the file.
If you want to run your program to run on a user other than root, this StackOverflow answer has instructions. This is already configured by default on raspbian.

Code:

fn main() {
    // The sensor is a DHT11 connected on pin 23
    let mut dht = Dht::new(DhtType::Dht11, 23).unwrap();

    // Important: DHT sensor reads fail sometimes. In an actual program, if a read fails you should retry multiple times until
    // the read succeeds.
    // For more information, see documentation on `read()`
    let reading = dht.read().unwrap();

    println!(
        "Temperature {} °C, Humidity {}%RH",
        reading.temperature(),
        reading.humidity()
    );
}

Tests

This repo contains two tests,
one that assumes a DHT11 is connected on GPIO pin 2 and
one that assumes a DHT22 is connected on GPIO pin 3.

Caveats

This library works on Raspberry PIs and not other embedded devices such as Arduino and the likes. That is why it needs so little boilerplate.