Raspberry Pi Wiring & Test

The Raspberry Pi also has an I2C interface that can be used to communicate with this sensor.

Install Python Software

Once your Pi is all set up, and you have internet access set up, lets install the software we will need. First make sure your Pi package manager is up to date

Download: file
sudo apt-get update

Next, we will install the Raspberry Pi library and Adafruit_GPIO which is our hardware interfacing layer

Download: file
sudo apt-get install -y build-essential python-pip python-dev python-smbus git
git clone https://github.com/adafruit/Adafruit_Python_GPIO.git
cd Adafruit_Python_GPIO
sudo python setup.py install

Next install the adafruit CCS811 python library.

Download: file
sudo pip install Adafruit_CCS811

Enable I2C

We need to enable the I2C bus so we can communicate with the sensor.

Download: file
sudo raspi-config

select Advanced options, enable I2C, and then finish.

Once I2C is enabled, we need to slow the speed way down due to constraints of this particular sensor.

Download: file
sudo nano /boot/config.txt

add this line to the file

Download: file
dtparam=i2c_baudrate=10000

press Ctrl+X, then Y, then enter to save and exit. Then run sudo shutdown -h now to turn off the Pi and prepare for wiring.

Wiring Up Sensor

With the Pi powered off, we can wire up the sensor to the Pi Cobbler like this:

  • Connect Vin to the 3V or 5V power supply (either is fine)
  • Connect GND to the ground pin on the Cobbler
  • Connect SDA  to SDA on the Cobbler
  • Connect SCL to SCL on the Cobbler
  • Connect Wake to the ground pin on the Cobbler

You can also use direct wires, we happen to have a Cobbler ready. remember you can plug the cobbler into the bottom of the PiTFT to get access to all the pins!

Now you should be able to verify that the sensor is wired up correctly by asking the Pi to detect what addresses it can see on the I2C bus:

Download: file
sudo i2cdetect -y 1

It should show up under it's default address (0x5A). If you don't see 5A, check your wiring, did you install I2C support, etc?

Run example code

At long last, we are finally ready to run our example code

Download: file
cd ~/
git clone https://github.com/adafruit/Adafruit_CCS811_python.git
cd Adafruit_CCS811_python/examples
sudo python CCS811_example.py

If everything is set up correctly, you should see it print out a few 0 readings, and then every few seconds it will print out another reading

This guide was first published on Aug 02, 2017. It was last updated on Aug 02, 2017. This page (Raspberry Pi Wiring & Test) was last updated on Aug 10, 2018.