Arduino UNO As AtMega328P Programmer

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.

4 People Made This Project!

Recommendations

  • Tiny Home Contest

    Tiny Home Contest
  • Creative Misuse Contest

    Creative Misuse Contest
  • Fix It! Contest

    Fix It! Contest

59 Discussions

0
None
curlyten

Question 9 days ago

Could you put an 8 Mhz resonator instead of 16? Would it work? I have seen that you do not put anything on the Aref pin, should placed o a capacitor form Aref to vcc?

hi first thanks for sharing your project i made your eagle pcb but i don't know pins or anything please give me datasheet of pcb in eagle but not the simple one i mean the board

0
None
jgrn

5 months ago

Hi Eric

Thank you very much for sharing your proyect. I found very useful the idea of the board fitting on the (omnipresent) arduino uno, so I toke your board design, I built it and it worked like a charm.

Anyway, when I was working with the printed (I migrated the files to Altium's CM) it seemed to me that the labeling for the isp header was not completely correct. I think that the order should be SCK, MISO, MOSI, RST, 5V, 0V.

Since for ISP purposes I use to connect the programming cable directly to the arduino ICSP six-pin connector, I did not check it, but it was the impression I had following the leads.

1 reply

Hi

Thanks for pointing out the labeling. When I have timer, I will update this.

Regards

ERic

Using your board I were successful with programming boatloader on Atmega 328p, but I am not sure if is possible to program HEX file on it.

Thanks for sharing this interesting project. Very clear and instructive.

However I can find Arduino Mini,Micro,Nano at a lower cost than Atmega328p + resonator including shipping to Norway.

Quite strange but the lowest cost Atmega328p I have found was about £ 1.8 ?

I have built one for programming an Atmega644, working fine first time.

1 reply

Thanks for your feedback.
Yes, one must look at the cheapest option available. For me, it is not really that the Atmega328 chip is the cheapest, but it is locally available. Lately, it is of no use in South Africa to order from eBay, as the shipping takes anywhere from 1 to 8 months....

Thanks for this, I was able to build the circuit on breadboard and burn the bootloader onto a blank 328P. I'd followed another tutorial and had no luck. This worked first time. Awesome!

1 reply

Hi

Glad this Instructable was of help.

Regards

Eric

I just answered my own question about the communication TX and RX. I guess now it comes done to the Sofware version. 1.8 just is not working.

0
None
sggm

1 year ago

Hi Eric,

Thanks a lot for excellent information & replies. I have followed everything as per the instructible but I get following error-

avrdude: Yikes! Invalid device signature.

Double check connections and try again, or use -F to override

this check.

Error while burning bootloader.

Please suggest the solution. Thanks.

3 replies

Hi sggm

I have few questions:

- Did you select "Arduino/Genuino Uno" as your board?

- Did you select the correct "COM" port?

- Did you select "Arduino as ISP" as your programmer?

- Did you upload the "Arduino ISP" code to your Uno board?

If you were able to upload the "Arduino ISP" software to your board, the heartbeat LED will flash indicating that the programmer is ready.

- Are you trying to program an ATMega328p chip?

- Did you insert the chip correctly into the programming socket?

- Is the power switch of the programmer on?

This is indicated by the heartbeat and PWR led.

- Are you able to burn the bootloader?

If you can not get to this point, you will have to double check all your connections.

Regards

Hi Eric,

Thanks a lot. The answer to all above qustions is "Yes". I am able to program Uno with ISP & the heartbeat LED is flashing . The only difference is I have 328P-PU chip on PCB. Is this a fault?? I have attched pdfs for clarity . Thanks

From the photos, it seems as if you did not connect the RESET line between the Uno and PCB. Connect as follow:

Arduino to Standalone chip

Arduino 13 - to pin 19 of target chip

Arduino 12 - to pin 18 of target chip

Arduino 11 - to pin 17 on target chip

Arduino 10 - to pin 1 on target chip (RESET)

Hope this helps.

Regards

Eric

Thank you for sharing this excellent build! One question though, do you have to remove the chip/MCU in Arduino UNO in order to upload a sketch in the chip/MCU in programming shield? I noticed almost all other Instructables/tutorials requires to do that before uploading.

1 reply

Thanks, I am glad you like this project.

Do NOT remove the chip from the Arduino board. This chip must be programmed with the Arduino ISP sketch.

The blank or new chip can then be programmed using the programming shield.

Regards

Eric

Hi Eric

Thanks for an excellent instructable.

Can I load the sketches on on chips (having no bootloaders) directly? In that case, can the maximum memory be increased on the boards.txt files to the value mentioned in datasheet?

Sincerely

Sanjay

2 replies

Hi SanjayG29.

When uploading to a new chip, first burn the bootloader. This will load the bootloader and set the configuration fuses to the correct settings.

Once this is done, any program uploaded using the programmer, will first erase the chip (erase the bootloader, but keep config fuses), then download your own program. No extra memory is used for a bootloader.

I suggest you add an additional board to the board.txt file to get access to all available memory.

##############################################################

uno.name=ATmega328 on a breadboard (16 MHz external clock)

uno.upload.tool=avrdude

uno.upload.protocol=arduino

uno.upload.maximum_size=32768

uno.upload.maximum_data_size=2048

uno.upload.speed=115200

uno.bootloader.tool=avrdude

uno.bootloader.low_fuses=0xFF

uno.bootloader.high_fuses=0xDE

uno.bootloader.extended_fuses=0x05

uno.bootloader.unlock_bits=0x3F

uno.bootloader.lock_bits=0x0F

uno.bootloader.file=optiboot/optiboot_atmega328.hex

uno.build.mcu=atmega328p

uno.build.f_cpu=16000000L

uno.build.board=AVR_UNO

uno.build.core=arduino

uno.build.variant=standard

##############################################################