Also in today: learning about I2C communications. Tips+resources:

  • @adafruit have a helpful guide to Setting up your Pi for I2C — remember to reboot after enabling I2C modules
  • All commands which access I2C need to be run as root using sudo
  • If you’re not sure which address a particular device is at, run sudo i2cdetect before and after plugging it in and see which address changed
  • If there are libraries available for easily talking to the device you’re using, make use of them. Do this first even if you want to learn about the lower level communications too to ensure that your device is working correctly.
  • Get to know i2cdump, i2cset and i2cget, they’re super useful for poking around in I2C devices

I cobbled together a class for communicating with the ADXL345 by cross-referencing between the Arduino library for that chip and Adafruit’s I2C library, only to find that someone else had done so only hours earlier!