Configuring I2C

I2C is a very commonly used standard designed to allow one chip to talk to another. So, since the Raspberry Pi can talk I2C we can connect it to a variety of I2C capable chips and modules.

The I2C bus allows multiple devices to be connected to your Raspberry Pi, each with a unique address, that can often be set by changing jumper settings on the module. It is very useful to be able to see which devices are connected to your Pi as a way of making sure everything is working.

Download: file
sudo apt-get install -y python-smbus
sudo apt-get install -y i2c-tools

Installing Kernel Support (with Raspi-Config)

Run sudo raspi-config and follow the prompts to install i2c support for the ARM core and linux kernel

Go to Interfacing Options

On older versions, look under Advanced

then I2C

Enable!

Download: file
sudo reboot

Testing I2C

Now when you log in you can type the following command to see all the connected devices

Download: file
sudo i2cdetect -y 1

This shows that two I2C addresses are in use – 0x40 and 0x70.

Note that if you are using one of the very first Raspberry Pis (a 256MB Raspberry Pi Model B) then you will need to change the command to:

Download: file
sudo i2cdetect -y 0

The Raspberry Pi designers swapped over I2C ports between board releases. Just remember: 512M Pi's use i2c port 1, 256M ones use i2c port 0!

When you are finished in raspi-config reboot for the i2c modules to automatically load into the kernel.

This guide was first published on Dec 14, 2012. It was last updated on Dec 14, 2012. This page (Configuring I2C) was last updated on Jun 16, 2019.