Arduino library · Sensors

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 nameAdafruit CCS811 Library
AuthorAdafruit
Include#include <Adafruit_CCS811.h>
Boardsevery board Mokxi compiles for but ATtiny85
In the simulatorSimulated: it runs against the part the way it does on the bench.
Parts it drivesAir 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.

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.

sketch.ino · Arduino Uno R3
/***************************************************************************
  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

Open it in the editor, wired and ready to run

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.

Try Adafruit CCS811 Library without installing anything

Open the example, change the sketch, and keep your version in a free account.