3个版本 (破坏性更新)
0.3.0 | 2024年1月10日 |
---|---|
0.2.0 | 2024年1月5日 |
0.1.0 | 2023年11月28日 |
1522 在 嵌入式开发
每月36 次下载
11KB
108 行
Si70xx
这是一个基于 embedded-hal 和 embedded-hal-async 特性的Si70xx系列相对湿度温度传感器Rust驱动程序,与平台无关。
数据表
lib.rs
:
这是一个基于 embedded-hal
和 embedded-hal-async
特性的Si70xx系列相对湿度温度传感器Rust驱动程序,与平台无关。
数据表
读取湿度和温度
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.);
使用异步方式读取湿度和温度
通过启用 async
功能,异步API变为可用。
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.);
使用Si7013读取湿度和温度
Si7013支持两个I2C地址,所有其他传感器使用固定的0x40地址。要使用Si7013,必须启用si7013
功能。
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.
依赖项
~62KB