Configuring your Pi for I2C

The Holtek HT16K33 chip used in all of our backpacks communicates using the common I2C bus.  Linux and the Pi both have native support for I2C, but you'll need to run through a couple quick steps from the console before you can use it in Python.  

To learn more about how to setup I2C with Raspbian, take a minor diversion to this Adafruit Tutorial:

Then come back here to continue!

Download: file
sudo apt-get install -y i2c-tools python-smbus
i2c-tools isn't strictly required, but it's a useful package since you can use it to scan for any I2C or SMBus devices connected to your board.  If you know something is connected, but you don't know it's 7-bit I2C address, this library has a great little tool to help you find it:
Download: file
      sudo i2cdetect -y 1

This will search I2C for all address, and if a Holtek HT16K33 breakout is properly connected and it's set to it's default address it should show up as follows (the exact address will vary depending on whether or not you have any of the address solder jumpers set).

If you happen to have one of the original first batch of Raspberry Pis, you will need to change the 1 to a 0 in the command above.

Once both of these packages have been installed, you have everything you need to get started accessing I2C and SMBus devices in Python.
This guide was first published on Aug 24, 2012. It was last updated on Aug 24, 2012. This page (Configuring your Pi for I2C) was last updated on Jun 16, 2019.