Installing and enabling I2C on the #RaspberryPi running Raspbian

I’m rather cheekily taking most of this from ThinkBowl.com as it’s a brilliant, simple walk-through that I’d hate to lose if the site disappeared! I’ve added some comments by way of explanation, just to add a little value.

  1. First install the i2c-tools:
    apt-get install i2c-tools
  2. Next SPI and I2C is “blacklisted” (i.e. turned off) from modprobe (the module loader) by default. Edit /etc/modprobe.d/raspi-blacklist.conf with vi or nano and comment out (place # as first character on line):
    blacklist i2c-bcm2708
  3. To ensure modules are loaded at boot add the following lines to /etc/modules:
    i2c-bcm2708
    i2c-dev
  4. Optional: If you are going to access the I2C from users other then root create a file called /etc/udev/rules.d/99-i2c.rules with the following line:
    SUBSYSTEM==”i2c-dev”, MODE=”0666″
    This will allow access from every user. To allow access only from a specific group:
    SUBSYSTEM==”i2c-dev”, GROUP=”input”, MODE=”0666″
  5. Reboot the pi by issuing:
    reboot
  6. After the reboot, verify that the I2C devices are available:
    ls /dev/i2c*
  7. Optional: If you are using I2C with Python, you will need the smbus python library as it is not installed by default:
    apt-get install python-smbus
  8. Once you have the I2C device attached, you can determine the address by running:
    i2cdetect -y <port>
    Replace <port> with 0 for Revision 1 Raspberry Pis and with 1 for Revision 2 boards.

 

1 comment for “Installing and enabling I2C on the #RaspberryPi running Raspbian

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.