https://github.com/mauriciobarroso/sgia
ESP-IDF component for Sensirion Gas Index Algorithm
https://github.com/mauriciobarroso/sgia
air-quality esp-idf esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 gas-index i2c nox sensirion sgp41 sht4x voc
Last synced: 19 days ago
JSON representation
ESP-IDF component for Sensirion Gas Index Algorithm
- Host: GitHub
- URL: https://github.com/mauriciobarroso/sgia
- Owner: mauriciobarroso
- License: mit
- Created: 2023-12-17T19:11:08.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-04T02:45:12.000Z (12 months ago)
- Last Synced: 2025-02-15T07:41:01.893Z (2 months ago)
- Topics: air-quality, esp-idf, esp32, esp32c2, esp32c3, esp32c6, esp32h2, esp32s2, esp32s3, gas-index, i2c, nox, sensirion, sgp41, sht4x, voc
- Language: C
- Homepage:
- Size: 32.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ESP-IDF SGIA (Sensirion Gas Index Algorithm) Component
ESP-IDF component for Sensirion Gas Index Algorithm based on [Sensirion Gas Index Algorithm](https://github.com/Sensirion/gas-index-algorithm)## Dependencies
This component only works with [ESP-IDF v5.2](https://github.com/espressif/esp-idf/tree/release/v5.2) or higher.The gas index algorithm depends on the values obtained from the SGP41 and SHT4x sensors. The ESP-IDF components of these sensors are available at the following links:
- [SGP41 ESP-IDF component](https://github.com/mauriciobarroso/sgp41)
- [SHT4x ESP-IDF component](https://github.com/mauriciobarroso/sht4x)## How to use
1. Include the I2C driver and component headers
```c
#include "driver/i2c_master.h"
#include "sgia.h"
```
2. Declare a handle of I2C bus and an instance of SGIA
```c
i2c_master_bus_handle_t i2c_bus_handle;
sgia_t button1;
```3. Define a RTOS task to run SGIA process
```c
void sgia_process_task(void *arg) {
int32_t voc_index, nox_index;
float temp, hum;
for (;;) {
/* Run SGIA process */
ESP_ERROR_CHECK(sgia_run(&sgia));/* Get and print VOC and NOx indices */
sgia_get_index_voc_and_nox(&sgia, &voc_index, &nox_index);
printf("VOC index: %ld\tNOx index: %ld\r\n", sgia.voc_index, sgia.nox_index);/* Get and print temperature and humidity values */
sgia_get_temp_and_hum(&sgia, &temp, &hum);
printf("Temperature: %f\tHumidity: %f\r\n\n", sgia.temp, sgia.hum);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
```4. Configure and create a new I2C bus
```c
/* Configure and create a new I2C bus */
i2c_master_bus_config_t i2c_bus_config = {
.clk_source = I2C_CLK_SRC_DEFAULT,
.i2c_port = I2C_NUM_0,
.scl_io_num = GPIO_NUM_48,
.sda_io_num = GPIO_NUM_47,
.glitch_ignore_cnt = 7
};ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_config, &i2c_bus_handle));
```5. Initialize SGIA instance
```c
/* Initialize SGIA instance */
sgia_init(&sgia, i2c_bus_handle);
```6. Create the RTOS task defined in 3
```c
xTaskCreate(
sgia_process_task, /* Task code */
"BSEC Task", /* Task name */
configMINIMAL_STACK_SIZE * 4, /* Task stack depth */
NULL, /* Task parameter */
tskIDLE_PRIORITY + 2, /* Task priority */
NULL); /* Task handle */
```## License
MIT LicenseCopyright (c) 2023 Mauricio Barroso Benavides
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.