Expand description
§MH-Z* CO2 sensor driver
MH-Z* family CO2 sensor driver built on top of embedded-hal primitives.
This is a no_std crate suitable for use on bare-metal.
§Usage
The Sensor struct exposes methods to
send commands (write_packet_op)
to the sensor and to read the response(read_packet_op).
§Example
use mh_zx_driver::{commands, Sensor, Measurement};
use nb::block;
use core::convert::TryInto;
let mut sensor = Sensor::new(uart);
// Send command to the sensor.
{
let mut op = sensor.write_packet_op(commands::READ_CO2);
block!(op()).unwrap();
};
// Read the response.
let mut packet = Default::default();
{
let mut op = sensor.read_packet_op(&mut packet);
block!(op()).unwrap();
}
let meas: Measurement = packet.try_into().unwrap();
println!("CO2 concentration: {}", meas.co2);§Future support
The experimental support for async/await can be activated by enabling the async feature in Cargo.toml.
It adds async methods to the Sensor struct.
Modules§
Structs§
- Invalid
Response - Measurement
- A struct representing measurement data returned by sensor as a response to
the
READ_CO2command. - Packet
- A wrapper for payload (9 bytes) sent/received by sensor hardware with some utility methods.
- RawMeasurement
- A struct representing raw CO2 data returned by sensor as a response to
the
READ_RAW_CO2command. - Sensor
- A struct representing sensor interface.
- Uart
Wrapper