3 releases (breaking)
0.3.0 | Jan 10, 2024 |
---|---|
0.2.0 | Jan 5, 2024 |
0.1.0 | Nov 28, 2023 |
#1225 in Hardware support
34 downloads per month
11KB
108 lines
Si70xx
This is a platform agnostic Rust driver for the Si70xx series relative humidity and temperature sensor based on embedded-hal and embedded-hal-async traits.
Datasheet
lib.rs
:
This is a platform agnostic Rust driver for the Si70xx series
relative humidity and temperature sensor
based on embedded-hal
and embedded-hal-async
traits.
Datasheet:
Read humidity and temperature
use linux_embedded_hal::I2cdev;
use si70xx::Si70xx;
let i2c = some_i2c_from_hal();
let mut sensor = Si70xx::new(i2c);
// Start humidity and temperature measurement.
sensor.measure().unwrap();
// Read out measurement results.
let hum = sensor.read_humidity().unwrap();
let temp = sensor.read_temperature().unwrap();
// Values are scaled with 100, print them as floats.
println!("Humidity: {:.1}", hum as f32 / 100.);
println!("Temperature: {:.1}ºC", temp as f32 / 100.);
Read humidity and temperature using async
Async API becomes available by enabling async
feature.
si70xx = { version: 0.1.0, features = "async"}
use linux_embedded_hal::I2cdev;
use si70xx::Si70xx;
let async_i2c = some_i2c_from_hal();
let mut sensor = Si70xx::new(async_i2c);
// Start humidity and temperature measurement.
sensor.measure().await.unwrap();
// Read out measurement results.
let hum = sensor.read_humidity().await.unwrap();
let temp = sensor.read_temperature().await.unwrap();
// Values are scaled with 100, print them as floats.
println!("Humidity: {:.1}", hum as f32 / 100.);
println!("Temperature: {:.1}ºC", temp as f32 / 100.);
Read humidity and temperature with Si7013
Si7013 supports two I2C addresses, all other sensors use fixed 0x40 address.
To use Si7013, feature si7013
must be enabled.
si70xx = { version: 0.1.0, features = "si7013"}
use linux_embedded_hal::I2cdev;
use si70xx::{Si70xx, Address};
let i2c = some_i2c_from_hal();
let mut sensor = Si70xx::new(i2c, Address::H41);
// Measuring and reading out values is the same as in the example above.
Dependencies
~62KB