The Adruino Diecimila board supposedly has circuit protection to ensure that one doesn’t fry their computer accidentally, but just in case, I figured it might be better to use a spare machine for my Arduino hacking. I happened to have an older PowerBook that fits the bill perfectly; however, I run Ubuntu PPC on it, and it didn’t take long for me to realize that neither the Arduino OS X or Linux builds would work on it.

Not to be discouraged, some quick googling led to the instructions on patching up the OS X release for Ubuntu PPC. However, a little more googling dug up something much more interesting: Arduino from the Command Line.

It’s not obvious while using the Arduino/Wiring IDE, but you’re really just writing C without includes and prototypes. When you save, the IDE patches up your code, then passes it to gcc-avr for compiling and avrdude for flashing. Therefore, if you’re so inclined (or happen to prefer vi and be on a non-supported platform), one can simply add the extra code manually and build/flash yourself.

The docs on this (linked above) tell the story, but they’re a little out of date (since they reference release 0007.) You still need to “sudo apt-get install gcc-avr avr-libc avrdude”, but after that, download the “Arduino 0009 installer for Linux” [the newest at the time of writing] instead, uncompress it, and look in “lib/targets/arduino/” for the Makefile and libraries you need. Read the comments in the Makefile — they explain it all quite well.

Once you stash the libraries somewhere handy, starting a new project goes like this:

  1. Create a new directory to work in
  2. Write your Arduino code as a *.cpp instead of a *.pde file
  3. Copy and modify the Makefile for your project
  4. Run ‘make’ to compile it
  5. Run ‘make upload’ to flash your code to the Arduino

It’s not as simple as the IDE, but it works, it lets you use any text editor you want, and gets you a little closer to whats going on behind the scenes.

For those curious, I’ve included an example of how the supplied “Blink” sample looks once modified for command-line building. It’s a bit longer… but still manageable:


/*
 * Blink (modified for command-line building)
 *
 * The basic Arduino example.  Turns on an LED on for one second,
 * then off for one second, and so on...  We use pin 13 because,
 * depending on your Arduino board, it has either a built-in LED
 * or a built-in resistor so that you need only an LED.
 *
 * http://www.arduino.cc/en/Tutorial/Blink
 */

#include <WProgram.h>

void setup();
void loop();
int main();

int ledPin = 13;                // LED connected to digital pin 13

void setup()                    // run once, when the sketch starts
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

void loop()                     // run over and over again
{
  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(1000);                  // waits for a second
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(1000);                  // waits for a second
}

int main() {
  init();
  setup();

  for (;;)
    loop();

  return 0;
}