A driver for the Sensirion SGP30 Indoor Air Quality sensor Datasheet
#include <freertos/FreeRTOS.h>
#include "sgp30.h"
static const char *TAG = "app_main";
static void measure(sgp30_handle_t *hdl) {
ESP_LOGI(TAG, "Initialize device");
ESP_ERROR_CHECK(sgp30_iaq_init(hdl));
ESP_LOGI(TAG, "The first 15s worth of data is always the same");
TickType_t prev_wake_time = xTaskGetTickCount();
while (1) {
uint16_t co2;
uint16_t tvoc;
xTaskDelayUntil(&prev_wake_time, pdMS_TO_TICKS(1000));
ESP_ERROR_CHECK(sgp30_measure_iaq(hdl, &co2, &tvoc));
ESP_LOGI(TAG, "CO2: %dppm, TVOC: %dppb", co2, tvoc);
}
}
void app_main(void) {
i2c_master_bus_config_t i2c_mst_config = {
.clk_source = I2C_CLK_SRC_DEFAULT,
.i2c_port = I2C_NUM_0,
.scl_io_num = 4,
.sda_io_num = 5,
.glitch_ignore_cnt = 7,
.flags.enable_internal_pullup = true,
};
i2c_master_bus_handle_t i2c_hdl;
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_mst_config, &i2c_hdl));
ESP_ERROR_CHECK(i2c_master_bus_reset(i2c_hdl));
sgp30_handle_t *hdl;
ESP_ERROR_CHECK(sgp30_new(&hdl, i2c_hdl));
vTaskDelay(pdMS_TO_TICKS(1000));
// measure_test(hdl);
measure(hdl);
}