I sat down last night to write a quick test program to make sure I understood how to program the watchdog timer. OK, I haven’t done this in a long time, looks simple enough though, I’ll be done in 20 minutes.
Yeah, right. Three hours later it still doesn’t work and I’ve come to learn there is a problem in the Arduino Nano’s bootloader that prevents the WDT from working correctly. In my circumstance, the Nano ran fine up to the point where the WDT reboots, but the Nano never recovers from the reboot. It just flashed the LED rapidly.
After some research of the problem, I found that if you replace the Arduino Nano’s bootloader with the Optiboot loader, the problem will be fixed, and you have some extra program memory left over as well because the Optiboot bootloader is smaller.
I updated a bootloader several years ago but had no memory of what the process was to install a normal Arduino bootloader, much less a different one. BUT I did have the AVR pocket programmer I had used so at least I had everything I needed!
First I needed to connect the Nano to the pocket programmer. The Nano (or at least mine) doesn’t have ICSP header pins soldered in place. It’s got the holes in the PCB, but no pins. But I really didn’t want to solder on pins mainly because there’s not that good a chance I’ll need to do this again.
So my first step was to connect the Nano to a breadboard and connect the AVR pocket programmer to the correct pins on the Nano. I used this website as a guide to getting the hardware setup correctly:
Here is how I connected it all together. I have written the Nano pins next to the diagram of the AVR pocket programmer pin outs along with the wire colors:
Once the hardware was setup, I didn’t want to make any assumptions, so first I simply installed a normal Nano boot loader using the Arduino IDE. To do this, first, select the board as an Arduino Nano:
then I selected the programmer which is the USBtinyISP:
and I burned the bootload by clicking on Burn Bootloader:
Once the bootloader was burned, I compiled and uploaded the blink sketch onto the Nano to be sure it still worked.
While I mainly burned the standard bootloader just to be sure I had the AVR programmer setup properly, I was hoping that a newer bootloader might fix the problem. Unfortunately it did not so I had to continue with installing Optiboot.
While researching how to install Optiboot, I discovered the Optiboot loader is actually in my Arduino installation (I’m using version 1.0.6). Examining the C :\Program Files\Arduino\hardware\arduino directory for the boards.txt file, I found that optiboot is loaded for a few of the boards (like the uno):
uno.name=Arduino Uno uno.upload.protocol=arduino uno.upload.maximum_size=32256 uno.upload.speed=115200 uno.bootloader.low_fuses=0xff uno.bootloader.high_fuses=0xde uno.bootloader.extended_fuses=0x05 uno.bootloader.path=optiboot uno.bootloader.file=optiboot_atmega328.hex
but not for the Nano:
nano328.name=Arduino Nano w/ ATmega328 nano328.upload.protocol=arduino nano328.upload.maximum_size=30720 nano328.upload.speed=57600 nano328.bootloader.low_fuses=0xFF nano328.bootloader.high_fuses=0xDA nano328.bootloader.extended_fuses=0x05 nano328.bootloader.path=atmega nano328.bootloader.file=ATmegaBOOT_168_atmega328.hex
I decided the easiest way to make use of the existing Optiboot loader was to fix the boards.txt file. Rather than mess with the existing entries, I wanted to create the ‘standard’ Optiboot entries using their boards.txt file.
So I downloaded their boards.txt file from here:
I then copied the contents of that file and appended it to the end of the boards.txt file already on my PC. Now I have a bunch of new boards prefixed with [Optiboot]:
At this point I was ready to upload the Optiboot loader. I selected the board titled “[optiboot] arduino duemilanove or nano with atmega 328”, still used the USBtinyISP programmer, and clicked on burn bootloader with a note of trepidation.
I then uploaded the blink sketch into the Arduino nano and it worked perfect.
I use codeblocks for Arduino for most of my Arduino IDE needs. The Optiboot board is not an option for codeblocks. During my research I found that once Optiboot is installed, the Nano can be programmed as if it were an Uno. So I changed the board type to Uno and uploaded the blink sketch again. It uploaded and ran fine.
Now that the bootload was replaced, the last test was to try my WDT program. SUCCESS! It now runs on the Nano just as it does on the Uno.
My last step was to write Uno over the Nano silk screen using a find sharpie. That is to remind me I will need to select the Uno board type for this card. I’m sure I’ll still forget, but hopefully will remember a little quicker.,