Monday, April 7, 2014

How to enable I2C (IIC) in Raspberry Pi

The simple instruction for enabling I2C interface in Raspberry Pi (Rasbian).

I2C (or IIC) is a universal bidirectional bus. I2C is common standard designed to allow one device communicate with another.
The bus can connect multiple devices, each device has an unique address to distinguish them.
Raspberry Pi supports I2C, but it’s disabled by default in Rasbian.

So here is steps for configuring I2C.

Enable kernel modules for I2C

sudo echo "i2c-bcm2708" >> /etc/modules
sudo echo "i2c-dev" >> /etc/modules

Remove enabled modules from kernel black list. Open file

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

and comment out the lines below:

    #blacklist spi-bcm2708
    #blacklist i2c-bcm2708

.. by putting a # in front of them. Save file.

Reboot system.

sudo reboot

Install I2C tools and Python library

Install following packages from default repositories

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

Check connected devices

Use following commnd for Raspberry Pi Model B:

sudo i2cdetect -y 1

And for Raspberry Pi Model A:

sudo i2cdetect -y 0

See example:

i2cdetect output

It shows that an one I2C address is in use - 0x77. So you can use it for communication with I2C device.
Now your Pi is ready to use I2C devices.

No comments:

Post a Comment