Configuring your Pi for I2C

Author Gravatar Image KEVIN TOWNSEND
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.  

If you are running Occidentalis and are familiar with Terminal commands, then the description below will be sufficient.

If not, then to learn more about how to setup I2C with either Raspbian or Occidentalis, then take a minor diversion to this Adafruit Tutorial: http://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c
Copy Code
sudo apt-get install python-smbus
sudo apt-get install i2c-tools
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:
Copy Code
sudo i2cdetect -y 1
This will search /dev/i2c-0 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.
Last updated on 2014-04-25 at 12.16.02 AM Published on 2012-08-24 at 08.17.01 PM