Raspberry Pi and Arduino

I program and control an Arduino UNO R3 from a Raspberry Pi using C instead of the Processing language.

Development Tools

The official Arduino IDE is Java-based and runs out of my 16GB SD card with Raspbian pre-installed. So I turned to use avr-gcc, which requires me to program using C, instead of the Processing language supported by Arduino IDE. But I like C as it allows me to accurately control my Arduino. To install required development tools:

sudo apt-get install gcc-avr binutils-avr gdb-avr avr-libc avrdude

A Sample Program

An example program named blink.c can be found in this Wikipage. It simply blinks the LED on Arduino board.

I use the Makefile downloaded from here. I only need to edit the first two lines of this Makefile and specify my program name.

Upload Binary

Above Wikipage shows how to use dmesg to identify the Unix device used to connect Arduino. In my case where I use a USB hub, the device is /dev/ttyACM0. The we use the following command line to upload the program:

avrdude -v -v -v -v -carduino -patmega328 -P/dev/ttyACM0 -U flash:w:blink.hex

Live Demo

I recorded this Youtube video to show you how this works. In the video, you can see the LED on my Arduino blinks.