Working with Arduino sketches on the command line on a Mac

I like using Emacs and the command line, even on a Mac where everything is supposed to be just a few mouse clicks away. The Arduino IDE is great to get started and if you check the “use external editor” box you can also use Emacs or any other editor you prefer.

Compiling and uploading Arduino projects from the command line requires a little more work. I use CrossPack for AVR® Development for pure AVR projects. CrossPack comes with a simple, easy to use Makefile template to run the avr-gcc toolchain and avrdude. So I was looking for something like the CrossPack Makefile template but for the Arduino.

Many people have written Makefiles for Arduino. For example, take a look at the Advanced Arduino Hacking article in PragPub Issue #22, April 2011 by Maik Schmidt. He uses a modified version of Alan Burlison’s A Makefile for Arduino Sketches. Both variants require some tweaks to work with the current Arduino 1.0.1, e.g. the default filename extension is now .ino. However, Alan’s website pointed me to Arduino from the command line by Martin Oldfield,

This works really well. The package comes with perl scripts to parse the Arduino IDE’s board.txt file and to reset the serial port. I had to install two more Perl packages to make them work:

$ sudo port install p5-YAML
$ sudo port install p5-device-serialport

The Makefile always sets two leonardo specific variables USB_VID and USB_PID even if you use a non-leonardo board such as the uno:

build.vid isn't defined for the uno board, at /Users/ubiyubix/bin/ard-parse-boards line 50. isn't defined for the uno board, at /Users/ubiyubix/bin/ard-parse-boards line 50.

This can be safely ignored, but I wrapped setting those variables in an ifeq ($(VARIANT),leonardo) to get rid of it. My github fork

This entry was posted in arduino and tagged , . Bookmark the permalink.

One Response to Working with Arduino sketches on the command line on a Mac

  1. Asher says:

    Thanks so much for the post – was mystified by the error. Please make a pull request for the main repo!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s