TechplexEngineer
3/6/2014 - 3:04 AM

Raspberry PI I2C setup

Raspberry PI I2C setup

Note to the reader: Code blocks beginning with a $ are commands to be run on a RPI Rasbian shell.

  1. Enable I2C support
    1. add i2c-dev to the end of /etc/modules
    2. comment out (with a #) the line that says blacklist i2c-bcm2708 in /etc/modprobe.d/raspi-blacklist.conf
  2. Enable the current user to access I2C hardware
    1. install i2c-tools (includes i2cdetect and adds the i2c group) with: $ sudo apt-get update && sudo apt-get install i2c-tools
    2. add the current user to the i2c group with: $ sudo adduser <USER> i2c where <USER> is the username to add to the i2c group
  3. Get the chip-address on the bus of a connected device
    1. $ i2cdetect -y i2cbus Where:
      • i2cbus is the # bus; RPIv2 bus=1; RPIv1 bus=0
  4. Get the data on the I2C bus:
    1. $ i2cget -y i2cbus chip-address [data-address [mode]] Where:
      • i2cbus is the # bus, for us it was 1
      • chip-address is the value returned from i2cdetect (0x48)
      • data-address is the value of the data in the device to read, you'll have to find this value in the datasheet (0x00)