Enabling i2c on the Raspberry Pi

Getting an I2C device to work with your Raspberry PI requires a few steps, in this guide we show how to enable this.

First of all you have to start up the raspian config tool, you do this as follows

sudo raspi-config

Select ‘Advanced Options’ and then select the relevant option.
Enabling The I2C Port On Old Raspbian Distributions

The I2C ports need to be enabled in Raspbian before they can be used.

Edit the modules file by typing the following in the terminal window

sudo nano /etc/modules

Add these lines:
i2c-bcm2708
i2c-dev

Exit and save the file

Now you need to edit the modules blacklist file by typing the following in the terminal window. Note this file may be blank, in this case skip the step.

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

Add a ‘#’ character to this line so it commented out:
#blacklist i2c-bcm2708

Exit and save the file.

Finally install the required I2C utilities, again in the terminal type the following

sudo apt-get install python-smbus
sudo apt-get install i2c-tools

Type in “sudo reboot” to restart and I2C should be available. Connect an I2C device up and run the folllowing to test
sudo i2cdetect -y 1

On the older Raspberry Pi’s you hav eto use port 0

sudo i2cdetect -y 0

 

I connected an I2C SSD1306 OLED display, this is what I saw in the terminal window

i2cdetect output
i2cdetect output
SHARE
Previous articlePython query SQlite database example
Next articleRaspberry PI LCD plate