CCS811
— Atmospheric Carbon Dioxide Sensor
Class CCS811
This module provides the class and functions to use the CCS811 sensor chip which detects carbon dioxide (CO2) in parts per million (ppm) and total volatile organic compounds (tVOC) in parts per billion (ppb).
The sensor is a digital metal oxide gas sensor which detects a wide range of volatile organic compounds. The module starts the sensor in constant power mode, giving a new measurement every second.
The module contains a class CCS811.CCS811 which provides the methods shown below.
Usage of the module is best achieved by following this example:
from CCS811 import CCS811
from machine import SoftI2C, Pin
import time
from kooka import display # Set up the display object
i2c = SoftI2C(scl=) # set up an I2C serial interface object using connector ‘P3’
sensor = CCS811(i2c) # create a CCS811 object assigned to the variable ‘sensor’ using the I2C interface
time.sleep(1) # give the sensor time to initialise
while True: # run in this loop forever
display.clear()
display.print('CCS811 Sensor')
if sensor.data_ready(): # when new data is ready
display.print('eCO2: %d ppm' % sensor.eCO2) # print latest CO2 reading
display.print('TVoC: %d ppb' % sensor.tVOC) # print latest tVOC reading
The data-sheet and a typical breakout board for the CCS811 sensor can be found here:
CCS811 Constructors
- class CCS811.CCS811(i2c, addr=0x5A)
Creates a CCS811 object as a device on the nominated I2C bus:
i2c is an I2C bus interface object created by
machine.SoftI2C
addr is one of the valid I2C device addresses supported by the CCS811 sensor chip - (
0x5A
(default) or0x5B
)
CCS811 Methods
- CCS811.data_ready()
Returns true if new sensor data is available.
The sensor readings accessible in the parameters CCS811.eCO2 and CCS811.tVOC
- CCS811.get_baseline()
- CCS811.put_baseline(HB, LB)
The put_baseline() and get_baseline() functions are used for external calibration of the sensor’s heating element, which is normally automatically internally maintained. Therefore there is not normally a need to use these functions.
- CCS811.put_envdata(humidity, temp)
The accuracy of the readings are affected by temperature and humidity, and can be improved by using the put_envdata(humidity, temperature) function in conjunction with another sensor such as the bme280 or dht to provide the compensating data. Humidity is relative humidity in %, and temperature is in degrees Centigrade.