The Raspberry Pi and the Arduino are both amazing, and each has its particular strengths. There are lots of projects that use one or the other, but there’s growing interest in solutions that combine the strengths of the two platforms.

We use both on C3Pi (our experimental robot). At present we use I2C to link the two, and today we found a way to simplify the way they are connected. Since there seems to be a lot of interest in this topic, I thought we’d share our approach and explain why the solution is a little simpler that we thought!


The I2C software is easy

We’ve been using our Python library on C3Pi to drive the I2C bus that we currently use to connect the Pi to the Arduino. We’ve also adapted the Arduino I2C slave code which is one of the Arduino  examples.

Both programs are very simple. You can find the current versions on github. (Warning: expect the code to change rapidly as we are experimenting with new ideas!)

Linking the Pi and Arduino hardware is easier than we thought

Until today, we were using a sparkfun level shifter to connect the 3v3 I2C bus used by the Pi to the 5v I2C bus on the Arduino.

It turns out that we don’t need to, because the pull-up resistors on the Pi keep the SDA and SCL lines close enough to 3v3 to be safe, even if they are directly connected.

Until today I thought that wasn’t the case. I dimly remembered that the Arduino has pull-up resistors that are enabled by default when you use the Wire library. However, it turns out that these are weak (high-resistance) pull-ups; the Pi has strong pull-ups which dominate those on the Arduino, making direct connection safe.

This only applies to I2C. If you want to connect the serial port on the Pi to the serial port on the Arduino, you will need some protective circuitry between them. That’s why we have a level shifter on our interface board.

But for I2C, just connect the Pi and Arduino as shown below and everything will be fine!

.————-.           .————.
|  Pi         |           | Arduino    |
|          SDA|———–|SDA         |
|          SCL|———–|SCL         |
|          Gnd|———–|Gnd         |
|             |           |            |
.————-.           .————.

Do you pine for the plug-in peripherals on other platforms like the Grove System from seeed studio or the Gadgeteer?

Are you finding it hard to choose between the great interface boards from companies like Ciseco and Quick2Wire?

Grove real time clock

Grove RTC

Sytech 3 Axis Accelerometer

Sytech 3 Axis Accelerometer

Help is at hand!

We’re about to start prototyping the babelboard – an inexpensive board that lets you connect I2C-based boards from all these families to the Raspberry Pi.

This will allow you to use dozens of I2C-based devices with the Pi without having to design or solder them. Just plug them in and write some code!

Over the next few days we will open up the project on GitHub and start posting details here. The board is fairly simple so we hope to have it available in kit form within weeks.

Find out more

If you want to know more, or have ideas, join our support forum, head over to the babelboard topic and get in touch.

One of the themes that came out of yesterday’s excellent Raspberry Jam at Milton Keynes was the very positive overlap between the Arduino and Raspberry Pi communities.

A lot of us Pi enthusiasts also have Arduinos and use them for projects. We’re beginning to investigate what the two can do together, and we’re seeing a number of projects (like Gordon Henderson’s wiringPi) which let people use their Arduino skills and code to drive hardware attached to the Pi.

Some of us are also currently evaluating a Pi shield from Cooking Hacks which allows you to plug in Arduino shields and control them from the Pi.

Of course, not everyone has both computers. If you’re trying to decide which one to use Andrew back has written a great comparison on DesignSpark.

If you do have both, there are several ways in which the Pi and Arduino can be connected.

You can use the serial ports. You need to remember to insert a level shifter to convert between the Pi’s 3.3 volts and the Arduino’s 5 volts, and you need to write programs to send and parse text at each end of the wire.

For most applications I prefer using I2C or SPI. You still need a level shifter, but the software is pretty straightforward. The standard Arduino examples include a sketch that makes the Arduino act as an I2C slave device, which you can then control from the Pi.

Since you decide on the address the Arduino uses on the I2C bus, you can (in theory) control over a hundred Arduinos from a single Pi! I2C is fairly slow, and if you need to send a lot of information to or from the Arduino then SPI might be a better solution.

One combination that I want to explore when I have time (ha!) links the Pi and the Teensy 3. If you haven’t come across one before, the Teensy is an Arduino-compatible computer with a very small form factor, and the Teensy 3 has a powerful ARM processor while maintaining a high degree of Arduino library compatibility.

It has 16K of RAM – not much by Pi standards, but eight times the memory of a standard Arduino – and it has a much more powerful processor. Together the Pi and the Teensy 3.0 should form an awesome combination.