Build Go Programs for Raspberry Pi

I tend to do cross compiling with Go >=1.5, so I don’t have to build Go on Raspberry Pi, which is slow.

GOOS=linux GOARCH=arm GOARM=6 go build -a

Please remember to use -a to avoid cached built packages.

Also, please remember to set the correct GOARM version. To get the ARM version, you can run

cat /proc/cpuinfo

On my Raspberry Pi, it outputs

yi@raspberrypi:~ $ cat /proc/cpuinfo
processor	: 0
model name	: ARMv6-compatible processor rev 7 (v6l)
BogoMIPS	: 2.00
Features	: half thumb fastmult vfp edsp java tls 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xb76
CPU revision	: 7

Hardware	: BCM2708
Revision	: 000e
Serial		: 00000000cd23b897

The line model name : ARMv6-compatible processor rev 7 (v6l) tells that it is ARMv6, so I set GOARM=6.

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.