Monday, November 12, 2012

Arduino Nano v3.0 bootloader

Last week I finally received a package from DX.com containing the Arduino Nano compatible board I've ordered nearly 2 month ago. For the price I've paid, just over $13, I wasn't expecting much and had already considered the money lost somewhere between China and Portugal.
Inside the package was the board, a long and thick USB cable and a small breadboard I've ordered with the Arduino. A long thread runs on the DX forum on the legitimacy of the name Arduino on these boards. That's another story.

I jumped to my netbook and downloaded the latest software package from arduino.cc. While downloading, I tried to mount the tiny board on the breadboard, just to find that either the board pins are too thick or the breadboard holes are too tight. Afraid of bending the pins or worse, breaking the board, I left it half way inserted.


In a hurry I connected the board to the netbook, which is running Windows7, by the way, and the USB to Serial drivers were installed straight away from Windows Update. So far, so good.
On connection, a bright tiny green LED came on. As the board comes with zero documentation, I didn't know exactly what this meant. Green is good, so move on.

Nano schematics: http://arduino.cc/en/uploads/Main/ArduinoNano30Schematic.pdf

After unzipping the package, a massive 90 MB file, I launched the Arduino IDE. This is very basic, and there's not much to configure, other than the COM port, the board type and the programmer which at that moment I hadn't realized if it would be necessary.
From then on, my patience was put to a test. Communicating with the board was a no go. No matter what setting I fiddled with, AVRDude, the program that talks to the micro, refused to establish a connection.

After hours of hell on earth checking every reference to this fact on Google, I decided that a new boot loader was the way to go. The boot loader basically is a piece of code that sits in the micro memory, taking about 2KB of space, and negotiates the upload of programs to memory, with the help of AVRDude or similar. The boot loader executes after the micro resets. It then waits for a few seconds for the serial lines to be active and to receive a predefined sequence of bytes indicating that a program is about to be upload.

The bad news were that my Nano board had come with a defective boot loader. There are two LEDs on the board, marked TX and RX, that blinked three or four times when the Upload button was clicked on the IDE. A few seconds later a message was displayed reporting there was a synchronization problem.
After installing AGG Software excellent tool Advanced Serial Port Monitor, I quickly found out that all attempts made by AVRDude to contact the Nano were being ignored.
No problem. The solution was on arduino.cc forums. A parallel port programmer is all you need to burn a new boot loader.

Parallel programmer on arduino.cc: http://arduino.cc/en/Hacking/ParallelProgrammer

A few resistors and some pieces of wire later, a programmer was ready to run.


Now, things can't be that easy. Although the programmer was built to the specs, failure hunted me back when trying to burn the boot loader, no matter what I did.
In total despair, I turned to the parallel port itself. In a rare moment of lucidity, I decided to look at the BIOS of the laptop. The port was set as bidirectional, and that sounded right. To fight the odds, I have decided to change the port setting to EPP (Enhanced Parallel Port). Reboot applied and voilá!
The Arduino IDE uploaded the boot loader in a few seconds, with the RX/TX LEDs happily blinking.
A minute later I was uploading my "blink" sketch to the Nano board.
Ufff!