I2C - mens-amplio/config GitHub Wiki
Notes on getting the Pi to communicate with an Arduino over I2C, as a precursor to talking to the wifire flame effects board which has an Atmel328 already on board.
The reasoning for using I2C instead of serial is that it doesn't require a level converter to mediate between the Pi's 3.3V and the Arduino's 5V (more in-depth explanation in the tutorial below). Also, the Pi sends console data through serial by default, and it's nice not to have to worry about disabling that.
Mostly following this: http://blog.oscarliang.net/raspberry-pi-arduino-connected-i2c/
- However, Occidentalis is I2C-ready out of the box - requires no editing of config files, and already has i2cdetect and python-smbus installed
- Had to use bus.write_byte(address, value) instead of bus.write_byte_data(address, 0, value) - otherwise Arduino reads 3 bytes every time (0, X, 1). Didn't read enough to determine why this is the case.
- Had to use bus.read_byte(address) instead of bus.read_byte_data(address, 1) - otherwise the Pi always reads a 9 (not that this really matters since we don't need bidirectional communication)
Pins:
- SDA pin is analog pin 4 on the Arduino Uno, which is pin 27 on the Atmega328.
- SCL pin is analog pin 5 on the Uno, which is pin 28 on the Atmega328.
- See Arduino to Atmega pin mappings: http://arduino.cc/en/Hacking/PinMapping168
Reference:
- Docs for Arduino Wire library: http://playground.arduino.cc/Main/WireLibraryDetailedReference