Adafruit CCS811 Library: an example that runs
Yes. You can use the Adafruit CCS811 Library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (Air quality, CCS811). The example below, "eCO2 and TVOC from a CCS811", runs on the Arduino Uno R3.
Built in on Mokxi: #include <Adafruit_CCS811.h> and it builds, with nothing to install. Free, and no account needed.
What Adafruit CCS811 Library does
Adafruit_CCS811 ccs: begin(), available(), readData(), geteCO2() and getTVOC(), the drive mode, environmental compensation, baseline and thresholds. That is what Adafruit CCS811 Library covers. The sketch below uses it on the Arduino Uno: “eCO2 and TVOC from a CCS811”.
The Adafruit CCS811 library's interface, for the ams (ScioSense) CCS811 metal-oxide gas sensor: equivalent CO2 and TVOC.
The board's WAK pin must be held low or the chip does not answer. With no CCS811 at the address begin() says so on the serial monitor and returns false; available() stays false and readData() fails. No air quality is made up.
The calls follow release 1.1.3 of the library, so a sketch written here builds on a real board too. The example is the one Mokxi's own tests build and run, so what is printed here is what runs.
| Library Manager name | Adafruit CCS811 Library |
|---|---|
| Author | Adafruit |
| Include | #include <Adafruit_CCS811.h> |
| Boards | every board Mokxi compiles for but ATtiny85 |
| In the simulator | Simulated: it runs against the part the way it does on the bench. |
| Parts it drives | Air quality, CCS811 |
Install it
It builds on every board Mokxi compiles for but ATtiny85.
In Mokxi it is built in: #include <Adafruit_CCS811.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "Adafruit CCS811 Library" by Adafruit from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add Adafruit CCS811 Library to lib_deps in PlatformIO. Mokxi follows the calls of release 1.1.3, so a sketch written here builds there too.
What to know in the simulator: The readings are the eCO2 and TVOC sliders, a sample each drive-mode period; the gas chemistry, run-in, baseline correction and compensation are not simulated. Hold WAK low or the chip does not answer.
- ESP32-C3
- Arduino Uno
- Arduino Nano
- Arduino Mega 2560
- Arduino Leonardo
- SparkFun Pro Micro
- Arduino Micro
- ESP32-C6
- WCH CH32V003
- Raspberry Pi Pico
- Raspberry Pi Pico W
- Seeed XIAO SAMD21
- STM32
- STM32 Nucleo-F411RE
- STM32 Blue Pill
- micro:bit V2
- Arduino Uno R4
- ESP32 DevKit
- ESP32-S3-DevKitC-1
- ESP8266 NodeMCU
- Arduino Pro Mini 3.3 V
- Seeed XIAO ESP32-C3
- ESP32-C3 SuperMini
- Seeed XIAO ESP32-C6
- ESP32-DevKitC V4
- LOLIN32 Lite
- Wemos D1 R32
- Cheap Yellow Display
- TTGO T-Display
- Seeed XIAO ESP32-S3
- Arduino Nano ESP32
- Arduino Nano RP2040 Connect
- Seeed XIAO RP2040
- Waveshare RP2040-Zero
- Arduino Uno R4 WiFi
The calls you will use
In the order a sketch meets them.
Adafruit_CCS811 ccs
Makes ccs, the Adafruit_CCS811 object the calls below are made on.
ccs.begin()
Starts it up and returns true if it started, false if it did not. Call it once in setup().
ccs.readData()
Returns the data as a whole number.
ccs.getTVOC()
Returns the tvoc as a whole number.
Example: eCO2 and TVOC from a CCS811
On the Arduino Uno R3. It runs in the browser exactly as printed.
/***************************************************************************
This is a library for the CCS811 air
This sketch reads the sensor
Designed specifically to work with the Adafruit CCS811 breakout
***************************************************************************/
#include "Adafruit_CCS811.h"
Adafruit_CCS811 ccs;
void setup() {
Serial.begin(9600);
Serial.println("CCS811 test");
if(!ccs.begin()){
Serial.println("Failed to start sensor! Please check your wiring.");
while(1);
}
// Wait for the sensor to be ready
while(!ccs.available());
}
void loop() {
if(ccs.available()){
if(!ccs.readData()){
Serial.print("CO2: ");
Serial.print(ccs.geteCO2());
Serial.print("ppm, TVOC: ");
Serial.println(ccs.getTVOC());
}
else{
Serial.println("ERROR!");
while(1);
}
}
delay(500);
}Wiring
- Arduino Uno R3 A4 to Air quality, CCS811 SDA
- Arduino Uno R3 A5 to Air quality, CCS811 SCL
- Arduino Uno R3 3V3 to Air quality, CCS811 VCC
- Arduino Uno R3 GND to Air quality, CCS811 GND
- Arduino Uno R3 GND to Air quality, CCS811 WAK
Projects that use Adafruit CCS811 Library
Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.
Keep going
Parts
Try Adafruit CCS811 Library without installing anything
Open the example, change the sketch, and keep your version in a free account.