Qwiic_CCS811_Py

follow on Twitter

SparkFun qwiic Environmental Combo

Python module for the qwiic ccs811 sensor, which is part of the SparkFun Qwiic Environmental Combo Breakout

This python package is a port of the existing SparkFun CCS811 Arduino Library

This package can be used in conjunction with the overall SparkFun qwiic Python Package

New to qwiic? Take a look at the entire SparkFun qwiic ecosystem.

warning:Using this sensor on a Raspberry Pi? :warning:

Your system might need modification. See this note.

Supported Platforms

The qwiic CCS811 Python package current supports the following platforms:

Dependencies

This driver package depends on the qwiic I2C driver: Qwiic_I2C_Py

Documentation

The SparkFun qwiic CCS811 module documentation is hosted at ReadTheDocs

Installation

PyPi Installation

This repository is hosted on PyPi as the sparkfun-qwiic-ccs811 package. On systems that support PyPi installation via pip, this library is installed using the following commands

For all users (note: the user must have sudo privileges):

sudo pip install sparkfun-qwiic-ccs811

For the current user:

pip install sparkfun-qwiic-ccs811

To install, make sure the setuptools package is installed on the system.

Direct installation at the command line:

python setup.py install

To build a package for use with pip:

python setup.py sdist

A package file is built and placed in a subdirectory called dist. This package file can be installed using pip.

cd dist
pip install sparkfun_qwiic_ccs811-<version>.tar.gz

Raspberry Pi Use

For this sensor to work on the Raspberry Pi, I2C clock stretching must be enabled.

To do this:

  • Login as root to the target Raspberry Pi

  • Open the file /boot/config.txt in your favorite editor (vi, nano …etc)

  • Scroll down until the block that contains the following is found: .. code-block:: ini

    dtparam=i2c_arm=on dtparam=i2s=on dtparam=spi=on

  • Add the following line: .. code-block:: ini

    # Enable I2C clock stretching dtparam=i2c_arm_baudrate=10000

  • Save the file

  • Reboot the raspberry pi

Example Use

See the examples directory for more detailed use examples.

from __future__ import print_function
import qwiic_ccs811
import time
import sys

def runExample():

    print("\nSparkFun CCS811 Sensor Basic Example \n")
    mySensor = qwiic_ccs811.QwiicCcs811()

    if mySensor.isConnected() == False:
        print("The Qwiic CCS811 device isn't connected to the system. Please check your connection", \
            file=sys.stderr)
        return

    mySensor.begin()

    while True:

        mySensor.readAlgorithmResults()

        print("CO2:\t%.3f" % mySensor.getCO2())

        print("tVOC:\t%.3f\n" % mySensor.getTVOC())


        time.sleep(1)


if __name__ == '__main__':
    try:
        runExample()
    except (KeyboardInterrupt, SystemExit) as exErr:
        print("\nEnding Basic Example")
        sys.exit(0)

SparkFun - Start Something

Indices and tables