sensor-temp-humidity-sht40

This is a rust embedded-hal driver for the Sensirion SHT40 temperature and relative-humidity sensor.

Status

Software

The driver is developed against the stable 0.2.6 version of embedded-hal. All releases from this branch are versioned 0.2.6xx with xx incrementing from one release to the next.

Please use the main branch for hal-1.0.0 support.

Hardware Features

Crate Features

Usage

Detailed API documentation here

Import this crate and an embedded_hal implementation, then instantiate the driver:

``` use linuxembeddedhal as hal;

use hal::{I2cdev, Delay}; use sensortemphumidity_sht40::{SHT40Driver, I2CAddr, Precision, Measurement, TempUnit};

fn main() { let i2cdev = I2cdev::new("/dev/i2c-1").unwrap(); let mut sht40 = SHT40Driver::new(i2cdev, I2CAddr::SHT4x_A, Delay);

if let Ok(measurement) =
    sht40.get_temp_and_rh(Precision::High, TempUnit::MilliDegreesCelsius) {
  println!("Temp: {temp} C, Relative Humidity: {rh} %",
           temp = measurement.temp,
           rh = measurement.rel_hum_pcm);
}

} ```

``` use espidfsys; use espidfhal::delay; use espidfhal::i2c; use espidfhal::prelude::*; use sensortemphumidity_sht40::{SHT40Driver, I2CAddr, Precision, TempUnit};

fn main() { let peripherals = Peripherals::take().unwrap(); let pins = peripherals.pins;

let i2c = peripherals.i2c0;
let scl = pins.gpio9;
let sda = pins.gpio8;
let i2c_config = <i2c::config::MasterConfig as Default>::default()
                 .baudrate(400.kHz().into());

let mut sensor_drv = SHT40Driver::new(
    i2c::Master::<i2c::I2C0, _, _>::new(i2c, 
                                        i2c::MasterPins { sda, scl }, 
                                        i2c_config).unwrap(), 
    I2CAddr::SHT4x_A, 
    delay::Ets);

let measurement = sensor_drv.get_temp_and_rh(Precision::High,
                                             TempUnit::MilliDegreesCelsius);
println!("Measurement {:#?}", measurement);

} ```

License

The crate is dually licensed under Apache License, Version 2.0 or the BSD 3-clause license (you can choose under which of the two licenses you use the code).

Contributions

If you want to contribute code to this project, you accept that any code you submit shall be dually licensed as above, with your copyright details added to the relevant source files.