Crate ahtx0

Crate ahtx0 

Source
Expand description

§Introduction

This is an async implementation of the ATH10 and ATH20 thermo-hygro sensor that relies on hardware abstraction crates for platform agnosticism. It supports asyncronous using executors such as tokio or Embassy.

§Supported Devices

This has been tested with the Adafruit AHT20 breakout board using the STEMMA QT/Qwiic connection standard.

§Asynchronous

This driver is based in part on the excellent shtcx-rs crate. However, while the shtcx-rs crate includes non-blocking and clocking methods this crate provides only async methods. There is a blocking version available on crates.io: adafruit-aht10.

§Usage

Providing an instance of a Delay type is required for most operations blocking variant requires a blocking Delay type that can be wated upon for processing time required in the sensor. In the async variant, an async Timer type must be provided.

An example for the async version follows:

use ahtx0::ahtx0;
use linux_embedded_hal::{Delay, I2cdev};
use tokio;

// You're going to need some kind of executor here, either embassy or tokio
#[tokio::main]
async fn main() {
    let i2c0 = I2cdev::new("/dev/i2c-3").unwrap();
    let mut delay = Delay;
    let mut aht = ahtx0(i2c0);

    // We don't care that much if calibration failed
    let _ = aht.calibrate(&mut delay).await;

    // To query the device state from the sensor:
    let device_id = aht.state().await.unwrap();

    // and, finally to get the current sensor values:
    let measurement = aht.measure(&mut delay).await;
}

The destroy method shouldn’t be needed in normal circumstances, but it can be useful when using a mock because it’ll return the i2c device back, which allows the done() method to be called on it.

§Acknowledgements

Many thanks to the authors of the shtcx-rs, and to the team at Adafruit who wrote the python implementation. Both were very helpful in getting started with this.

Modules§

blocking
types

Structs§

AHTx0

Enums§

Error

Functions§

ahtx0