Building an ATmega328 uploader

The ATmega328 is the heart of the Arduino Uno micro controller and has a very successful ecosystem and is used in hundreds of projects. The ATmega328 can be found as a SSD chip or as 28 DIP chip. The last is the one used in the Arduino Uno, and it is easy to handle and small enough to be used in really small projects.

When starting the design of the GlowSaber I used complete boards for the project, first with the Arduino Nano and later with the Adafruit Pro Trinket. Both boards are complete with USB port, voltage regulation, clock and other features.

As I learned more about Arduino I realized that it is possible to redesign the GlowSaber around the ATmega328 chip, and that only a few extra components are required, like a crystal and two condensers. Of course you need to provide also a well regulated voltage, using a linear regulator like the 7805 chip.

Problem is that to upload the code into the chip you need an AVR Programmer and need to do some magical configuration in your computer and use some arcane programs (the AVR programmer).

However there is an easier alternative, without leaving the Arduino IDE. I stumbled by chance in the excellent article From Arduino to a Microcontroller on a Breadboard. This blog explains how to use an Arduino Uno to burn the bootloader into an ATmega328 chip. The bootloader is the code that allows to upload code to the firmware in the chip.

Once you have bootloaded your chip is ready to get uploaded with any program using also an Arduino Uno, as explained in the article above.

If you are going to program one or two chips, the breadboard solution in the article is enough. But if you want to program several dozens of them then you need a more reliable way of doing it, and not having to deal with flimsy prototype boards and cables. That was my case as I plan to use this technique for my newer GlowSaber design, as well as for my Auduino breakout board.

To achieve that I designed an Arduino Shield that can be used to burn the bootloader and upload programs to an ATmega328 chip. I had the shield fabricated for me at OSH Park, my favorite PCB provider.f86ae9c5963cb58ac72055506a12c0f0
Order from OSH Park

The shield can be used either to burn the bootloader or to upload code into the chip. However they are two different operations and require slightly different configurations.

The bootloader burning configuration requires a complete Arduino Uno board, with the Arduino ISP code loaded, as explained in the article From Arduino to a Microcontroller on a Breadboard. The pins used in to send data to burn the firmware are 10, 11, 12 and 13. Pin 10 in the Arduino is used to control the reset pin in the chip to burn.

The code uploader requires an Arduino board without the chip. It uses pins Tx0 and Rx0 to upload the code. The reset pin needs to be connected to the reset pin in the Arduino board.

The shield has a switch to select whether you want the reset pin connected to pin 10 or to the reset pin in the Arduino board. It also has an option to add LED’s to pins 9, 8 and 7 as suggested in the code for Arduino ISP.

The rest of this blog will show the process of building this shield step by step.

Parts list

You will need the following parts. This is a link to order them from DigiKey

  • (1) zero insertion force (ZIF) 28 pin socket. This is a must if you are going to be doing a lot of chips. 
  • (1) crystal oscillator. The documentation says anything from 4 to 16 MHz. I am using a 16 MHz crystal.
  • (2) matching condensers for the crystal, usually 20~22pF
  • (3) 1 KΩ 1/8 watt resistors
  • (1) 10 KΩ 1/8 watt resistor
  • (1) Green LED 5mm
  • (1) Yellow LED 5mm
  • (1) Red LED 5mm
  • (1) switch slide SPDT
  • (1) male header 40 pins

Arduino Programmer Shield 030

The three 1 KΩ resistors and the LED’s are optional. The board will work without them. The single most expensive part is the ZIF socket, and I did not buy it from DigiKey.  You can find it from other suppliers and is included in the shared cart for completeness.

And last but not least you will need the PCB. You can order from OSH Park following the link above. They will send you three copies of the board for about $25. You will need one for the bootloader, if you plan to burn it and one for the uploader. You can use the third one as a spare.

Arduino Programmer Shield 003

Tools needed

You need a good soldering iron, cutters, pliers, soldering vacuum to remove excess solder or fix mistakes, and a good vise to hold the board

Assembling the board

I have two Arduino Uno R3 boards and all the instructions are based on them. Previous versions of Arduino may have fewer positions in the headers. That should not matter but I have not tested the hardware/software with other boards.

1. Start with the headers.

The Arduino board has four groups of pins with 10, 8, 8 and six pins. The easiest way to solder the headers and make them align right is to put the headers in your Arduino board:

Arduino Programmer Shield 038

Push the headers all the way down

Arduino Programmer Shield 039

and the put the shield on top of the Arduino board Arduino Programmer Shield 040

Solder all the pins and make sure there are no short circuits.

Arduino Programmer Shield 042

If you are going to use the board to burn the bootloader do not put headers in the TX0 and RX0 pins, as the may interfere with the burning operation. See the picture below


2. 10 kΩ resistor

Now notice the resistor close to where the 28 pin socket will be. This resistor need to go on the other side of the board, otherwise it will interfere with the socket. Also the board says 1 kΩ, but we should use the 10 KΩ resistor instead.

Arduino Programmer Shield 045

Once the resistor is soldered in place, cut the leads as flush as possible with the board.

3. Crystal and capacitors

Flip the board again and solder the crystal and the capacitors. They can go either way in the holes

Arduino Programmer Shield 054

4. 1 kΩ resistors

This step is optional. If you don’t plan to add the LED’s you can skip to step 6.

Position the three resistors in their holes. They can go either way, and I like to put them so I can read their color code from left to right

Arduino Programmer Shield 057

5. LED’s

You may want to skip to step six if you are not installing the LED’s. I position them from top to bottom as Yellow, Red and Green. The yellow LED will blink steadily when connected to the Arduino ISP. The red will get on if an error happens while burning the bootloader and the green will flicker to show that there is communication between the Arduino Uno and the Shield. The LED’s are only used while burning the bootloader.

The LED’s should be installed properly. The long leg should be closer to the resistors. The short leg close to edge of the board.

Arduino Programmer Shield 069

6. Slide switch

If you plan to have two boards, one for burning the bootloader and another for uploading code you may want to dispense with the switch and use a piece of wire instead. For the bootloader solder the left and middle holes together. For the uploader solder the middle and the right holes together. If you decide to use the switch then simply solder it in place. Move it to the left for the bootloader and right for the uploader

Arduino Programmer Shield 070

7. ZIF socket

Now is time to solder the socket. Before placing the socket in the holes examine it carefully. Some of the pins may have bent during transportation. Make sure that all are straight and that all fit into the holes.

Arduino Programmer Shield 071

Take your time and do it right. It is not fun to find that one pin was bent after you started soldering the socket. Arduino Programmer Shield 072

Solder each and every one of the pins. Make sure that there are no short circuits

Arduino Programmer Shield 074

You are done with assembly. Make sure that you cut all the leads and that the board is clean and free of rosin. I use a soft tooth brush with a little dish soap to scrub both surfaces of the board, rinse with water and let it dry on top of a paper towel.

Once the shield is completed and dry it should look like this, mounted on top of the Arduino Uno and with an ATmega328 ready to be programmed

Arduino Programmer Shield 075

Burning the bootloader

I am using the Arduino IDE 1.6.4 and I have not tested this hardware with previous versions. The documentation states that you should use at least Arduino IDE 1.5.

Make sure that the reset switch points to the bootloader position. Load the Arduino ISP sketch from your Examples folder.  This are the first lines of the version I am using

// ArduinoISP version 04m3
// Copyright (c) 2008-2011 Randall Bohn
// If you require a license, see
// This sketch turns the Arduino into a AVRISP
// using the following arduino pins:
// pin name:    not-mega: mega(1280 and 2560)
// slave reset: 10:          53
// MOSI:        11:          51
// MISO:        12:          50
// SCK:         13:          52
// Put an LED (with resistor) on the following pins:
// 9: Heartbeat - shows the programmer is running
// 8: Error - Lights up if something goes wrong (use red if that makes sense)
// 7: Programming - In communication with the slave

In the Tools menu select the board: “Arduino/Genuino Uno”, set the proper serial port and set AVR ISP as programmer. Load the sketch into your Arduino before you put the shield on. Once the sketch has been loaded you can put the shield. The yellow led should start blinking slowly.

Now change the board to “Arduino Duomilanove or Diecimilla”. Set the Processor to ATmega328 and change the Programmer to “Arduino as ISP”.

Put a new ATmega328 chip in the ZIF socket and do Tools->Burn Bootloader. After a moment the green led should blink fast for a few seconds and the in your screen you can see the message:

Done burning bootloader

And that is it. You have changed a factory clean ATmega328 into and Arduino processor.

Uploading code

To upload code you need to remove the ATmega328 chip from your Arduino
April 25 024

April 25 025

Now you can use your bootloaded chip to upload any code in the ATmega328 chip. Keep the settings you had for burning the bootloader, that is select the Duomilanove board with the ATmega328 processor and the Arduino as ISP programmer. Upload your sketches in the usual way. When uploaded you can remove the chip from the ZIF socket and use it in your project.

Have fun using the Bootloader/Programmer Shield.