Knowledge Base

The AB Electronics UK Knowledge Base provides support solutions, tutorials and troubleshooting guides.

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 Jessie or Raspbian Stretch 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 5 Interfacing Options and then  P5 I2C. 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 python3-smbus python-dev 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:

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

Save your changes and exit the nano editor.

All versions:

Step 6: To avoid having to run the I2C tools at root you will need to add the ‘pi’ user to the I2C group:

sudo adduser pi i2c

Step 7: 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.