Crates.io | embedded-hdc1080-rs |
lib.rs | embedded-hdc1080-rs |
version | 0.1.0 |
source | src |
created_at | 2021-09-11 08:14:18.280452 |
updated_at | 2021-09-11 08:14:18.280452 |
description | Rust driver for the HDC1080 low-power humidity and temperature digital sensor. |
homepage | https://github.com/maxmarvil/hdc1080-embedded-rs |
repository | https://github.com/maxmarvil/hdc1080-embedded-rs |
max_upload_size | |
id | 449661 |
size | 22,540 |
Made on the model of a crate for HDC20xx
Designed for use with [embedded-hal
]
read()
temperature()
and 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();
}
}
For questions, issues, feature requests, and other changes, please file an issue in the github project.