sht4x-rs
A platform-agnostic embedded-hal 1.0 driver for the Sensirion SHT4x family of high-accuracy temperature and humidity sensors. no_std, blocking and async APIs, zero unsafe.
Note: the bare
sht4xname on crates.io is already taken, so this crate is published assht4x-rs. The library itself is imported asuse sht4x::....
Supported sensors
- SHT40
- SHT41
- SHT45
All variants share the same I²C protocol; the differences are accuracy class and packaging.
Features
| Feature | Default | Description |
|---|---|---|
blocking |
yes | Sync API on embedded-hal 1.0 traits. |
async |
no | Mirror API on embedded-hal-async 1.0 traits. |
defmt |
no | defmt::Format impls for the public types & errors. |
Blocking usage
use ;
# # where I: I2c, D: DelayNs
Async usage
Enable the async cargo feature:
= { = "0.1", = false, = ["async"] }
use ;
let mut sensor = new;
let m = sensor.measure_async.await?;
Integer accessors (no FPU? no problem)
Every Measurement exposes fixed-point accessors that never touch f32:
m.temperature_milli_celsius; // e.g. 23_456 -> 23.456 °C
m.humidity_milli_percent; // e.g. 50_123 -> 50.123 %RH
Linux example
See examples/linux.rs for a Raspberry-Pi-style usage with linux-embedded-hal:
Datasheet
Sensirion SHT4x datasheet (current revision): https://sensirion.com/resource/datasheet/sht4x.
Command bytes and timings in this driver were cross-checked against datasheet rev. 7.1 (March 2025).
Contributing
Issues, PRs, and additional hardware test reports are welcome at https://github.com/KarpagamKarthikeyan/sht4x-rs. Please run cargo test, cargo clippy --all-features -- -D warnings, and cargo fmt before opening a PR.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.