1 个不稳定版本

0.1.0 2022年12月1日

#1109嵌入式开发

MIT/Apache

19KB
297

Sensirion SHT4x 嵌入式 HAL 驱动程序

这是一个适用于Sensirion SHT4x 温湿传感器系列的平台无关设备驱动程序。它基于embedded-hal特质,并在no_std环境中工作。

理论上,它支持该传感器系列的所有设备,但到目前为止只测试了SHT40-AD1B。

Build Status crates.io Documentation

特性

  • 阻塞操作
  • 支持数据表中指定的所有命令
  • 显式借用DelayMs以执行命令,以便可以共享(多个传感器之间)
  • 可以使用SHT40-BD1B的备用I2C地址实例化
  • 使用定点算术将原始传感器数据转换为SI单位中的测量值
    • 基于fixed crate中的I16F16
    • 如果需要,允许转换为浮点值
    • 方便的定点转换方法,将毫摄氏度或毫百分比相对湿度转换为常用值,这些值通常由Sensirion的其他湿度和温度传感器的驱动程序使用
  • 可选支持defmt

示例

use embedded_hal::blocking::delay::DelayMs;
use sht4x::Sht4x;
// Device-specific use declarations.

let mut delay = // Device-specific initialization of delay.
let i2c = // Device-specific initialization of I2C peripheral.
let mut sht40 = Sht4x::new(i2c);

let serial = sht40.serial_number(&mut delay);
defmt::info!("serial number: {}", serial);

let measurement = sht40.measure(Precision::Low, &mut delay);
defmt::info!("measurement: {}", &measurement);

if let Ok(measurement) = measurement {
    // Convert temperature measurand into different formats for further
    // processing.
    let int: i32 = measurement.temperature_milli_celsius();
    let fixed: I16F16 = measurement.temperature_celsius();
    let float: f32 = measurement.temperature_celsius().to_num();
}

sensor-temp-humidity-sht40是该传感器系列的另一个驱动程序。

许可证

根据您的选择,许可方式为

贡献

除非您明确说明,否则根据Apache-2.0许可证定义的,您有意提交以包含在作品中的任何贡献,都应按上述方式双许可,而不附加任何额外条款或条件。

依赖项

约2.5MB
约49K SLoC