Skip to content

Instantly share code, notes, and snippets.

@TechplexEngineer
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save TechplexEngineer/9381470 to your computer and use it in GitHub Desktop.

Select an option

Save TechplexEngineer/9381470 to your computer and use it in GitHub Desktop.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment