[][src]Crate shtcx

Introduction

This is a platform agnostic Rust driver for the Sensirion SHTCx temperature / humidity sensor series, based on the embedded-hal traits.

Supported Devices

Tested with the following sensors:

Support for the SHTC1 will be added later on. Support for SHTWx should be doable as well, since the protocol seems to be very similar.

Blocking / Non-Blocking Modes

This driver currently uses only blocking calls. Non-blocking measurements may be added in the future. Clock stretching is not implemented and probably won't be.

The Device

The Sensirion SHTCx series offers low-power high-precision digital temperature and humidity sensors that communicate over the I²C bus.

Examples

There are two examples in the examples directory: The linux example queries the sensor a few times using linux-embedded-hal, while the monitor example implements a terminal based real-time graphical temperature/humidity monitoring tool.

gif

Usage

Setup

Instantiate a new driver instance using a blocking I²C HAL implementation and a blocking Delay instance. For example, using linux-embedded-hal:

use linux_embedded_hal::{Delay, I2cdev};
use shtcx::ShtCx;

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let address = 0x70; // SHTC3
let mut sht = ShtCx::new(dev, address, Delay);

Device Info

Then, you can query information about the sensor:

let device_id = sht.device_identifier().unwrap();
let raw_id = sht.raw_id_register().unwrap();

Measurements

For measuring your environment, you can either measure just temperature, just humidity, or both:

use shtcx::PowerMode;

let temperature = sht.measure_temperature(PowerMode::NormalMode).unwrap();
let humidity = sht.measure_humidity(PowerMode::NormalMode).unwrap();
let combined = sht.measure(PowerMode::NormalMode).unwrap();

println!("Temperature: {} °C", temperature.as_degrees_celsius());
println!("Humidity: {} %RH", humidity.as_percent());
println!("Combined: {} °C / {} %RH",
         combined.temperature.as_degrees_celsius(),
         combined.humidity.as_percent());

You can also use the low power mode for less power consumption, at the cost of reduced repeatability and accuracy of the sensor signals. For more information, see the "Low Power Measurement Mode" application note.

let measurement = sht.measure(PowerMode::LowPower).unwrap();

Sleep Mode

The sensor can be set to sleep mode when in idle state:

sht.sleep().unwrap();

When the sensor is in sleep mode, it requires the following wake-up command before any further communication.

sht.wakeup().unwrap();

Soft Reset

The SHTC3 provides a soft reset mechanism that forces the system into a well-defined state without removing the power supply. If the system is in its idle state (i.e. if no measurement is in progress) the soft reset command can be sent. This triggers the sensor to reset all internal state machines and reload calibration data from the memory.

sht.reset().unwrap();

Structs

Humidity

A humidity measurement.

Measurement

A combined temperature / humidity measurement.

ShtCx

Driver for the SHTCx sensor.

Temperature

A temperature measurement.

Enums

Error

All possible errors in this crate

PowerMode

Measurement power mode: Normal mode or low power mode.