pub struct Dht { /* private fields */ }
Expand description
Handle on a Dht device, can be used to read sensor data. The internal memmap reference is automatically cleared on drop.
Implementations§
Source§impl Dht
impl Dht
Sourcepub fn new(typ: DhtType, gpio_pin: usize) -> Result<Dht, GpioOpenError>
pub fn new(typ: DhtType, gpio_pin: usize) -> Result<Dht, GpioOpenError>
Create a new Dht
struct, which can be used to read sensor data.
Note: Specifying the wrong DhtType only results in absurd readings, but does not have any other risks.
The gpio_pin
is the GPIO number, not the pin number. You can find annotated visual charts for your PI’s layout online.
Make sure you have specified the correct pin number.
Pin numbers from 0..57 are allowed here, but only pins 0..39 are actually available on current PI hardware.
Sourcepub fn read(&mut self) -> Result<Reading, DhtError>
pub fn read(&mut self) -> Result<Reading, DhtError>
Try to get a reading from the DHT sensor.
Note that reading from DHT sensors is inherently unreliable: expect one in three reads to fail, round about.
Additionally, in rare cases individual reads may result in incorrect values.
This is a hardware issue. If you need more reliable reads, read twice
and make sure the results don’t deviate much.
Lastly, if you need accurate readings, cross-check your readings to some sensor you know to be correct,
it has been reported online that some DHT modules report values that are offset from the actual value by
some amount.