I2C, SMBus and Raspbian Linux

Created 02/10/2015 | Find out how to set up I2C communication on the Rasberry Pi using i2c tools.

This page details how to setup I2C support on the Raspbian “Wheezy” and "Jessie" image from http://www.raspberrypi.org/downloads

Step 1: Download the latest Raspbian linux image and burn to your SD Card following the instructions on http://elinux.org/RPi_Easy_SD_Card_Setup

If you are using Raspian Linux 3.18 or later you need to go into the raspberry pi config utility and enable I2C.

sudo raspi-config

Select 8 Advanced Options and then  A7 I2C - Enable/Disable automatic loading. A prompt will appear asking Would you like the ARM I2C interface to be enabled?, select Yes, exit the utility and reboot your raspberry pi.

sudo reboot

Step 2: Next you need to update your Raspberry Pi to ensure all the latest packages are installed:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade

Step 3 a:  Once you have logged into your Raspberry Pi from the command line, run the following command to install SMBus and Python Dev:

sudo apt-get install python-smbus
sudo apt-get install python3-smbus
sudo apt-get install python-dev
sudo apt-get install python3-dev

Step 4:  From the command line, run the following command to install i2c-tools:

sudo apt-get install i2c-tools

For previous releases before Raspian Linux 3.18 you need to complete the following steps:

Step 5: Enable I2C and SPI protocols. I2C and SPI protocols are turned off in the wheezy distro by default, so you will need to enable them by editing the file /etc/modprobe.d/raspi-blacklist.conf :

sudo nano /etc/modprobe.d/raspi-blacklist.conf

In the file you will see two lines, you need to disable the blacklisting of these by adding a # character before each line:

#blacklist spi-bcm2708
#blacklist i2c-bcm2708

Save your changes and exit the nano editor.

Step 6:

For recent versions of the Raspberry Pi (3.18 kernel or later) you will need to update the /boot/config.txt file.  Open the file with nano using the command:

sudo nano /boot/config.txt

Add the following text to the bottom of the file:

dtparam=i2c1=on
dtparam=i2c_arm=on

Save your changes and exit the nano editor.

All versions:

Step 7: Set the Raspberry Pi to start I2C automatically at boot by editing /etc/modules :

sudo nano /etc/modules

Use your cursor keys to move to the last line and add a new line and then add:

i2c-dev

Save your changes and exit the nano editor.

Step 8: To avoid having to run the I2C tools at root add the ‘pi’ user to the I2C group:

sudo adduser pi i2c

Step 9: Next reboot the Raspberry Pi:

sudo reboot

When your Raspberry Pi has rebooted you will now have I2C and SMBus Python 2 or 3 support.

Shop

Support

Click to contact us.
X

Have any Questions?

Send us any questions about this page or product and we will reply within 24 hours.

Submit your Message

X

Have any Questions?

Thank you for contacting us.

We will respond to your enquiry in the next 24 hours.

You can find answers to many questions and additional product support in our Knowledge Base and the Community Forum.