# ScioSense CCS811 Sensor [](/LICENSE) [](https://visualstudio.microsoft.com) [](https://platformio.org/) [](https://registry.platformio.org/libraries/k0i05/esp_ccs811) [](https://components.espressif.com/components/k0i05/esp_ccs811) This ESP32 espressif IoT development framework (esp-idf) i2c peripheral driver was developed for the ScioSense CCS811 digital metal-oxide multi-gas sensor. Information on features and functionality are documented and can be found in the `ccs811.h` header file and in the `documentation` folder. ## Repository The component is hosted on github and is located here: <https://github.com/K0I05/ESP32-S3_ESP-IDF_COMPONENTS/tree/main/components/peripherals/i2c/esp_ccs811> ## General Usage To get started, simply copy the component to your project's `components` folder and reference the `ccs811.h` header file as an include. The component includes documentation for the peripheral such as the datasheet, application notes, and/or user manual where applicable. ```text components └── esp_ccs811 ├── CMakeLists.txt ├── README.md ├── LICENSE ├── idf_component.yml ├── library.json ├── documentation │ └── datasheets, etc. ├── include │ └── ccs811_version.h │ └── ccs811.h └── ccs811.c ``` ## Basic Example Once a driver instance is instantiated the sensor is ready for usage as shown in the below example. This basic implementation of the driver utilizes default configuration settings and makes a measurement request from the sensor at user defined interval and prints the results. ```c #include <ccs811.h> void i2c0_ccs811_task( void *pvParameters ) { // initialize the xLastWakeTime variable with the current time. TickType_t last_wake_time = xTaskGetTickCount (); // // initialize i2c device configuration ccs811_config_t dev_cfg = I2C_CCS811_CONFIG_DEFAULT; ccs811_handle_t dev_hdl; // // init device ccs811_init(i2c0_bus_hdl, &dev_cfg, &dev_hdl); if (dev_hdl == NULL) { ESP_LOGE(APP_TAG, "ccs811 handle init failed"); assert(dev_hdl); } // // task loop entry point for ( ;; ) { ESP_LOGI(APP_TAG, "######################## CCS811 - START #########################"); // // handle sensor uint16_t eco2; uint16_t etvoc; esp_err_t result = ccs811_get_measurement(dev_hdl, &eco2, &etvoc); if(result != ESP_OK) { ESP_LOGE(APP_TAG, "i2c0 i2c_ccs811_get_measurement failed: %s", esp_err_to_name(result)); } else { ESP_LOGI(APP_TAG, "eCO2 value: %d ppm", eco2); ESP_LOGI(APP_TAG, "eTVOC value: %d ppb", etvoc); } // ESP_LOGI(APP_TAG, "######################## CCS811 - END ###########################"); // // // pause the task per defined wait period vTaskDelaySecUntil( &last_wake_time, I2C0_TASK_SAMPLING_RATE ); } // // free resources ccs811_delete( dev_hdl ); vTaskDelete( NULL ); } ``` Copyright (c) 2024 Eric Gionet (<gionet.c.eric@gmail.com>)
idf.py add-dependency "k0i05/esp_ccs811^1.1.7"