Release date: 2017 March 31
This is an Arduino library that helps establish I2C communication with a Raspberry Pi, with the Arduino acting as the I2C slave. It should work with most Arduino-compatible boards, but we designed it for use with these Pololu products:
These boards are designed to connect conveniently to the Pi's GPIO header. The idea is that the Raspberry Pi can take care of high-level tasks like video processing or network communication, while the AVR microcontroller takes care of actuator control, sensor inputs, and other low-level tasks that the Pi is incapable of.
There are a few reasons we made a library for this instead of just recommending the standard Arduino I2C library, Wire.h:
- Wire.h just gives you access to raw I2C packets; you have to decide how they should relate to your data, and that's not trivial. This library implements a specific protocol allowing bidirectional access to a buffer, with atomic reads and writes.
- The processor on the Raspberry Pi has a major bug that corrupts data except at very low speeds. The standard Arduino I2C library, Wire.h, is not flexible enough to allow us to follow the suggested workarounds (delays inserted at key points).
We have included example Arduino code for the A-Star or Romi and Python code for the Raspberry Pi. Together, the examples set up a web server on the Raspberry Pi that will let you remotely control and monitor a robot from your smartphone or computer.
See this blog post for a complete tutorial including step-by-step build instructions for an example robot.
The included script
benchmark.py times reads and writes of 8 bytes,
to give you an idea of how quickly data can be transferred between the
devices. Because of a limitation in the AVR's I2C module,
we have slowed down reads significantly.
|100 kHz||21 kbit/s||53 kbit/s|
|400 kHz||43 kbit/s||140 kbit/s|
- 2.0.0 (2017 Mar 31): Added support for encoder counts and slave sketch for the Romi 32U4 robot. Updated Raspberry Pi scripts to use Python 3 instead of Python 2.
- 1.0.1 (2017 Jan 23): Added and adjusted delays necessary for reliable operation on the Pi 3.
- 1.0.0 (2016 Feb 16): Original release.