6个版本 (3个破坏性版本)
0.3.1 | 2024年6月1日 |
---|---|
0.3.0 | 2024年4月16日 |
0.2.1 | 2024年4月11日 |
0.1.0 | 2024年4月10日 |
0.0.0 | 2024年3月28日 |
#191 in 嵌入式开发
每月448次下载
87KB
1K SLoC
Lib SCD
LibSCD是使用embedded-hal
和embedded-hal-async
接口实现的SCD30、SCD40和SCD41传感器的Rust驱动程序。
用法
将crate作为Cargo.toml
中的依赖项添加,并选择所需的功能
[dependencies.libscd]
version = "0.3"
features = ["defmt", "sync", "scd40"]
然后我们可以开始使用阻塞I2C通信从SCD40获取数据
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
let i2c = I2c::new(
p.I2C2,
p.PB10,
p.PB3,
Irqs,
NoDma,
NoDma,
Hertz(100_000),
Default::default(),
);
let mut scd = Scd40::new(i2c, Delay);
// When re-programming, the controller will be restarted,
// but not the sensor. We try to stop it in order to
// prevent the rest of the commands failing.
_ = scd.stop_periodic_measurement();
info!("Sensor serial number: {:?}", scd.serial_number());
if let Err(e) = scd.start_periodic_measurement() {
defmt::panic!("Failed to start periodic measurement: {:?}", e);
}
loop {
if scd.data_ready().unwrap() {
let m = scd.read_measurement().unwrap();
info!("CO2: {}\nHumidity: {}\nTemperature: {}", m.co2, m.humidity, m.temperature)
}
Delay.delay_ms(1000)
}
}
crate功能标志
每个传感器和同步/异步模式的支持由一个功能控制
功能 | 描述 |
---|---|
sync | 启用所选传感器的阻塞驱动程序实现 |
async | 启用所选传感器的异步驱动程序实现 |
scd30 | 启用SCD30传感器的驱动程序 |
scd40 | 启用SCD40传感器的驱动程序 |
scd41 | 启用SCD41传感器的驱动程序 |
defmt | 为错误类型派生defmt::Format |
许可
项目根据MIT或APACHE-2.0双许可
依赖
~175KB