Flashing an Arduino from a Raspberry Pi

With the whole staircase project coming to an end and almost ready to move the hardware (the 16-channel LED driver, Arduino) from my lab to their final location (i.e. near the stairs), I struggled with a convenience issue that I wanted to resolve before mounting all the hardware where it belongs. How to flash the Arduino when it’s not connected to my PC anymore but in some enclosure, under the stairs? The solution was surprisingly simple.

I read about TFTP bootloaders, Serial connections using the Raspberry Pi GPIO and more, but those solutions just weren’t what I was looking for. The Arduino IDE is available for Linux, so would there there be something out there like a “Arduino cli for compiling and flashing” ? There is! Within a few clicks I ended up here, Makefile for Arduino sketches. And guess what, I read that there’s a package called arduino-mk for FreeBSD, Debian and Ubuntu. I stopped reading and first tried to install the package on my Raspberry Pi:

$ sudo apt-get install arduino-mk

Yippie, it works! I created a ~/sketchbook/staircase directory, downloaded the partially finished sketch with ftp from my NAS and started reading about a suitable Makefile in the directory mentioned above. This is it:

BOARD_TAG = atmega328
ARDUINO_PORT = /dev/ttyUSB0
ARDUINO_LIBS = SPI I2C pca9635 i2c_device
ARDUINO_DIR = /usr/share/arduino
include /usr/share/arduino/Arduino.mk

The BOARD_TAG needs to be changed to the right Arduino board type (in my case a Duemilanove). To list all board_tags, you can do a make show_boards and pick the right tag for your board. Another thing that has to be done is adding all the libraries the sketch uses on the ARDUINO_LIBS line. That’s it…

I connected my Duemilanove to the Raspberry Pi with a USB cable and did a make upload:

make staircase

Wow! Now I can do everything from behind my PC: edit the sketch, compile it and upload the result to an Arduino that’s placed near the stairs, at the other end of the house.. very convenient!

Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *