Expand description
Crate to interface with the HTU21D temperature and relaive humidity sensor (commonly referred to as GY-21)
Implements Read
and Write
from embedded_hal::blocking::i2c
This crate does not implement all the features of the HTU21D. It doesn’t implement the master hold read or the precision change. It also ignores the status bits since the sensor I used to develop this doesn’t seem to use those in the same way as the datasheet does
How to use
Create the GY-21:
// `delay` is your HAL's delay object
// `i2c` is a i2c bus you have previously prepared
let gy_21 = Gy21::new(i2c, delay); // Using the default I2C address for the sensor (0x40)
// otherwise
let gy_21 = Gy21::with_address(i2c, delay, 0x40) // Using 0x39 as the I2C address
Read the temperature, humidity and dew point temperature:
if let Ok(temp) = gy_21.temperature() {
println!("Temperature = {}", temp);
}
if let Ok(rhum) = gy_21.humidity() {
println!("Relative humidity = {}%", rhum);
}
if let Ok(dpt) = gy_21.dew_point_temp() {
println!("Dew point temperature = {}\n\n", dpt);
}
Structs
- Represents the GY-21 sensor
Enums
- Error type containing I2C Read and Write errors