Introduction: Arduino UNO As AtMega328P Programmer

After receiving my first Arduino UNO, I soon realised that it will be impractical to use an UNO for every project. As with the Microchip family of MCUs, I wanted an easy way to program stand-alone circuits and chips.

Searching the internet, it was clear that the Arduino IDE can cater for all my needs, and that no additional hardware will be required. The Arduino UNO can be programmed as an In Circuit Programmer with the supplied example sketch ArduinoISP and the UNO. There is thus no need for a separate programmer, or using AvrDude software for programming. A lot of examples on this was found on the internet.

After some testing, it was clear that programming the AtMega328P was not as easy as I thought. Programming all depended on the AtMega328P chip. Does it already contained the bootloader, or is the chip blank? Costs of a chip with bootloader is double that of a clean chip, so my first batch of chips was blank.

What is the difference, you may ask. Well, it is all about the AtMega328P oscillator selection.

Lets look at the differences

AtMega328P with bootloader

Cost of this chip is about double that of a blank chip
The config registers of the chip is set to use an external crystal as clock (16MHz)
Without an external oscillator, one can not program the chip using the Arduino as programmer
Once fitted with an external oscillator, the chip can be programmed using the Arduino as programmer

AtMega328P without bootloader

Cost is half of a chip with bootloader
The config register of the chip is set to use the internal 1MHz clock
Chip can be programmed using the Arduino as programmer, BUT the program will run 16 times slower than the code should, as the Arduino IDE compiles the code to run at 16MHz, and not 1MHz
Chip can be configured for 16MHz by uploading the Arduino bootloader.

Step 1: Designing a Programmer Shield

Designing the programmer shield, I looked at the requirements to program chips with and without bootloaders. First, I looked at the oscillator selection.

Oscillator

AtMega328P with bootloader

The chip needs an external oscillator to be programmed, so this must be present on the shield.

AtMega328P without bootloader

If the chip was configured to use the internal oscillator, no additional components are needed. However, if the chip was previously configured to use an external oscillator, an oscillator will be required. With an external oscillator, both types can be programmed.

It is clear that adding an external oscillator to the shield, will accommodate all types of chips. A 16MHz crystal and 2 x 15pf capacitors, or a 16MHz resonator can be used.

LED indications

The source code or sketch indicated 3 outputs that can be connected to LEDs. This indications should be present on the shield.

Resetting the programmer

With a shield placed on top of an Arduino UNO, the UNO reset button is normally out of reach. The shield should include a separate reset button.

Powering the chip to be programmed

The chip that needs to be programmed, must have power connected to it. For the supply, the +5V and 0V is taken from the Arduino UNO board. However, inserting and removing a chip from the programmer with supply on, might cause damage to the chip. For this reason, a switch was added to the shield.

I/O Port protection

The ArduinoISP shield sets certain pins as OUTPUT on the Arduino UNO. If one now connect a previously used AtMega328P to the programmer, there can be conflict between the two chip's I/O lines that can cause damage to the ports. For protection, I added 470R resistors between the programmer, and the chip to be programmed.

Reset line of chip to be programmed

To ensure a stable reset circuit for the chip to be programmed, I added a 10K pull-up resistor to the RESET line.

Programming Method

ZIF Socket

This will be an easy way to program stand-alone chips, or to burn the bootloader on new chips. I thus added the ZIF socket to the design.

Programming cable

As almost all my designs are stand-alone circuits, my programming and development is done on breadboard. Thereafter, program updates are done via programming headers on the final circuit board. For this reason, I added the programming cable to the design.

Step 2: Building the Shield

I designed a PC Board with the free version of Eagle, and the shield fits directly onto the Arduino UNO. After designing the layout of the board, I noticed that the space taken up by the ZIF socket as well as the standard programming cable leave me with two options:

- use normal 1/4W resistors, which will leave no space for labels, or
- use SMD resistors which is more work, but will leave space for the labels.

My final PCB design uses SMD resistors, soldered to the solder side of the board. I used a 16MHz resonator as oscillator, but this can easily be changed with a crystal and 2 capacitors.

The power switch is connected such as to switch off the +5V to the ZIF socket, as well as the programming headers. This give more options when doing development on stand-alone circuits. Due to the limited space for the shield, the power switch was placed where the A0 - A5 pins are located on the Arduino. As these pins are not used for programming, they were omitted.

Building the circuit is quick using the PC Board. The standard header pins used to connect the shield to the Arduino, was modified. Using needle nose pliers, the header pins were pressed flush with the black plastic, and inserted from the component side.

Finally, I added labels to the LEDs and programming header.

Step 3: Setting Up the Arduino IDE to Use the Programmer

After building the programming shield, connect it to an Arduino UNO, and connect the Arduino USB cable to the PC.

- Open Arduino IDE.
- Select File - Examples - ArduinoISP
- Upload the sketch to the Arduino.
- The programmer shield LEDs should flash rapidly, where after the OK LED will fade on/off.
- Select Tools - Board - Arduino UNO
- Select Tools - Programmer - Arduino as ISP

The shield is now ready to be used to program any AtMega328P.

Step 4: Using the Programmer Shield

To burn the bootloader to the chip:

- Insert the chip into the ZIF socket.
- Goto Tools - Burn Bootloader
- Programmer LEDs will indicate programming status
- On completion, the OK LED will again fade on/off

To burn a sketch to the chip

- Insert the chip into the ZIF socket.
- Goto File - Upload Using Programmer
- Programmer LEDs will indicate programming status
- On completion, the OK LED will again fade on/off

The same method can be used to program an AtMege328P in a stand-alone circuit (breadboard or PC board) using the programming cable. For stand-alone circuits, it is normally required that they are powered up via their own supply. If no supply is available, and the circuit does not require a lot of power, the circuit can be power from the programming shield by switching on the +5V

NOTE:
Always ensure that you switch off the power switch (+5V LED off) before inserting or removing a chip into the ZIF socket, or before connecting/disconnecting the programming cables to the stand-alone circuit.