MH-Z19 CO2 sensor driver.
More...
MH-Z19 CO2 sensor driver.
Description
The MH-Z19 is a CO2 sensor. Measurements are provided in parts per million (ppm) over UART and PWM. The ppm value ranges from 0 (theoretically) to 2000 or 5000, depending on the sensor settings.
In UART mode, additional commands are available to configure the sensor.
Note that the sensor requires considerable time before accurate measurements are provided.
|
file | mhz19.h |
| Interface definition for the MH-Z19 CO2 sensor driver.
|
|
file | mhz19_internals.h |
| Internal addresses, registers, constants for the MH-Z19 CO2 sensor.
|
|
file | mhz19_params.h |
| Default configuration for MH-Z19.
|
|
◆ anonymous enum
Status and error return codes.
Enumerator |
---|
MHZ19_OK | everything was fine
|
MHZ19_ERR_INIT | error initializing the device
|
MHZ19_ERR_TIMEOUT | timeout on retrieving sensor data
|
MHZ19_ERR_CHECKSUM | checksum failure on received data
|
Definition at line 62 of file mhz19.h.
◆ mhz19_get_ppm()
int mhz19_get_ppm |
( |
mhz19_t * |
dev, |
|
|
int16_t * |
ppm |
|
) |
| |
Get measured CO2 ppm value.
- Parameters
-
[in] | dev | device descriptor |
[out] | ppm | int16_t buffer where CO2 measurement will be written to, in ppm |
- Returns
- MHZ19_OK
-
MHZ19_ERR_TIMEOUT
-
MHZ19_ERR_CHECKSUM
◆ mhz19_init()
int mhz19_init |
( |
mhz19_t * |
dev, |
|
|
const mhz19_params_t * |
params |
|
) |
| |
Initialize a MH-Z19 device.
- Parameters
-
[out] | dev | device descriptor |
[in] | params | MH-Z19 initialization struct |
- Returns
- MHZ19_OK
-
MHZ19_ERR_INIT