5 releases
0.1.4 | Jan 21, 2024 |
---|---|
0.1.3 | Nov 3, 2023 |
0.1.2 | Nov 2, 2023 |
0.1.1 | Oct 29, 2023 |
0.1.0 | Oct 28, 2023 |
#404 in Hardware support
16KB
231 lines
HTU21D(F) sensor support
Crate for reading temperature and humidity values from a HTU21D(F) sensor over I²C.
The implementation is based on the datasheet provided by MEAS [^0]
and was tested with a GY-21 sensor board. The API is heavily inspired
by the shtcx
crate.
[^0] https://cdn-shop.adafruit.com/datasheets/1899_HTU21D.pdf
lib.rs
:
-
About
- This is a Rust driver for the HTU21D(F) temperature / humidity sensor
- by TE MEAS found in widely available sensor components. It was tested on
- GY-21 sensor but should work with different HTU21 based sensors too.
- The implementation is based on [the official datasheet by TE
- MEAS](https://cdn-shop.adafruit.com/datasheets/1899_HTU21D.pdf).
-
Example performing measurements with the HTU21D on the ESP32
- In this example only the HTU21 (GY-21) is accessed over I²C but since
- in a real-world application that is unlikely to be the only slave
- device on the bus, the I²C struct is wrapped with the
shared-bus
crate.-
- use esp_println::{print, println};
- use hal::{clock::ClockControl, gpio::IO, i2c::I2C, peripherals::Peripherals,
-
prelude::*, Delay};
- use htu21df_sensor::Sensor;
- // set up clock and delay handle to ensure the proper duration between
- // measurement initiation and reading the result
- let clocks = ClockControl::max(system.clock_control).freeze();
- let mut delay = Delay::new(&clocks);
- // initialize I²C with the default GPIO pins on ESP32
- let i2c = I2C::new(
-
peripherals.I2C0,
-
io.pins.gpio21,
-
io.pins.gpio22,
-
100u32.kHz(),
-
/* TODO: this will go away soon
Dependencies
~71KB