If you're following along with a Raspberry Pi, Beaglebone or any other supported small linux computer, we'll use a special library called adafruit_blinka (named after Blinka, the CircuitPython mascot) to provide the layer that translates the CircuitPython hardware API to whatever library the Linux board provides. It's CircuitPython, on Pi!

If you haven't set up Blinka and/or the Adafruit IO Python Library yet on your Raspberry Pi, follow our guide before continuing with the steps on this page:

Enable I2C

We "talk" to the Si7021 sensor over I2C. To do this, we'll need to set up our Pi's I2C interface. You only have to do this once per Raspberry Pi, the interface is disabled by default.

Once you're done with this and have rebooted, verify you have the I2C devices with the command:

sudo i2cdetect -y 1

The output from running this command should look like the following:

Installing the Adafruit_CircuitPython_Si7021 Sensor Library

We'll need libraries to communicate with the Si7021 sensor. Since we're using Adafruit Blinka (CircuitPython), we can install CircuitPython libraries straight to our Raspberry Pi by using PyPi.

Enter the following command into your terminal to install the adafruit_circuitpython_si7021 library:

sudo pip3 install adafruit-circuitpython-si7021

Installing the Adafruit_CircuitPython_NeoPixel Library

To control our NeoPixels, we'll use the NeoPixel Library for CircuitPython

Enter the following command into your terminal to install the Adafruit_CircuitPython_NeoPixel library:

sudo pip3 install Adafruit_CircuitPython_NeoPixel

Python Code Setup

The code for this guide is located on the Adafruit Learning Guides repository on GitHub under the IO House Series

If you'd like to directly load this code on your Pi, type the following in your terminal and press enter:

git clone https://github.com/adafruit/Adafruit_Learning_System_Guides.git

Then, navigate to the directory where the code for this tutorial is located by typing the following into your terminal:

cd Adafruit_Learning_System_Guides/IO_House_Series/Lights_and_Temp

Let's check to make sure the python code is within that directory. To do this, type ls into your terminal and hit enter. You should see io_house_light_temp.py in this directory:

Before running the code, we need to set our Adafruit IO Key (ADAFRUIT_IO_KEY) and Adafruit IO Username (ADAFRUIT_IO_USERNAME).

To do this, open the code in your text editor of choice (I'm using nano for this example) by entering the following into your terminal:

nano code.py

The code should open in the nano editor. Scroll down to the Adafruit_IO_KEY variable and set it to the your Adafruit IO Key. Then, set the Adafruit_IO_USERNAME to your Adafruit IO Username.

When you're done editing the values, save the file by pressing control + x.

When prompted to save the modified buffer, type and press enter.

At the File Name to Write prompt, press enter and you should be directed back to the terminal.

Next, we're going to learn how the code works and run it from our Pi.

This guide was first published on Aug 27, 2018. It was last updated on Jun 14, 2024.

This page (Python Setup) was last updated on Mar 08, 2024.

Text editor powered by tinymce.