[][src]Crate hdc1080

This is a platform agnostic Rust driver for the HDC1080 temperature sensor and thermal watchdog, based on the I2CDevice traits.

This driver allows you to:

  • Read the temperature.
  • Read the relative humidity.
  • Read both temperature and humidity.
  • Test low battery condition.
  • Set temperature resolution.
  • Set humidity resolution.
  • Set heater on/off.
  • Reset device.

The device

The HDC1080 is a digital humidity sensor with integrated temperature sensor. The host can query the HDC1080 through its I2C interface to start a temperature and/or humidity reading at any time.

Datasheet:

Usage examples (see also examples folder)

To use this driver, import this crate and an I2CDevice implementation, then instantiate the device.

Read temperature

extern crate i2cdev;
extern crate hdc1080;

use i2cdev::linux::LinuxI2CDevice;
use std::{thread, time};
use hdc1080::{Config, Hdc1080};

const HDC1080_SLAVE_ADDR: u16 = 0x40;

let dev = LinuxI2CDevice::new("/dev/i2c-0", HDC1080_SLAVE_ADDR).unwrap();
let mut sensor = Hdc1080::new(dev);
sensor.read_temperature_start().unwrap();
thread::sleep(time::Duration::from_millis(500u64));
let temp_celsius = sensor.read_temperature_finish().unwrap();
println!("Temperature: {}ºC", temp_celsius);

Read relative humidity

extern crate i2cdev;
extern crate hdc1080;

use i2cdev::linux::LinuxI2CDevice;
use std::{thread, time};
use hdc1080::{Config, Hdc1080};

const HDC1080_SLAVE_ADDR: u16 = 0x40;

let dev = LinuxI2CDevice::new("/dev/i2c-0", HDC1080_SLAVE_ADDR).unwrap();
let mut sensor = Hdc1080::new(dev);
sensor.read_humidity_start().unwrap();
thread::sleep(time::Duration::from_millis(500u64));
let humidity = sensor.read_humidity_finish().unwrap();
println!("Temperature: {}ºC", humidity);

Read temperature and relative humidity in sequence

extern crate i2cdev;
extern crate hdc1080;

use i2cdev::linux::LinuxI2CDevice;
use std::{thread, time};
use hdc1080::{Config, Hdc1080, Mode};

const HDC1080_SLAVE_ADDR: u16 = 0x40;

let dev = LinuxI2CDevice::new("/dev/i2c-0", HDC1080_SLAVE_ADDR).unwrap();
let mut sensor = Hdc1080::new(dev);
let mut config: Config = hdc1080::Config::default();
config.set_mode(Mode::TAndH);
sensor.write_config(config).unwrap();
sensor.read_temperature_start().unwrap();
thread::sleep(time::Duration::from_millis(500u64));
let (temp,humidity) = sensor.read_temperature_humidity_finish().unwrap();
println!("Temperature: {}ºC, Humidity: {}RH", temp,humidity);

Structs

Config

Config register content to be sent

Hdc1080

Hdc1080 device driver.

Enums

Error

All possible errors in this crate

HResolution

Resolution of humidity

HeaterMode

Heater operation mode

Mode

Heater operation mode

TResolution

Resolution of temperature