Computing stuff tied to the physical world

Arduino sketches on RPi

In AVR, Software, Linux on Jan 17, 2013 at 00:01

There’s an arduino-mk package which makes it simple to build and upload sketches on a Raspberry Pi. Here’s how to set it up and use it with a JeeLink, for example:

Install the package:

  sudo apt-get install arduino-mk

That gets all the required software and files, but it needs a tiny bit of setup.

First, create the library area with a demo sketch in it:

  mkdir ~/sketchbook
  cd ~/sketchbook
  ln -s /usr/share/arduino/Arduino.mk
  mkdir blink
  cd blink

Then create two files – the blink.ino sketch for a JeeLink or JeeNode SMD / USB:

// Blink - adapted for a JeeNode / JeeLink

void setup() {
  pinMode(9, OUTPUT);
}

void loop() {
  digitalWrite(9, LOW);
  delay(1000);
  digitalWrite(9, HIGH);
  delay(1000);
}

… and a Makefile which ties it all together:

BOARD_TAG    = uno
ARDUINO_PORT = /dev/ttyUSB0
ARDUINO_LIBS =
ARDUINO_DIR  = /usr/share/arduino

include ../Arduino.mk

(that Arduino.mk file in the sketchbook/ dir is well-commented and worth a read)

That’s it. You now have the following commands to perform various tasks:

  make             - no upload
  make upload      - compile and upload
  make clean       - remove all our dependencies
  make depends     - update dependencies
  make reset       - reset the Arduino by tickling DTR on the serial port
  make raw_upload  - upload without first resetting
  make show_boards - list all the boards defined in boards.txt

The first build is going to take a few minutes, because it compiles the entire runtime code. After that, compilation should be fairly snappy. Be sure to do a make clean whenever you change the board type, to re-compile for a different board. The make depends command should be used when you change any #include lines in your code or add / remove source files to the project.

This setup makes things run smoothly, without requiring the Arduino IDE + Java runtime.

  1. On linux/osx I like to use https://github.com/suapapa/arscons which is a slightly more friendlier way to build stuff than Makefiles. The logic is python instead of the hackage Make language..

  2. I hope it’s OK to make a little shameless plug :). Recently my linuxgpio programmer type was finally included in upstream SVN of avrdude. With it you can connect an AVR to any 4 GPIO lines on an embedded Linux board (like the RPi) and program it directly, without the need of a bootloader. This way you also free up the USB port. You can find more info here: http://kolev.info/avrdude-linuxgpio

    I hope you may find it useful, and thanks for the great blog!

    Regards, Rado

  3. Thanks Radoslav, nice ISP. How would one use the arduino-mk for the ATTiny84 processor? Could we direct the output directly to your programmer in a one step process?

  4. I’ve never used arduino-mk, but I had a quick look at it and it seems it should be easy. There is a section there called ARDUINO WITH ISP where you should replace “ISP_PROG = -c stk500v2” with “ISP_PROG = -c linuxgpio” and then use “make ispload”.

  5. Thank you once again Radoslav, that is great. I now need to find out how to get the ATTiny84 support into arduino-mk.

Comments are closed.