UDOO Board : Command Line Arduino, an Open Challenge!

In my last post we setup a UDOO Board and ran our first, non-trivial sketch.

But when I was writing that post, my original goal was to show how to compile and upload Arduino sketches from the command line. That should be simple, right? Right? Surely!

Not so much as it turns out... 

Apparently working on Arduino from the command line is a challenging, "advanced users only" task. Working on Arduino from the command line of a relatively new and less-supported platform like the UDOO board is even more so. So after many hours of working on this, I have not yet fully conquered it...

So I present this blog as an open challenge! I intend to update it as I make more progress, but I also hope to solicit help in the comments if anyone else out there has had similar problems and had more success defeating them!

The Sketch

I choose a really simple sketch to execute, just a high speed variant of the standard Blink tutorial:

int LED_1 = 23;

void setup() {  
  pinMode(LED_1, OUTPUT);     

void loop() {  
  digitalWrite(LED_1, HIGH);
  digitalWrite(LED_1, LOW);

My UDOO Board is wired with a single LED / resistor pair as shown here:

Nothing too difficult, just a proof of concept. I verified that the sketch and the circuit functioned correctly using the Arduino IDE that is provided in the Desktop GUI to rule out any problems with the hardware.

Command Line

My first attempt has been to use the Ino open source library available on github. Ino is a command line tool that can build and upload sketches to a Arduino board from the command line. Just the thing I needed!

First I first tried installing Ino from source (downloading from github and running the make file.) Six missing dependencies later, I gave this up and tried a different approach.

I installed pip (a package manager tool for Python):

sudo apt-get install python-pip  

With pip installed I could install ino with all its dependencies automatically.

sudo pip install ino  

With ino installed I could test to see if it could see my Arduino board. By running:

ino list-models  

Immediately this failed with the complaint that it could not find boards.txt (which defines what Arduino devices are available and how to communicate with them.) Conveniently however, it listed where it was looking. 

I discovered that on the UDOO board, the Arduino tools were not installed in /usr/share/arduino/ where ino expected it, but rather in /opt/arduino-1.5.4.

My first solution was to create a soft link between /usr/share/ and /opt/. Like so:

sudo ln -s /opt/arduino-1.5.4 /usr/share/arduino  

I later realized that ino can also take a parameter indicating where to look for Arduino:

ino list-models -d /opt/arduino-1.5.4/  

Which may be cleaner depending on your use case. 

Unfortunately, both of these proved to be only partial fixes. When trying to find boards.txt, ino only looks in <ARDUINO>/hardware/arduino directories. As of Arduino 1.5 and later, there can be subdirectories (/sam in the case of a UDOO board), which ino does not scan.

NOTE: This is the point at which I lost my dignity as a programmer and devolved into a hacker who just wanted to make this thing work. In retrospect, this is also probably also the point where I should have started trying something else instead of ino... But oh well. Too late for that...

So I decided to relocate the contents of the sam directory into its parent directory.

cp -R /opt/arduino-1.5.4/hardware/arduino/sam/* /opt/arduino-1.5.4/hardware/arduino  

That fixed ino's immediate issues, I finally got the list-models command to execute successfully:

arduino_due_x_dbg: Arduino Due (Programming Port)  
arduino_due_x: Arduino Due (Native USB Port)  

That looked much better! I was then able to successfully initialize an ino project:

mkdir ~/arduino_blink  
cd arduino_blink  
ino init -t arduino_blink  

I modified the source code to match my sketch above and tried to build the ino project:

ino build -m arduino_due_x_dpg  

Errr... After processing for several minutes, this command failed with the rather crypted make error "argument list too long". Turns out that ino recursively links the libraries it finds in the Arduino installation directory. If you have a lot of system libraries, this can generate an enormous list and kill the tool chain because there are too many parameters.

The workaround that I discovered was to simple relocate the Arduino libraries elsewhere. (See note about turning from programmer to hacker... I _have _to beat this thing now!)

sudo mv /opt/arduino-1.5.4/libraries /opt/arduino-1.5.4/libraries_BAK  
sudo mkdir /opt/arduino-1.5.4/libraries  

Repeating the build command progressed _much _more quickly this time!

The next error it spit out was that it could not find avr-gcc (its default tool chain command). Seems reasonable. After looking around I see that there is a /opt/arduino-1.5.4/hardware/tools/arm-none-eabi/arm-none-eabi/bin/gcc tool which looks more promising. Even better, the running:

ino build --help  

Indicates that there is a --cc parameter that allows you to overwrite the default compiler. 

I will save you the long succession, but it turns out that ino build also wants a g++, an ar, and an objcopy tool, all of which have parametric overrides in the build command. It was not long before my build command had swelled to:

ino build -m arduino_due_x_dbg --cc /opt/arduino-1.5.4/hardware/tools/arm-none-eabi/arm-none-eabi/bin/gcc --cxx /opt/arduino-1.5.4/hardware/tools/arm-none-eabi/arm-none-eabi/bin/g++ --ar /opt/arduino-1.5.4/hardware/tools/arm-none-eabi/arm-none-eabi/bin/ar --objcopy /opt/arduino-1.5.4/hardware/tools/arm-none-eabi/arm-none-eabi/bin/objcopy  

And this brings us to the finale:

unrecognized command line option '-mmcu=cortex-m3'  

This is where I am currently stumped. All my hackery has been for naught thus far. So I present the challenge to my readers. What next? 

Should I abandon ino and try a different approach? 

Did I just pick the wrong tool chain?

Did I miss an obvious means of installing avr-gcc?

That is the challenge! What is next?

Should I overcome this challenge I will update this blog. But if you figure it out first, sound off in the comments! 

Questions? Comments? Give me a shout out at: [email protected]!