Configuring Your Pi for I2C

Before you can get started with I2C on the Pi, you'll need to run through a couple quick steps from the console.  

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

When you are happy to continue enter the following commands to add SMBus support (which includes I2C) to Python:
Download: file
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:
Download: file
sudo i2cdetect -y 0
This will search /dev/i2c-0 for all address, and if an MCP4725 DAC breakout is properly connected and it's set to it's default address it should show up at 0x62.

If you are using a 512MB Raspberry Pi version 2, you'll want to use /dev/i2c-1 by running sudo i2cdetect -y 1 as the i2c port # changed from #0 to #1
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 17, 2012. It was last updated on Aug 17, 2012. This page (Configuring Your Pi for I2C) was last updated on Sep 20, 2019.