Preparing for à la mode: Raspberry Pi and Arduino

Well, I got my Raspberry Pi, and preparations are well underway to make an Arduino compatible clone that fits right on top.

Anool Mahidaria has completed an initial circuit design, and I’ve gotten some of the software set up. Lots of information out there that helped me figure out what to do, so I thought I’d compile it here in one place.

à la mode will connect via the uart on the GPIO, so we need to figure out how to enable serial communications, and get the Arduino environment installed.

Serial port: An embarrassment of riches?

The Pi’s Broadcom brain has a very rich set of peripherals, unfortunately it was hard for the Pi’s designers to route them all out to a connector. There’s a limited functionality min-uart that is very well supported, and at least in the debian image I’ve tried has drivers.

It doesn’t have hardware handshaking or DTR (needed for auto reset on the Arduino) but is supported at this stage so I think that’s what we’ll go with. There’s also a fully featured UART, and most of it’s compatible pins are brought out to the GPIO connector, but as far as I can tell, it’s not fully supported in the distributions generally available for the Pi.

The GPIO connector is well documented on the Pi’s wiki:

But I found this blog post most helpful: http://lavalink.com/2012/03/raspberry-pi-serial-interfacing/ from which I get this useful illustration.

That’s great, but it turns out that the Serial port is a little too well supported. (Caveat, I’m talking about the recommended Debian Squeeze image) You can log into it as a console! This, of course, prevents you from opening the port in a program (such as Arduino), so we need to disable logins on this port, as well as logging messages that go out. This post explains how to disable both.

I’ll repeat the instructions here, in case the link goes away:

First, disable logging messages:

Edit /boot/cmdline.txt

From:

[code]dwc_otg.lpm_enable=0 rpitestmode=1 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait[/code]

to:

[code]dwc_otg.lpm_enable=0 rpitestmode=1 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait[/code]

deleting the two parameters involving the serial port /dev/ttyAM0

You also have to edit /etc/innitab to remove the login (getty)

comment out:

[code]2:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100[/code]

then reboot.

Arduino IDE:

The Homelabs raspberry pi blog has good concise instructions for installing the Arduino IDE. The IDE is written in Java (based on Processing) and while Oracle doesn’t have an official Java for the ARM core in the Pi, the Open JDK has been ported. It doesn’t have a JIT (Just In Time Compiler) so it’s a little slower, but it works.

First grab the Arduino IDE code. (you can change the url if you want the latest)

[code]wget http://arduino.googlecode.com/files/arduino-1.0-linux64.tgz
tar zxvf arduino-1.0-linux64.tgz[/code]

The Arduino IDE is written in Java, but there are native parts to do compilation for the atmega328p  microcontroller. Fortunately those have also been ported:

[code]
sudo apt-get install avr-libc
sudo apt-get install libftdi1
sudo apt-get install avrdude

[/code]
Java:

[code]sudo apt-get install openjdk-6-jre[/code]

Serial support:
[code]sudo apt-get install librxtx-java[/code]

And then copy the native stuff into the Arduino directory:

[code]
cd arduino-1.0
for i in $(find . -name “librxtxSerial.so”) ; do cp /usr/lib/jni/librxtxSerial.so $i ; done
for i in $(find . -name “RXTXcomm.jar”) ; do cp /usr/share/java/RXTXcomm.jar $i ; done
cp /usr/bin/avrdude /home/pi/arduino-1.0/hardware/tools/avrdude
cp /etc/avrdude.conf /home/pi/arduino-1.0/hardware/tools/avrdude.conf

[/code]

After this, you can attach an Arduino to one of the USB ports, or (carefully) a 3.3 v clone to the GPIO pins.

More to come!