|
1 |
| -# CCS811 |
2 |
| -Library for the CCS811 digital gas sensor for monitoring indoor air quality from ams. |
| 1 | +# iAQcore |
| 2 | +Arduino library for the CCS811 digital gas sensor for monitoring indoor air quality from ams. |
| 3 | + |
| 4 | +## Introduction |
| 5 | +This project is an Arduino *library*. It implements a driver for the CCS811. |
| 6 | +This chip is a indoor air quality sensor module with an I2C interface. |
| 7 | + |
| 8 | +The code has been tested with |
| 9 | + - [NodeMCU (ESP8266)](https://www.aliexpress.com/item/NodeMCU-V3-Lua-WIFI-module-integration-of-ESP8266-extra-memory-32M-flash-USB-serial-CP2102/32779738528.html) |
| 10 | + - [Arduino pro mini](https://www.aliexpress.com/item/ProMini-ATmega328P-3-3V-Compatible-for-Arduino-Pro-Mini/32525927539.html) |
| 11 | + - [Arduino nano](https://www.aliexpress.com/item/Nano-CH340-ATmega328P-MicroUSB-Compatible-for-Arduino-Nano-V3/32572612009.html) |
| 12 | + |
| 13 | +Note that the CCS811 requires a supply voltage of 1.8V .. 3.6V. |
| 14 | +So, 3.3V is ok, but *do not use a 5V board*. |
| 15 | +The Nano has 3v3 supply, but runs I2C on 5V. This does seem to work. |
| 16 | +Also note that the minimum supply voltage is 1.8V and should not drop below this value for reliable device operation. |
| 17 | + |
| 18 | +## Links |
| 19 | +The CCS811 is made by [ams](http://www.ams.com). This library is compatible with the following variants. |
| 20 | + - Find the datasheet of the CCS811 on the |
| 21 | + [product page](http://ams.com/eng/Products/Environmental-Sensors/Air-Quality-Sensors/CCS811). |
| 22 | + - Find application notes and software on the |
| 23 | + [download page](https://download.ams.com/ENVIRONMENTAL-SENSORS/CCS811). |
| 24 | + |
| 25 | +## Prerequisites |
| 26 | +It is assumed that |
| 27 | + - The Arduino IDE has been installed. |
| 28 | + If not, refer to "Install the Arduino Desktop IDE" on the |
| 29 | + [Arduino site](https://www.arduino.cc/en/Guide/HomePage). |
| 30 | + - The library directory is at its default location. |
| 31 | + For me, Maarten, that is `C:\Users\maarten\Documents\Arduino\libraries`. |
| 32 | + |
| 33 | +## Installation |
| 34 | +Installation steps |
| 35 | + - Visit the [project page](https://github.com/maarten-pennings/iAQcore) for the Arduino iAQcore library. |
| 36 | + - Click the green button `Clone or download` on the right side. |
| 37 | + - From the pop-up choose `Download ZIP`. |
| 38 | + - Unzip the file "Here", so that this `README.md` is in the top-level directory |
| 39 | + with the name `CCS811-master`. |
| 40 | + - Rename the top-level directory `CCS811-master` to `CCS811`. |
| 41 | + - Copy the entire tree to the Arduino library directory. |
| 42 | + This `README.md` should be located at e.g. |
| 43 | + `C:\Users\maarten\Documents\Arduino\libraries\CCS811\README.md`. |
| 44 | + |
| 45 | +## Build an example |
| 46 | +To build an example sketch |
| 47 | + - (Re)start Arduino. |
| 48 | + - Open File > Example > Examples from Custom Libraries > CCS811 > CCS811demo. |
| 49 | + - Make sure Tools > Board lists the correct board. |
| 50 | + - Select Sketch > Verify/Compile. |
| 51 | + |
| 52 | +## Wiring |
| 53 | +This library has been tested with three boards. |
| 54 | + |
| 55 | +For the NodeMCU (ESP8266), connect as follows (I did not use pull-ups, presumably they are inside the MCU) |
| 56 | + |
| 57 | +| CCS811 | ESP8266 | |
| 58 | +|:-------:|:---------:| |
| 59 | +| VDD | 3V3 | |
| 60 | +| GND | GND | |
| 61 | +| SDA | D2 | |
| 62 | +| SCL | D1 | |
| 63 | +| nWAKE | D3 or GND | |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | +For the Pro mini (do *not* use a 5V board), connect as follows (I did not use pull-ups, presumably they are inside the MCU) |
| 68 | + |
| 69 | +| CCS811 | Pro mini | |
| 70 | +|:-------:|:---------:| |
| 71 | +| VDD | VCC | |
| 72 | +| GND | GND | |
| 73 | +| SDA | A4 | |
| 74 | +| SCL | A5 | |
| 75 | +| nWAKE | D3 or GND | |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | +For the Arduino Nano, connect as follows (I did not use pull-ups, presumably they are inside the MCU) |
| 80 | + |
| 81 | +| CCS811 | Nano | |
| 82 | +|:-------:|:---------:| |
| 83 | +| VDD | 3V3 | |
| 84 | +| GND | GND | |
| 85 | +| SDA | A4 | |
| 86 | +| SCL | A5 | |
| 87 | +| nWAKE | D3 or GND | |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | +Connect the iAQcore module as follows |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | +## Flash an example |
| 97 | +To build an example sketch |
| 98 | + - (Re)start Arduino. |
| 99 | + - Open File > Example > Examples from Custom Libraries > CCS811 > CCS811demo. |
| 100 | + - In `setup()` make sure to start the I2C driver correctly. |
| 101 | + For example, for ESP8266 NodeMCU have |
| 102 | + ```C++ |
| 103 | + // Enable I2C for ESP8266 NodeMCU boards [VDD to 3V3, GND to GND, SDA to D2, SCL to D1] |
| 104 | + Wire.begin(D2,D1); |
| 105 | + Wire.setClockStretchLimit(1000); |
| 106 | + ``` |
| 107 | + and for Arduino pro mini or Nano have |
| 108 | + ```C++ |
| 109 | + // Enable I2C for Arduino pro mini or Nano [VDD to VCC/3V3, GND to GND, SDA to A4, SCL to A5] |
| 110 | + Wire.begin(); |
| 111 | + ``` |
| 112 | + - Make sure Tools > Board lists the correct board. |
| 113 | + - Select Sketch > Upload. |
| 114 | + - Select Tools > Serial Monitor. |
| 115 | + - Enjoy the output, which should be like this for `iAQcore-simple`: |
| 116 | + |
| 117 | + ```Text |
| 118 | + Starting iAQcore simple demo |
| 119 | + iAQcore: eco2=456 ppm, stat=0x0, resist=363157 ohm, tvoc=127 ppb |
| 120 | + iAQcore: eco2=453 ppm, stat=0x0, resist=363586 ohm, tvoc=126 ppb |
| 121 | + iAQcore: eco2=455 ppm, stat=0x0, resist=363157 ohm, tvoc=127 ppb |
| 122 | + iAQcore: eco2=450 ppm, stat=0x0, resist=364447 ohm, tvoc=125 ppb |
| 123 | + iAQcore: eco2=450 ppm, stat=0x0, resist=364878 ohm, tvoc=125 ppb |
| 124 | + iAQcore: eco2=605 ppm, stat=0x0, resist=331010 ohm, tvoc=168 ppb |
| 125 | + iAQcore: eco2=1560 ppm, stat=0x0, resist=212175 ohm, tvoc=431 ppb |
| 126 | + iAQcore: eco2=3721 ppm, stat=0x0, resist=117065 ohm, tvoc=1026 ppb |
| 127 | + iAQcore: eco2=4749 ppm, stat=0x0, resist=96488 ohm, tvoc=1309 ppb |
| 128 | + iAQcore: eco2=6127 ppm, stat=0x0, resist=78091 ohm, tvoc=1689 ppb |
| 129 | + iAQcore: eco2=4822 ppm, stat=0x0, resist=95307 ohm, tvoc=1329 ppb |
| 130 | + iAQcore: eco2=3645 ppm, stat=0x0, resist=118936 ohm, tvoc=1005 ppb |
| 131 | + iAQcore: eco2=2830 ppm, stat=0x0, resist=143618 ohm, tvoc=781 ppb |
| 132 | + iAQcore: eco2=2221 ppm, stat=0x0, resist=169921 ohm, tvoc=613 ppb |
| 133 | + iAQcore: eco2=1483 ppm, stat=0x0, resist=218476 ohm, tvoc=410 ppb |
| 134 | + iAQcore: eco2=1091 ppm, stat=0x0, resist=257597 ohm, tvoc=302 ppb |
| 135 | + iAQcore: eco2=912 ppm, stat=0x0, resist=280448 ohm, tvoc=253 ppb |
| 136 | + iAQcore: eco2=852 ppm, stat=0x0, resist=289063 ohm, tvoc=236 ppb |
| 137 | + iAQcore: eco2=824 ppm, stat=0x0, resist=293181 ohm, tvoc=228 ppb |
| 138 | + ``` |
| 139 | + |
| 140 | +## Clock stretching |
| 141 | +I2C _slave_ devices, such as the iAQcore, are controlled by I2C _masters_, such as the ESP8266, pro mini or nano. |
| 142 | +The master is in charge of the communication to the slave: it toggles the clock line (SCL) high and low. |
| 143 | +Each clock pulse one bit is transferred between the master and the slave (from or to). |
| 144 | +If the slave is not yet ready, it may _stretch the clock_, i.e. force it low, so that the master can not complete the pulse. |
| 145 | + |
| 146 | +The figure below shows that after the master has send the address byte of the iAQcore, this iAQcore chip |
| 147 | +stretches the SCL line for 306.8 us. |
| 148 | + |
| 149 | + |
| 150 | + |
| 151 | +Unfortunately, the ESP8266 I2C library has a clock stretch timeout of 230us. |
| 152 | +So, this timeout must be set to a higher value: `Wire.setClockStretchLimit(1000)`. |
| 153 | + |
| 154 | +(end of doc) |
0 commit comments