#温度湿度 #温度传感器 #温度 #湿度 #传感器 #嵌入式HAL驱动

无std embedded-hdc1080-rs

Rust对HDC1080低功耗温湿度数字传感器的驱动程序

1 个不稳定版本

0.1.0 2021年9月11日

#905嵌入式开发

MIT/Apache

12KB
172

hdc1080-embedded-rs - 温湿传感器驱动程序

基于HDC20xx的crate模型

HDC1080参考

适用于与embedded-hal一起使用

功能

  • 使用单个请求从传感器读取数据 read()
  • 分别读取温度和湿度的命令 temperature()humidity()
  • 获取关于传感器的信息:get_device_id()get_man_id()get_serial_id()
  • 低电量检查:battery_low()

使用方法

#![deny(unsafe_code)]
#![no_main]
#![no_std]
extern crate cortex_m;
extern crate cortex_m_rt as rt;
extern crate nb;
extern crate stm32g0xx_hal as hal;

use hal::{prelude::*, stm32, time::Hertz, i2c::Config};
use nb::block;
use rt::entry;
use embedded_hdc1080_rs::Hdc1080;

fn main() {
    let dp = stm32::Peripherals::take().expect("cannot take peripherals");
    let mut rcc = dp.RCC.constrain();
    let gpioc = dp.GPIOC.split(&mut rcc);
    let gpioa = dp.GPIOA.split(&mut rcc);
    let mut delay = dp.TIM14.delay(&mut rcc);
    let mut led = gpioc.pc6.into_push_pull_output();
    let sda = gpioa.pa10.into_open_drain_output();
    let scl = gpioa.pa9.into_open_drain_output();
    let mut temp:f32;
    let mut hum:f32;

    let mut timer = dp.TIM17.timer(&mut rcc);

    let conf:Config = Config::new(100.khz());

    let mut i2c = dp
        .I2C1
        .i2c(sda, scl, conf, &mut rcc);
    let mut dev = Hdc1080::new(i2c, delay).unwrap();
    
    dev.init().unwrap();
    //hprintln!("device ID {:?}", dev.get_device_id().unwrap());
    //hprintln!("manufacturer id {:?}", dev.get_man_id().unwrap());
    //hprintln!("Serial ID {:?}", dev.get_serial_id().unwrap());
    //hprintln!("curent config {:?}", dev.read_config().unwrap());

    timer.start(500.ms());
    loop {
        led.toggle().unwrap();
        let (temp, hum) = dev.read().unwrap();
        //hprintln!("temperature {}", temp);
        //hprintln!("humidity {}", hum);
        block!(timer.wait()).unwrap();
    }
}

支持

有关问题、问题、功能请求和其他更改,请在github项目中提交问题。

许可证

依赖关系

~71KB