An I²C driver for Innovative Sensor Technology IST AG's HYT-series temperature and humidity sensor modules (HYT221, HYT271 and HYT939).
let i2c = ...; // Some embedded-hal I²C device.
let hyt = ist_hyt::Hyt::new(i2c).start_measurement().unwrap();
let measurement = loop {
// Poll until the measurement is ready.
let m = hyt.read().unwrap();
if !m.is_stale() {
break m;
}
};
let humidity = measurement.humidity();
let temperature = measurement.temperature();
See examples/measure.rs
for a full working example.
For simplicity, the basic humidity()
and temperature()
functions return
integer results. However, the HYT-series sensors provide measurements with
useful resolution significantly smaller than 1°C or 1%RH. Most microcontrollers
lack floating-point capabilities, so this crate provides two separate mechanisms
for increasing the precision of the result:
- Values scaled by a user-defined constant (e.g.
temperature_scaled(100)
). - Fixed-point (I8F24) values (e.g.
temperature_i8f24()
) based on the fixed crate, but only if thei8f24
feature is enabled.
This crate is in early development and its API should be considered to be unstable.
Known issues:
- Whilst the I²C interface is the same for the whole HYT family, this crate is only known to have been tested with the HYT221.
- Support for "command mode" is not yet implemented. Command mode is not required for normal operation, but allows configuration, for example, of the sensor's I²C address.
- There is not yet any support for non-blocking operations. To mitigate
this, the
start_measurement()
andread()
functions are separate, so that calling code can do other work whilst the sensor is busy. Note that the embedded-hal crate doesn't currently provide a non-blocking I²C API. - Floating-point results are not supported at all, even on microcontrollers that can handle them.
cargo test
doesn't do anything useful at the moment.
This project is licensed under the terms of the MIT Licence. See LICENCE for the licence text.