Rust embedded-HAL driver for the AHT20 temperature and humidity sensor.

Overview

AHT20-driver

crates.io crates.io API

Rust embedded-HAL driver for the AHT20 temperature and humidity sensor.

Blue Pill with AHT20 sensor

You can read my blog post AHT20 thermometer driver which details the creation of this driver.

Example

There is an example app for the Blue Pill board in the examples/blue_pill/ directory. You can run that with cargo run --release. It will read the temperature and humidity and print it the console.

How to use

Using the AHT20 driver in your own project should be possible with any platform that supports the embedded-HAL. See awesome-embedded-rust for a list of supported platforms. I've used this driver with the stm32f103, aka. the Blue Pill board.

In order to use the aht20-driver you'll need to configure an I2C device that implements the embedded HAL blocking I2C traits. You'll also need a delay device that implements the embedded HAL blocking delay traits.

The example in this repository shows an example for the Blue Pill board. Once you have those configured - pass those to the AHT20::new method to create the device driver. You will need to call the init method on it, which will calibrate the sensor and return a new struct with methods for measuring and resetting the sensor.

Once calibrated you can call the measure method which will return a measurement containing temperature and humidity values in relative humidity %, and degrees Celsius.

// Configure the AHT20 temperature and humidity sensor.
let mut aht20_uninit = aht20_driver::AHT20::new(i2c, aht20_driver::SENSOR_ADDRESS);
let mut aht20 = aht20_uninit.init(&mut delay).unwrap();

// Take the temperature and humidity measurement.
let aht20_measurement = aht20.measure(&mut delay).unwrap();

rprintln!("temperature (aht20): {:.2}C", aht20_measurement.temperature);
rprintln!("humidity (aht20): {:.2}%", aht20_measurement.humidity);

Contributing

Please open an issue, start a conversation under discussions, or submit a pull request - all are welcome.

I'd love to know if you're using the driver, and I'd like to link to your projects so that others can learn from them.

License

aht20-driver is distributed under the terms of both the MIT License and the Apache License 2.0.

See the LICENSE-APACHE and LICENSE-MIT files for license details.

You might also like...
A stupid macro that compiles and executes Rust and spits the output directly into your Rust code

inline-rust This is a stupid macro inspired by inline-python that compiles and executes Rust and spits the output directly into your Rust code. There

This is a Discord bot written in Rust to translate to and from the Bottom Encoding Standard using bottom-rs and Serenity.
This is a Discord bot written in Rust to translate to and from the Bottom Encoding Standard using bottom-rs and Serenity.

bottom-bot This is a Discord bot written in Rust to translate to and from the Bottom Encoding Standard using bottom-rs and Serenity. Ever had this pro

lightweight and customizable rust s-expression (s-expr) parser and printer

s-expr Rust library for S-expression like parsing and printing parser keeps track of spans, and representation (e.g. number base) number and decimal d

Simplify temporary email management and interaction, including message retrieval and attachment downloads, using Rust.

Tempmail The Tempmail simplifies temporary email management and interaction, including message retrieval and attachment downloads, using the Rust prog

A library and tool for automata and formal languages, inspired by JFLAP
A library and tool for automata and formal languages, inspired by JFLAP

Sugarcubes is a library and application for automata and formal languages. It is inspired by JFLAP, and is intended to eventually to be an alternative to JFLAP.

An implementation of Code Generation and Factoring for Fast Evaluation of Low-order Spherical Harmonic Products and Squares

sh_product An implementation of Code Generation and Factoring for Fast Evaluation of Low-order Spherical Harmonic Products and Squares (paper by John

Crates Registry is a tool for serving and publishing crates and serving rustup installation in offline networks.
Crates Registry is a tool for serving and publishing crates and serving rustup installation in offline networks.

Crates Registry Description Crates Registry is a tool for serving and publishing crates and serving rustup installation in offline networks. (like Ver

First Git on Rust is reimplementation with rust in order to learn about rust, c and git.

First Git on Rust First Git on Rust is reimplementation with rust in order to learn about rust, c and git. Reference project This project refer to the

`Debug` in rust, but only supports valid rust syntax and outputs nicely formatted using pretty-please
`Debug` in rust, but only supports valid rust syntax and outputs nicely formatted using pretty-please

dbg-pls A Debug-like trait for rust that outputs properly formatted code Showcase Take the following code: let code = r#" [ "Hello, World!

Releases(v1.2.0)
  • v1.2.0(Mar 5, 2022)

    This release adds a measure_no_fp method, which does not use floating point. For microcontrollers which lack floating point support - this will prevent floating point functions from being linked in - making the binary smaller. It will also make the calculations faster for those microcontrollers.

    Thank you to u/snakehand for suggesting this, with an example.

    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Feb 22, 2022)

    This release switches from rtt logging to defmt. This enables logging from the library, and additionally saves about 30kb of flash space from the example binary, which is a significant saving.

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Feb 9, 2022)

Owner
Rikard Anglerud
I'm just a ghost in an autobiographical tragedy; too many lines and nothing to say.
Rikard Anglerud
Example of reading the BME280 sensor on an ESP32-C3 using Rust

Rust ESP32-C3 BME280 Example of reading the BME280 sensor on an ESP32-C3 using Rust Hardware: ESP32-C3 microcontroller BME280 sensor Breadboard Jump w

Wei-ying Chen 21 Mar 9, 2024
A basic rp2040-hal project with blinky and rtt logging example code.

A basic rp2040-hal project with blinky and rtt logging example code. With this you can quickly get started on a new rp2040 project

rp-rs 202 Jan 6, 2023
A Rust driver for the Arm Generic Interrupt Controller version 3 or 4 (GICv3 and GICv4).

Arm Generic Interrupt Controller driver This crate provides a Rust driver for the Arm Generic Interrupt Controller version 3 or 4 (GICv3 and GICv4). C

Google 7 Apr 17, 2023
Wojak quits his job at McDonalds and becomes a Takeaway driver.

DeliveryGuy ?? Summary This repo is a crypto cross-exchange arbitrage implementation in Rust. work for Binance | OKX | Bybit | GateIO | Kucoin How to

null 20 Oct 29, 2022
Rust driver for the Blues.io Notecard

Rust driver for notecard This is a rust driver for the blues.io notecard based on embedded-hal. use notecard::Note; let mut note = Note::new(i2c); no

Gaute Hope 5 Oct 12, 2022
`fugit` provides a comprehensive library of `Duration` and `Instant` for the handling of time in embedded systems, doing all it can at compile time.

fugit fugit provides a comprehensive library of Duration and Instant for the handling of time in embedded systems, doing all it can at compile time. T

Emil Fresk 40 Oct 2, 2022
cargo extension for flashing embedded rust programs via dfu based on jacobrosenthals cargo-hf2

cargo-dfu This crate provides a cargo subcommand to flash ELF binaries via dfu Most STM chips will probably work with this, although you might need to

Roman Kretschmer 0 Feb 6, 2022
OpenEMC: open embedded management controller

OpenEMC OpenEMC is an open-source firmware implementing an embedded management controller (EMC) on an STM32F1 microcontroller. It consists of a bootlo

Sebastian Urban 5 Dec 25, 2022
Embedded demo based on esp32-c3

wot-esp-demo Demo Hygro-Thermometer based on the esp-rust-board. http version based on std-training Deploy Rust prerequisites Install espflash, ldprox

null 3 Dec 1, 2023
A Rust proc-macro crate which derives functions to compile and parse back enums and structs to and from a bytecode representation

Bytecode A simple way to derive bytecode for you Enums and Structs. What is this This is a crate that provides a proc macro which will derive bytecode

null 4 Sep 3, 2022