[][src]Crate hdc20xx

This is a platform agnostic Rust driver for the HDC2080, HDC2021 and HDC2010 low-power humidity and temperature digital sensor using the embedded-hal traits.

This driver allows you to:

The devices

The HDC2080 device is an integrated humidity and temperature sensor that provides high accuracy measurements with very low power consumption in a small DFN package. The capacitive-based sensor includes new integrated digital features and a heating element to dissipate condensation and moisture.

The HDC2080 digital features include programmable interrupt thresholds to provide alerts and system wake-ups without requiring a microcontroller to be continuously monitoring the system. Combined with programmable sampling intervals, a low power consumption, and a support for a 1.8-V supply voltage, the HDC2080 is designed for battery-operated systems.

This driver is compatible with HDC2080, HDC2021 and HDC2010.

Datasheets: HDC2080, HDC2021, HDC2010

Usage examples (see also examples folder)

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

Please find additional examples using hardware in this repository: driver-examples

Make a one-shot temperature and humidity measurement

extern crate linux_embedded_hal as hal;
use hdc20xx::{Hdc20xx, SlaveAddr};
use nb::block;
 
let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
let address = SlaveAddr::default();
let mut sensor = Hdc20xx::new(dev, address);
loop {
    let data = block!(sensor.read()).unwrap();
    println!(
        "Temperature: {:2}°C, Humidity: {:2}%",
        data.temperature,
        data.humidity.unwrap()
    );
}

Use an alternative address

extern crate linux_embedded_hal as hal;
use hdc20xx::{Hdc20xx, SlaveAddr};
 
let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
let address = SlaveAddr::Alternative(true);
let sensor = Hdc20xx::new(dev, address);

Configure measuring only the temperature

extern crate linux_embedded_hal as hal;
use hdc20xx::{Hdc20xx, MeasurementMode, SlaveAddr};
 
let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
let address = SlaveAddr::default();
let mut sensor = Hdc20xx::new(dev, address);
sensor.set_measurement_mode(MeasurementMode::TemperatureOnly).unwrap();

Read the manufacturer and device ID

extern crate linux_embedded_hal as hal;
use hdc20xx::{Hdc20xx, SlaveAddr};
 
let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
let address = SlaveAddr::default();
let mut sensor = Hdc20xx::new(dev, address);
let manuf_id = sensor.manufacturer_id().unwrap();
let dev_id = sensor.device_id().unwrap();
println!(
    "Manufacturer ID: {}, Device ID: {}",
    manuf_id, dev_id
);

Read the data and interrupt status

extern crate linux_embedded_hal as hal;
use hdc20xx::{Hdc20xx, SlaveAddr};
 
let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
let address = SlaveAddr::default();
let mut sensor = Hdc20xx::new(dev, address);
let status = sensor.status().unwrap();
println!("Status: {:?}", status);

Modules

mode

Mode marker

Structs

Hdc20xx

HDC2080, HDC2021 and HDC2010 device driver

Measurement

Measurement result

Status

Status

Enums

Error

All possible errors in this crate

MeasurementMode

Measurement mode

SlaveAddr

Possible slave addresses