How to: CO2 Module

With CO2 Module you can easily measure the concentration of carbon dioxide.

It is low power device which can be used with battery power. Remember that the device can require calibration and to get best results it has to be in active state for few days.

How It Works

Technically it uses infrared light for measurements. More information on Wikipedia

And how it works within the SDK? As any other TOWER module. There are init, periodical + manual measurements and calibration functions available in the SDK

Recognizable CO2 Module Events

For now there are just two events - error and update.

  • TWR_MODULE_CO2_EVENT_ERROR

  • TWR_MODULE_CO2_EVENT_UPDATE

Usage

You can measure the CO2 level manually or periodically. Every measure can trigger function within event handler.

To set periodic measurements, just use this function in your application_init: twr_module_co2_set_update_interval(twr_tick_t interval). interval is time between measurements, in milliseconds.

To make a manual measurement, just use twr_module_co2_measure(void).

To get CO2 concentration from last measurement you have to use this function: twr_module_co2_get_concentration_ppm(float *ppm).

Example

In this example, CO2 levels will be measured and sent to computer every time button is pressed.

 1#include <application.h>
 2
 3twr_button_t button;
 4
 5void button_event_handler(twr_button_t *self, twr_button_event_t event, void *event_param)
 6{
 7    (void) self;
 8    (void) event_param;
 9
10    float ppm = 0.0;
11
12    if (event == TWR_BUTTON_EVENT_PRESS)
13    {
14        twr_module_co2_measure();
15        twr_module_co2_get_concentration_ppm(&ppm);
16
17        twr_log_debug("CO2 level: %.4fppm", ppm);
18    }
19}
20
21void application_init(void)
22{
23    twr_log_init(TWR_LOG_LEVEL_DEBUG, TWR_LOG_TIMESTAMP_ABS);
24
25    twr_module_co2_init();
26
27    twr_button_init(&button, TWR_GPIO_BUTTON, TWR_GPIO_PULL_DOWN, false);
28    twr_button_set_event_handler(&button, button_event_handler, NULL);
29}