Expand description
AHT20 driver.
Example:
let mut aht20_uninit = AHT20::new(mock_i2c, SENSOR_ADDRESS);
let mut aht20 = aht20_uninit.init(&mut mock_delay).unwrap();
let measurement = aht20.measure(&mut mock_delay).unwrap();
println!("temperature (aht20): {:.2}C", measurement.temperature);
println!("humidity (aht20): {:.2}%", measurement.humidity);
aht20_uninit.destroy().done();
Note that the datasheet linked directly from the manufacturer’s website Aogong AHT20 is an older datasheet (version 1.0, rather than version 1.1 as linked above) and is significantly more difficult to understand. I recommend reading version 1.1. All section references in this file are to the 1.1 version.
The below is a flowchart of how the sensor gets initialized and measurements taken. Note that the flowchart does not include the parameters that you need to give to some commands, and it also doesn’t include the SoftReset command flow.
Start (Power on)
│
▼
Wait 40 ms
│
▼
Read status byte ◄─── Wait 10 ms
│ ▲
▼ │
Status::Calibrated ──► No ──► Command::Initialize (0xBE)
│
▼
Yes
│
▼
Command::TriggerMeasurement (0xAC) ◄─┐
│ │
▼ │
Wait 80 ms │
│ │
▼ │
Read status byte ◄──┐ │
│ │ │
▼ │ │
Status::Busy ───► Yes │
│ │
▼ │
No │
│ │
▼ │
Read 7 bytes │
│ │
▼ │
Calculate CRC │
│ │
▼ │
CRC good ─► No ─────────┘
│ ▲
▼ │
Yes │
│ │
▼ │
CRC-checked Ready ─► No ─────┘
│
▼
Yes
│
▼
Calc Humidity and Temp
Structs§
- AHT20
- An AHT20 sensor on the I2C bus
I
. - AHT20
Initialized - AHT20Initialized is returned by AHT20::init() and the sensor is ready to read from.
- Sensor
Reading - SensorReading is a single reading from the AHT20 sensor.
- Sensor
Status - SensorStatus is the response from the sensor indicating if it is ready to read from, and if it is calibrated.
Enums§
Constants§
- SENSOR_
ADDRESS - AHT20 sensor’s I2C address.