- small corrections
- changes to use the same source code with ESP8266 (esp-open-rtos) and ESP32 (ESP-IDF)
This commit is contained in:
parent
c3ae04c93f
commit
f0425e7abd
9 changed files with 251 additions and 138 deletions
|
@ -9,8 +9,8 @@ Most examples use only one CCS811 sensor. Following figure shows the hardware co
|
||||||
```
|
```
|
||||||
+------------------------+ +--------+
|
+------------------------+ +--------+
|
||||||
| ESP8266 Bus 0 | | CCS811 |
|
| ESP8266 Bus 0 | | CCS811 |
|
||||||
| GPIO 5 (SCL) >----> SCL |
|
| GPIO 5 (SCL) -----> SCL |
|
||||||
| GPIO 4 (SDA) ------ SDA |
|
| GPIO 4 (SDA) <----> SDA |
|
||||||
| GND -----> /WAKE |
|
| GND -----> /WAKE |
|
||||||
+------------------------+ +--------+
|
+------------------------+ +--------+
|
||||||
```
|
```
|
||||||
|
@ -20,8 +20,8 @@ If *nINT* interrupt is used to fetch new data, additionally the interrupt pin ha
|
||||||
```
|
```
|
||||||
+------------------------+ +--------+
|
+------------------------+ +--------+
|
||||||
| ESP8266 Bus 0 | | CCS811 |
|
| ESP8266 Bus 0 | | CCS811 |
|
||||||
| GPIO 5 (SCL) >----> SCL |
|
| GPIO 5 (SCL) -----> SCL |
|
||||||
| GPIO 4 (SDA) ------ SDA |
|
| GPIO 4 (SDA) <----> SDA |
|
||||||
| GPIO 2 <----- /nINT |
|
| GPIO 2 <----- /nINT |
|
||||||
| GND -----> /WAKE |
|
| GND -----> /WAKE |
|
||||||
+------------------------+ +--------+
|
+------------------------+ +--------+
|
||||||
|
@ -32,13 +32,13 @@ In examples where CCS811 sensor is used in conjunction with a SHT3x sensor, the
|
||||||
```
|
```
|
||||||
+------------------------+ +--------+
|
+------------------------+ +--------+
|
||||||
| ESP8266 Bus 0 | | CCS811 |
|
| ESP8266 Bus 0 | | CCS811 |
|
||||||
| GPIO 5 (SCL) >--+----> SCL |
|
| GPIO 5 (SCL) ---+----> SCL |
|
||||||
| GPIO 4 (SDA) ---|-+--- SDA |
|
| GPIO 4 (SDA) <--|-+--> SDA |
|
||||||
| GND ---|-|--> /WAKE |
|
| GND ---|-|--> /WAKE |
|
||||||
| | | | +--------+
|
| | | | +--------+
|
||||||
| | | | | SHT3x |
|
| | | | | SHT3x |
|
||||||
| | +----> SCL |
|
| | +----> SCL |
|
||||||
| | +--- SDA |
|
| | +--> SDA |
|
||||||
+------------------------+ +--------+
|
+------------------------+ +--------+
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -6,40 +6,57 @@
|
||||||
*
|
*
|
||||||
* Harware configuration:
|
* Harware configuration:
|
||||||
*
|
*
|
||||||
* +------------------------+ +--------+
|
* +-----------------+ +----------+
|
||||||
* | ESP8266 Bus 0 | | CCS811 |
|
* | ESP8266 / ESP32 | | CCS811 |
|
||||||
* | GPIO 5 (SCL) >----> SCL |
|
* | | | |
|
||||||
* | GPIO 4 (SDA) ------ SDA |
|
* | GPIO 14 (SCL) ----> SCL |
|
||||||
* | GPIO 2 <----- /nINT |
|
* | GPIO 13 (SDA) <---> SDA |
|
||||||
* | GND -----> /WAKE |
|
* | GPIO 5 <---- INT1 |
|
||||||
* +------------------------+ +--------+
|
* | GND ----> /WAKE |
|
||||||
|
* +-----------------+ +----------+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// use following constants to define the demo mode
|
/* -- use following constants to define the example mode ----------- */
|
||||||
|
|
||||||
// #define INT_DATA_RDY_USED
|
// #define INT_DATA_RDY_USED
|
||||||
// #define INT_THRESHOLD_USED
|
// #define INT_THRESHOLD_USED
|
||||||
|
|
||||||
#include "espressif/esp_common.h"
|
#if defined(INT_DATA_RDY_USED) || defined(INT_THRESHOLD_USED)
|
||||||
#include "esp/uart.h"
|
#define INT_USED
|
||||||
#include "i2c/i2c.h"
|
#endif
|
||||||
|
|
||||||
#include "FreeRTOS.h"
|
/* -- includes ----------------------------------------------------- */
|
||||||
#include <task.h>
|
|
||||||
|
|
||||||
// include CCS811 driver
|
#include "ccs811.h"
|
||||||
#include "ccs811/ccs811.h"
|
|
||||||
|
|
||||||
// define I2C interfaces at which CCS811 sensors can be connected
|
/* -- platform dependent definitions ------------------------------- */
|
||||||
|
|
||||||
|
#ifdef ESP_PLATFORM // ESP32 (ESP-IDF)
|
||||||
|
|
||||||
|
// user task stack depth for ESP32
|
||||||
|
#define TASK_STACK_DEPTH 2048
|
||||||
|
|
||||||
|
#else // ESP8266 (esp-open-rtos)
|
||||||
|
|
||||||
|
// user task stack depth for ESP8266
|
||||||
|
#define TASK_STACK_DEPTH 256
|
||||||
|
|
||||||
|
#endif // ESP_PLATFORM
|
||||||
|
|
||||||
|
// I2C interface defintions for ESP32 and ESP8266
|
||||||
#define I2C_BUS 0
|
#define I2C_BUS 0
|
||||||
#define I2C_SCL_PIN 5
|
#define I2C_SCL_PIN 14
|
||||||
#define I2C_SDA_PIN 4
|
#define I2C_SDA_PIN 13
|
||||||
|
#define I2C_FREQ I2C_FREQ_100K
|
||||||
|
|
||||||
// define GPIO for interrupt
|
// interrupt GPIOs defintions for ESP8266 and ESP32
|
||||||
#define INT_GPIO 2
|
#define nINT_PIN 13
|
||||||
|
|
||||||
|
/* -- user tasks --------------------------------------------------- */
|
||||||
|
|
||||||
static ccs811_sensor_t* sensor;
|
static ccs811_sensor_t* sensor;
|
||||||
|
|
||||||
#if defined(INT_DATA_RDY_USED) || defined(INT_THRESHOLD_USED)
|
#ifdef INT_USED
|
||||||
/**
|
/**
|
||||||
* In this example, the interrupt *nINT* is used. It is triggered every time
|
* In this example, the interrupt *nINT* is used. It is triggered every time
|
||||||
* new data are available (INT_DATA_RDY_USED) or exceed defined thresholds
|
* new data are available (INT_DATA_RDY_USED) or exceed defined thresholds
|
||||||
|
@ -73,12 +90,12 @@ void user_task_interrupt (void *pvParameters)
|
||||||
|
|
||||||
// Interrupt handler which resumes user_task_interrupt on interrupt
|
// Interrupt handler which resumes user_task_interrupt on interrupt
|
||||||
|
|
||||||
void nINT_handler (uint8_t gpio)
|
static void IRAM nINT_handler(uint8_t gpio)
|
||||||
{
|
{
|
||||||
xTaskResumeFromISR (nINT_task);
|
xTaskResumeFromISR (nINT_task);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else // !INT_USED
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* In this example, user task fetches the sensor values every seconds.
|
* In this example, user task fetches the sensor values every seconds.
|
||||||
|
@ -106,20 +123,21 @@ void user_task_periodic(void *pvParameters)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif // INT_USED
|
||||||
|
|
||||||
|
/* -- main program ------------------------------------------------- */
|
||||||
|
|
||||||
void user_init(void)
|
void user_init(void)
|
||||||
{
|
{
|
||||||
// set UART Parameter
|
// Set UART Parameter.
|
||||||
uart_set_baud(0, 115200);
|
uart_set_baud(0, 115200);
|
||||||
// give the UART some time to settle
|
// Give the UART some time to settle
|
||||||
sdk_os_delay_us(500);
|
vTaskDelay(1);
|
||||||
|
|
||||||
/** -- MANDATORY PART -- */
|
/** -- MANDATORY PART -- */
|
||||||
|
|
||||||
// init all I2C bus interfaces at which CCS811 sensors are connected
|
// init all I2C bus interfaces at which CCS811 sensors are connected
|
||||||
i2c_init (I2C_BUS, I2C_SCL_PIN, I2C_SDA_PIN, I2C_FREQ_100K);
|
i2c_init (I2C_BUS, I2C_SCL_PIN, I2C_SDA_PIN, I2C_FREQ);
|
||||||
|
|
||||||
// longer clock stretching is required for CCS811
|
// longer clock stretching is required for CCS811
|
||||||
i2c_set_clock_stretch (I2C_BUS, CCS811_I2C_CLOCK_STRETCH);
|
i2c_set_clock_stretch (I2C_BUS, CCS811_I2C_CLOCK_STRETCH);
|
||||||
|
@ -129,28 +147,29 @@ void user_init(void)
|
||||||
|
|
||||||
if (sensor)
|
if (sensor)
|
||||||
{
|
{
|
||||||
#if defined(INT_DATA_RDY_USED) || defined(INT_THRESHOLD_USED)
|
#if !defined (INT_USED)
|
||||||
|
|
||||||
|
// create a periodic task that uses the sensor
|
||||||
|
xTaskCreate(user_task_periodic, "user_task_periodic", TASK_STACK_DEPTH, NULL, 2, NULL);
|
||||||
|
|
||||||
|
#else // INT_USED
|
||||||
|
|
||||||
// create a task that is resumed by interrupt handler to use the sensor
|
// create a task that is resumed by interrupt handler to use the sensor
|
||||||
xTaskCreate(user_task_interrupt, "user_task_interrupt", 256, NULL, 2, &nINT_task);
|
xTaskCreate(user_task_interrupt, "user_task_interrupt", TASK_STACK_DEPTH, NULL, 2, &nINT_task);
|
||||||
|
|
||||||
// activate the interrupt for INT_GPIO and set the interrupt handler
|
// activate the interrupt for nINT_PIN and set the interrupt handler
|
||||||
gpio_set_interrupt(INT_GPIO, GPIO_INTTYPE_EDGE_NEG, nINT_handler);
|
gpio_enable(nINT_PIN, GPIO_INPUT);
|
||||||
|
gpio_set_interrupt(nINT_PIN, GPIO_INTTYPE_EDGE_NEG, nINT_handler);
|
||||||
|
|
||||||
#ifdef INT_DATA_RDY_USED
|
#ifdef INT_DATA_RDY_USED
|
||||||
// enable the data ready interrupt
|
// enable the data ready interrupt
|
||||||
ccs811_enable_interrupt (sensor, true);
|
ccs811_enable_interrupt (sensor, true);
|
||||||
#else
|
#else // INT_THRESHOLD_USED
|
||||||
// set threshold parameters and enable threshold interrupt mode
|
// set threshold parameters and enable threshold interrupt mode
|
||||||
ccs811_set_eco2_thresholds (sensor, 600, 1100, 40);
|
ccs811_set_eco2_thresholds (sensor, 600, 1100, 40);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#endif // !defined(INT_USED)
|
||||||
|
|
||||||
// create a periodic task that uses the sensor
|
|
||||||
xTaskCreate(user_task_periodic, "user_task_periodic", 256, NULL, 2, NULL);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// start periodic measurement with one measurement per second
|
// start periodic measurement with one measurement per second
|
||||||
ccs811_set_mode (sensor, ccs811_mode_1s);
|
ccs811_set_mode (sensor, ccs811_mode_1s);
|
||||||
|
|
|
@ -6,13 +6,13 @@
|
||||||
*
|
*
|
||||||
* +------------------------+ +--------+
|
* +------------------------+ +--------+
|
||||||
* | ESP8266 Bus 0 | | CCS811 |
|
* | ESP8266 Bus 0 | | CCS811 |
|
||||||
* | GPIO 5 (SCL) >--+----> SCL |
|
* | GPIO 14 (SCL) ---+----> SCL |
|
||||||
* | GPIO 4 (SDA) ---|-+--- SDA |
|
* | GPIO 13 (SDA) <--|-+--> SDA |
|
||||||
* | GND ---|-|--> /WAKE |
|
* | GND ---|-|--> /WAKE |
|
||||||
* | | | | +--------+
|
* | | | | +--------+
|
||||||
* | | | | | SHT3x |
|
* | | | | | SHT3x |
|
||||||
* | | +----> SCL |
|
* | | +----> SCL |
|
||||||
* | | +--- SDA |
|
* | | +--> SDA |
|
||||||
* +------------------------+ +--------+
|
* +------------------------+ +--------+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -31,8 +31,8 @@
|
||||||
|
|
||||||
// define I2C interfaces at which CCS811 and SHT3x sensors are connected
|
// define I2C interfaces at which CCS811 and SHT3x sensors are connected
|
||||||
#define I2C_BUS 0
|
#define I2C_BUS 0
|
||||||
#define I2C_SCL_PIN 5
|
#define I2C_SCL_PIN 14
|
||||||
#define I2C_SDA_PIN 4
|
#define I2C_SDA_PIN 13
|
||||||
|
|
||||||
static ccs811_sensor_t* ccs811; // CCS811 device data structure
|
static ccs811_sensor_t* ccs811; // CCS811 device data structure
|
||||||
static sht3x_sensor_t* sht3x; // SHT3x device data structure
|
static sht3x_sensor_t* sht3x; // SHT3x device data structure
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
*
|
*
|
||||||
* +------------------------+ +--------+
|
* +------------------------+ +--------+
|
||||||
* | ESP8266 Bus 0 | | CCS811 |
|
* | ESP8266 Bus 0 | | CCS811 |
|
||||||
* | GPIO 5 (SCL) >----> SCL |
|
* | GPIO 14 (SCL) >----> SCL |
|
||||||
* | GPIO 4 (SDA) ------ SDA |
|
* | GPIO 13 (SDA) <----> SDA |
|
||||||
* | GND -----> /WAKE |
|
* | GND -----> /WAKE |
|
||||||
* +------------------------+ +--------+
|
* +------------------------+ +--------+
|
||||||
*/
|
*/
|
||||||
|
@ -27,8 +27,8 @@
|
||||||
|
|
||||||
// define I2C interfaces at which CCS811 sensors can be connected
|
// define I2C interfaces at which CCS811 sensors can be connected
|
||||||
#define I2C_BUS 0
|
#define I2C_BUS 0
|
||||||
#define I2C_SCL_PIN 5
|
#define I2C_SCL_PIN 14
|
||||||
#define I2C_SDA_PIN 4
|
#define I2C_SDA_PIN 13
|
||||||
|
|
||||||
|
|
||||||
static ccs811_sensor_t* sensor;
|
static ccs811_sensor_t* sensor;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# Driver for the ams CCS811 digital gas sensor for monitoring indoor air quality.
|
# Driver for the ams CCS811 digital gas sensor for monitoring indoor air quality.
|
||||||
|
|
||||||
This driver is written for usage with the ESP8266 and FreeRTOS using the I2C interface driver.
|
The driver is for the usage with the ESP8266 and [esp-open-rtos](https://github.com/SuperHouse/esp-open-rtos).
|
||||||
|
|
||||||
|
It is also working with ESP32 and [ESP-IDF](https://github.com/espressif/esp-idf.git) using a wrapper component for ESP8266 functions, see folder ```components/esp8266_wrapper```, as well as Linux based systems using a wrapper library.
|
||||||
|
|
||||||
## About the sensor
|
## About the sensor
|
||||||
|
|
||||||
|
@ -32,7 +34,7 @@ After power up, the sensor starts automatically in *Idle, Low Current Mode* (```
|
||||||
|
|
||||||
**Please note:** In *Constant Power Mode* with measurements every 250 ms (```mode_250ms```) only raw data are available. In all other measurement modes, the Indoor Air Quality (IAQ) values are available additionally. The *Constant Power Mode* with measurements every 250 ms (```mode_250ms```) is only intended for systems where an external host system wants to run an algorithm with raw data.
|
**Please note:** In *Constant Power Mode* with measurements every 250 ms (```mode_250ms```) only raw data are available. In all other measurement modes, the Indoor Air Quality (IAQ) values are available additionally. The *Constant Power Mode* with measurements every 250 ms (```mode_250ms```) is only intended for systems where an external host system wants to run an algorithm with raw data.
|
||||||
|
|
||||||
Once the is initialized with function ```ccs811_init_sensor```, function ```ccs811_set_mode``` can be used to start periodic measurements with a given period.
|
Once the sensor is initialized with function ```ccs811_init_sensor```, function ```ccs811_set_mode``` can be used to start periodic measurements with a given period.
|
||||||
|
|
||||||
```
|
```
|
||||||
static ccs811_sensor_t* sensor;
|
static ccs811_sensor_t* sensor;
|
||||||
|
@ -211,42 +213,46 @@ First, the hardware configuration has to be established.
|
||||||
|
|
||||||
### Hardware configurations
|
### Hardware configurations
|
||||||
|
|
||||||
Following figure shows the hardware configuration if no interrupt is used.
|
Following figure shows the hardware configuration for ESP8266 and ESP32 if no interrupt is used.
|
||||||
|
|
||||||
```
|
```
|
||||||
+------------------------+ +--------+
|
+------------------+ +--------+
|
||||||
| ESP8266 Bus 0 | | CCS811 |
|
| ESP8266 / ESP32 | | CCS811 |
|
||||||
| GPIO 5 (SCL) >----> SCL |
|
| | | |
|
||||||
| GPIO 4 (SDA) ------ SDA |
|
| GPIO 14 (SCL) >-------> SCL |
|
||||||
| GND -----> /WAKE |
|
| GPIO 13 (SDA) <-------> SDA |
|
||||||
+------------------------+ +--------+
|
| GND --------> /WAKE |
|
||||||
|
+------------------+ +--------+
|
||||||
```
|
```
|
||||||
|
|
||||||
If interrupt signal *nINT* is used to fetch new data, additionally the interrupt pin has to be connected to a GPIO pin.
|
If interrupt signal *nINT* is used to fetch new data, additionally the interrupt pin has to be connected to a GPIO pin.
|
||||||
|
|
||||||
```
|
```
|
||||||
+------------------------+ +--------+
|
+------------------+ +--------+
|
||||||
| ESP8266 Bus 0 | | CCS811 |
|
| ESP8266 / ESP32 | | CCS811 |
|
||||||
| GPIO 5 (SCL) >----> SCL |
|
| | | |
|
||||||
| GPIO 4 (SDA) ------ SDA |
|
| GPIO 14 (SCL) >-------> SCL |
|
||||||
| GPIO 2 <----- /nINT |
|
| GPIO 13 (SDA) <-------> SDA |
|
||||||
| GND -----> /WAKE |
|
| GPIO 5 <-------- /nINT |
|
||||||
+------------------------+ +--------+
|
| GND --------> /WAKE |
|
||||||
|
+------------------+ +--------+
|
||||||
```
|
```
|
||||||
|
|
||||||
If CCS811 sensor is used in conjunction with another sensor, e.g., a SHT3x sensor, the hardware configuration looks like following:
|
If CCS811 sensor is used in conjunction with another sensor, e.g., a SHT3x sensor, the hardware configuration looks like following:
|
||||||
|
|
||||||
```
|
```
|
||||||
+------------------------+ +--------+
|
+------------------+ +--------+
|
||||||
| ESP8266 Bus 0 | | CCS811 |
|
| ESP8266 / ESP32 | | CCS811 |
|
||||||
| GPIO 5 (SCL) >--+----> SCL |
|
| | | |
|
||||||
| GPIO 4 (SDA) ---|-+--- SDA |
|
| GPIO 14 (SCL) >--+----> SCL |
|
||||||
|
| GPIO 13 (SDA) <--|-+--> SDA |
|
||||||
| GND ---|-|--> /WAKE |
|
| GND ---|-|--> /WAKE |
|
||||||
| | | | +--------+
|
| | | | +--------+
|
||||||
| | | | | SHT3x |
|
| | | | | SHT3x |
|
||||||
|
| | | | | |
|
||||||
| | +----> SCL |
|
| | +----> SCL |
|
||||||
| | +--- SDA |
|
| | +--> SDA |
|
||||||
+------------------------+ +--------+
|
+------------------+ +--------+
|
||||||
```
|
```
|
||||||
|
|
||||||
### Communication interface settings
|
### Communication interface settings
|
||||||
|
@ -256,12 +262,11 @@ Dependent on the hardware configuration, the communication interface settings ha
|
||||||
```
|
```
|
||||||
// define I2C interfaces at which CCS811 sensors can be connected
|
// define I2C interfaces at which CCS811 sensors can be connected
|
||||||
#define I2C_BUS 0
|
#define I2C_BUS 0
|
||||||
#define I2C_SCL_PIN 5
|
#define I2C_SCL_PIN 14
|
||||||
#define I2C_SDA_PIN 4
|
#define I2C_SDA_PIN 13
|
||||||
|
|
||||||
// define GPIO for interrupt
|
// define GPIO for interrupt
|
||||||
#define INT_GPIO 2
|
#define INT_GPIO 5
|
||||||
#include "sht3x/sht3x.h"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Main program
|
### Main program
|
||||||
|
@ -272,7 +277,7 @@ Before using the CCS811 driver, function ```i2c_init``` needs to be called for e
|
||||||
|
|
||||||
```
|
```
|
||||||
...
|
...
|
||||||
i2c_init(I2C_BUS, I2C_SCL_PIN, I2C_SDA_PIN, I2C_FREQ_100K));
|
i2c_init(I2C_BUS, I2C_SCL_PIN, I2C_SDA_PIN, I2C_FREQ_100K);
|
||||||
i2c_set_clock_stretch (I2C_BUS, CCS811_I2C_CLOCK_STRETCH);
|
i2c_set_clock_stretch (I2C_BUS, CCS811_I2C_CLOCK_STRETCH);
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
@ -401,31 +406,47 @@ ccs811_set_eco2_thresholds (sensor, 600, 1100, 40);
|
||||||
## Full Example
|
## Full Example
|
||||||
|
|
||||||
```
|
```
|
||||||
// use following constants to define the demo mode
|
/* -- use following constants to define the example mode ----------- */
|
||||||
|
|
||||||
// #define INT_DATA_RDY_USED
|
// #define INT_DATA_RDY_USED
|
||||||
// #define INT_THRESHOLD_USED
|
// #define INT_THRESHOLD_USED
|
||||||
|
|
||||||
#include "espressif/esp_common.h"
|
#if defined(INT_DATA_RDY_USED) || defined(INT_THRESHOLD_USED)
|
||||||
#include "esp/uart.h"
|
#define INT_USED
|
||||||
#include "i2c/i2c.h"
|
#endif
|
||||||
|
|
||||||
#include "FreeRTOS.h"
|
/* -- includes ----------------------------------------------------- */
|
||||||
#include <task.h>
|
|
||||||
|
|
||||||
// include CCS811 driver
|
#include "ccs811.h"
|
||||||
#include "ccs811/ccs811.h"
|
|
||||||
|
|
||||||
// define I2C interfaces at which CCS811 sensors can be connected
|
/* -- platform dependent definitions ------------------------------- */
|
||||||
|
|
||||||
|
#ifdef ESP_PLATFORM // ESP32 (ESP-IDF)
|
||||||
|
|
||||||
|
// user task stack depth for ESP32
|
||||||
|
#define TASK_STACK_DEPTH 2048
|
||||||
|
|
||||||
|
#else // ESP8266 (esp-open-rtos)
|
||||||
|
|
||||||
|
// user task stack depth for ESP8266
|
||||||
|
#define TASK_STACK_DEPTH 256
|
||||||
|
|
||||||
|
#endif // ESP_PLATFORM
|
||||||
|
|
||||||
|
// I2C interface defintions for ESP32 and ESP8266
|
||||||
#define I2C_BUS 0
|
#define I2C_BUS 0
|
||||||
#define I2C_SCL_PIN 5
|
#define I2C_SCL_PIN 14
|
||||||
#define I2C_SDA_PIN 4
|
#define I2C_SDA_PIN 13
|
||||||
|
#define I2C_FREQ I2C_FREQ_100K
|
||||||
|
|
||||||
// define GPIO for interrupt
|
// interrupt GPIOs defintions for ESP8266 and ESP32
|
||||||
#define INT_GPIO 2
|
#define nINT_PIN 13
|
||||||
|
|
||||||
|
/* -- user tasks --------------------------------------------------- */
|
||||||
|
|
||||||
static ccs811_sensor_t* sensor;
|
static ccs811_sensor_t* sensor;
|
||||||
|
|
||||||
#if defined(INT_DATA_RDY_USED) || defined(INT_THRESHOLD_USED)
|
#ifdef INT_USED
|
||||||
/**
|
/**
|
||||||
* In this example, the interrupt *nINT* is used. It is triggered every time
|
* In this example, the interrupt *nINT* is used. It is triggered every time
|
||||||
* new data are available (INT_DATA_RDY_USED) or exceed defined thresholds
|
* new data are available (INT_DATA_RDY_USED) or exceed defined thresholds
|
||||||
|
@ -459,12 +480,12 @@ void user_task_interrupt (void *pvParameters)
|
||||||
|
|
||||||
// Interrupt handler which resumes user_task_interrupt on interrupt
|
// Interrupt handler which resumes user_task_interrupt on interrupt
|
||||||
|
|
||||||
void nINT_handler (uint8_t gpio)
|
static void IRAM nINT_handler(uint8_t gpio)
|
||||||
{
|
{
|
||||||
xTaskResumeFromISR (nINT_task);
|
xTaskResumeFromISR (nINT_task);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else // !INT_USED
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* In this example, user task fetches the sensor values every seconds.
|
* In this example, user task fetches the sensor values every seconds.
|
||||||
|
@ -492,20 +513,21 @@ void user_task_periodic(void *pvParameters)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif // INT_USED
|
||||||
|
|
||||||
|
/* -- main program ------------------------------------------------- */
|
||||||
|
|
||||||
void user_init(void)
|
void user_init(void)
|
||||||
{
|
{
|
||||||
// set UART Parameter
|
// Set UART Parameter.
|
||||||
uart_set_baud(0, 115200);
|
uart_set_baud(0, 115200);
|
||||||
// give the UART some time to settle
|
// Give the UART some time to settle
|
||||||
sdk_os_delay_us(500);
|
vTaskDelay(1);
|
||||||
|
|
||||||
/** -- MANDATORY PART -- */
|
/** -- MANDATORY PART -- */
|
||||||
|
|
||||||
// init all I2C bus interfaces at which CCS811 sensors are connected
|
// init all I2C bus interfaces at which CCS811 sensors are connected
|
||||||
i2c_init(I2C_BUS, I2C_SCL_PIN, I2C_SDA_PIN, I2C_FREQ_100K);
|
i2c_init (I2C_BUS, I2C_SCL_PIN, I2C_SDA_PIN, I2C_FREQ);
|
||||||
|
|
||||||
// longer clock stretching is required for CCS811
|
// longer clock stretching is required for CCS811
|
||||||
i2c_set_clock_stretch (I2C_BUS, CCS811_I2C_CLOCK_STRETCH);
|
i2c_set_clock_stretch (I2C_BUS, CCS811_I2C_CLOCK_STRETCH);
|
||||||
|
@ -515,33 +537,35 @@ void user_init(void)
|
||||||
|
|
||||||
if (sensor)
|
if (sensor)
|
||||||
{
|
{
|
||||||
#if defined(INT_DATA_RDY_USED) || defined(INT_THRESHOLD_USED)
|
#if !defined (INT_USED)
|
||||||
|
|
||||||
|
// create a periodic task that uses the sensor
|
||||||
|
xTaskCreate(user_task_periodic, "user_task_periodic", TASK_STACK_DEPTH, NULL, 2, NULL);
|
||||||
|
|
||||||
|
#else // INT_USED
|
||||||
|
|
||||||
// create a task that is resumed by interrupt handler to use the sensor
|
// create a task that is resumed by interrupt handler to use the sensor
|
||||||
xTaskCreate(user_task_interrupt, "user_task_interrupt", 256, NULL, 2, &nINT_task);
|
xTaskCreate(user_task_interrupt, "user_task_interrupt", TASK_STACK_DEPTH, NULL, 2, &nINT_task);
|
||||||
|
|
||||||
// activate the interrupt for INT_GPIO and set the interrupt handler
|
// activate the interrupt for nINT_PIN and set the interrupt handler
|
||||||
gpio_set_interrupt(INT_GPIO, GPIO_INTTYPE_EDGE_NEG, nINT_handler);
|
gpio_enable(nINT_PIN, GPIO_INPUT);
|
||||||
|
gpio_set_interrupt(nINT_PIN, GPIO_INTTYPE_EDGE_NEG, nINT_handler);
|
||||||
|
|
||||||
#ifdef INT_DATA_RDY_USED
|
#ifdef INT_DATA_RDY_USED
|
||||||
// enable the data ready interrupt
|
// enable the data ready interrupt
|
||||||
ccs811_enable_interrupt (sensor, true);
|
ccs811_enable_interrupt (sensor, true);
|
||||||
#else
|
#else // INT_THRESHOLD_USED
|
||||||
// set threshold parameters and enable threshold interrupt mode
|
// set threshold parameters and enable threshold interrupt mode
|
||||||
ccs811_set_eco2_thresholds (sensor, 600, 1100, 40);
|
ccs811_set_eco2_thresholds (sensor, 600, 1100, 40);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#endif // !defined(INT_USED)
|
||||||
|
|
||||||
// create a periodic task that uses the sensor
|
|
||||||
xTaskCreate(user_task_periodic, "user_task_periodic", 256, NULL, 2, NULL);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// start periodic measurement with one measurement per second
|
// start periodic measurement with one measurement per second
|
||||||
ccs811_set_mode (sensor, ccs811_mode_1s);
|
ccs811_set_mode (sensor, ccs811_mode_1s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Further Examples
|
## Further Examples
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
/*
|
/*
|
||||||
* Driver for ams CCS811 digital temperature, humity, pressure and
|
* Driver for AMS CCS811 digital gas sensor connected to I2C.
|
||||||
* gas sensor connected to I2C or SPI
|
|
||||||
*
|
*
|
||||||
* Part of esp-open-rtos [https://github.com/SuperHouse/esp-open-rtos]
|
* This driver is for the usage with the ESP8266 and FreeRTOS (esp-open-rtos)
|
||||||
|
* [https://github.com/SuperHouse/esp-open-rtos]. It is also working with ESP32
|
||||||
|
* and ESP-IDF [https://github.com/espressif/esp-idf.git] as well as Linux
|
||||||
|
* based systems using a wrapper library for ESP8266 functions.
|
||||||
*
|
*
|
||||||
* ---------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* The BSD License (3-clause license)
|
* The BSD License (3-clause license)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2017 Gunar Schorcht (https://github.com/gschorcht]
|
* Copyright (c) 2017 Gunar Schorcht (https://github.com/gschorcht)
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -39,14 +41,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include "espressif/esp_common.h"
|
|
||||||
#include "espressif/sdk_private.h"
|
|
||||||
|
|
||||||
#include "FreeRTOS.h"
|
|
||||||
#include "task.h"
|
|
||||||
|
|
||||||
#include "i2c/i2c.h"
|
|
||||||
|
|
||||||
#include "ccs811.h"
|
#include "ccs811.h"
|
||||||
|
|
||||||
|
@ -239,7 +234,7 @@ bool ccs811_set_mode (ccs811_sensor_t* dev, ccs811_mode_t mode)
|
||||||
|
|
||||||
// check whether setting measurement mode were succesfull
|
// check whether setting measurement mode were succesfull
|
||||||
if (!ccs811_reg_read(dev, CCS811_REG_MEAS_MODE, (uint8_t*)®, 1) ||
|
if (!ccs811_reg_read(dev, CCS811_REG_MEAS_MODE, (uint8_t*)®, 1) ||
|
||||||
!reg.drive_mode == mode)
|
reg.drive_mode != mode)
|
||||||
{
|
{
|
||||||
error_dev ("Could not set measurement mode to %d", __FUNCTION__, dev, mode);
|
error_dev ("Could not set measurement mode to %d", __FUNCTION__, dev, mode);
|
||||||
return ccs811_check_error_status (dev);
|
return ccs811_check_error_status (dev);
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
/*
|
/*
|
||||||
* Driver for AMS CCS811 digital gas sensor connected to I2C
|
* Driver for AMS CCS811 digital gas sensor connected to I2C.
|
||||||
*
|
*
|
||||||
* Part of esp-open-rtos [https://github.com/SuperHouse/esp-open-rtos]
|
* This driver is for the usage with the ESP8266 and FreeRTOS (esp-open-rtos)
|
||||||
|
* [https://github.com/SuperHouse/esp-open-rtos]. It is also working with ESP32
|
||||||
|
* and ESP-IDF [https://github.com/espressif/esp-idf.git] as well as Linux
|
||||||
|
* based systems using a wrapper library for ESP8266 functions.
|
||||||
*
|
*
|
||||||
* ---------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* The BSD License (3-clause license)
|
* The BSD License (3-clause license)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2017 Gunar Schorcht (https://github.com/gschorcht]
|
* Copyright (c) 2017 Gunar Schorcht (https://github.com/gschorcht)
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -40,13 +43,15 @@
|
||||||
#ifndef CCS811_DRV_H_
|
#ifndef CCS811_DRV_H_
|
||||||
#define CCS811_DRV_H_
|
#define CCS811_DRV_H_
|
||||||
|
|
||||||
#include "stdint.h"
|
|
||||||
#include "stdbool.h"
|
|
||||||
|
|
||||||
// Uncomment one of the following defines to enable debug output
|
// Uncomment one of the following defines to enable debug output
|
||||||
// #define CCS811_DEBUG_LEVEL_1 // only error messages
|
// #define CCS811_DEBUG_LEVEL_1 // only error messages
|
||||||
// #define CCS811_DEBUG_LEVEL_2 // debug and error messages
|
// #define CCS811_DEBUG_LEVEL_2 // debug and error messages
|
||||||
|
|
||||||
|
#include "stdint.h"
|
||||||
|
#include "stdbool.h"
|
||||||
|
|
||||||
|
#include "ccs811_platform.h"
|
||||||
|
|
||||||
// CCS811 I2C addresses
|
// CCS811 I2C addresses
|
||||||
#define CCS811_I2C_ADDRESS_1 0x5A // default
|
#define CCS811_I2C_ADDRESS_1 0x5A // default
|
||||||
#define CCS811_I2C_ADDRESS_2 0x5B
|
#define CCS811_I2C_ADDRESS_2 0x5B
|
||||||
|
|
69
extras/ccs811/ccs811_platform.h
Normal file
69
extras/ccs811/ccs811_platform.h
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
* Driver for AMS CCS811 digital gas sensor connected to I2C.
|
||||||
|
*
|
||||||
|
* This driver is for the usage with the ESP8266 and FreeRTOS (esp-open-rtos)
|
||||||
|
* [https://github.com/SuperHouse/esp-open-rtos]. It is also working with ESP32
|
||||||
|
* and ESP-IDF [https://github.com/espressif/esp-idf.git] as well as Linux
|
||||||
|
* based systems using a wrapper library for ESP8266 functions.
|
||||||
|
*
|
||||||
|
* ---------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* The BSD License (3-clause license)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017 Gunar Schorcht (https://github.com/gschorcht)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. Neither the name of the copyright holder nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from this
|
||||||
|
* software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Platform file: platform specific definitions, includes and functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __CCS811_PLATFORM_H__
|
||||||
|
#define __CCS811_PLATFORM_H__
|
||||||
|
|
||||||
|
#if !defined(ESP_OPEN_RTOS)
|
||||||
|
#define ESP_OPEN_RTOS 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef ESP_OPEN_RTOS // ESP8266
|
||||||
|
|
||||||
|
// platform specific includes
|
||||||
|
|
||||||
|
#include "FreeRTOS.h"
|
||||||
|
#include "task.h"
|
||||||
|
|
||||||
|
#include "espressif/esp_common.h"
|
||||||
|
#include "espressif/sdk_private.h"
|
||||||
|
|
||||||
|
#include "esp/uart.h"
|
||||||
|
#include "i2c/i2c.h"
|
||||||
|
|
||||||
|
#endif // ESP_OPEN_RTOS
|
||||||
|
|
||||||
|
#endif // __CCS811_PLATFORM_H__
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
# expected anyone using ccs811 driver includes it as 'ccs811/ccs811.h'
|
# expected anyone using ccs811 driver includes it as 'ccs811/ccs811.h'
|
||||||
INC_DIRS += $(ccs811_ROOT)..
|
INC_DIRS += $(ccs811_ROOT)..
|
||||||
|
INC_DIRS += $(ccs811_ROOT)
|
||||||
|
|
||||||
# args for passing into compile rule generation
|
# args for passing into compile rule generation
|
||||||
ccs811_SRC_DIR = $(ccs811_ROOT)
|
ccs811_SRC_DIR = $(ccs811_ROOT)
|
||||||
|
|
Loading…
Reference in a new issue