Introduction: Arduino UNO As AtMega328P Programmer

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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.

Comments

sggm (author)2017-08-13

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.

Eric Brouwer (author)sggm2017-08-14

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

sggm (author)Eric Brouwer2017-08-14

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

Eric Brouwer (author)sggm2017-08-15

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

PatrickT103 (author)2017-07-13

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.

Eric Brouwer (author)PatrickT1032017-07-13

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

SanjayG29 (author)2017-03-19

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

Eric Brouwer (author)SanjayG292017-03-20

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

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

SanjayG29 (author)Eric Brouwer2017-03-21

Thanks Eric

Rabbit12345 (author)2017-03-16

Hi Eric,

Great job! Can you send the type (+ link?) of the resonator you've used?

Thanks, Rabbit

Eric Brouwer (author)Rabbit123452017-03-17

The resonator used is a standard 16MHz, 3pin resonator. It is basically a 16MHz crystal with the capacitors build into the resonator.

I have uploaded a new version of the PCB file, which now makes provision for the resonator, or a standard 16MHz crystal and 2 capacitors.

This makes it easiers and cheaper to build the circuit.

Hope this will assist you.

Regards

cheeju (author)2017-03-11

Can I use ATMEGA328-PU instead of ATMEGA328P-PU on your programmer shield? I m using Arduino 1.8.1 on my MacbookPro, do i have to downgrade version of arduino? While burn bootloader on ATMEGA328-PU it shows some error massage like this rdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00

avrdude: stk500_recv(): programmer is not responding.

Pls give me right solution on my mail sanjushr2006@yahoo.com

Eric Brouwer (author)cheeju2017-03-14

The ATMEGA328 has a different signature compared to the ATMEGA328p.

You will have to add the ATMEGA328 to your list of boards in the Arduino IDE..

Follow this link for more info.

http://www.digitalmisery.com/2011/11/arduino-bootloader-with-atmega328-and-atmega328p/

cheeju (author)Eric Brouwer2017-03-14

Thank you Eric for your information about the link.

AdamGadut (author)2017-01-19

i believe the Resistors in connection to pins 13 - 10 on arduino are simply for protection and are not entirely necessary. I have built a programmer Shield for ATtiny's and they have worked fine without those resistors...
could this be the same for the ATmega328?...

Eric Brouwer (author)AdamGadut2017-01-20

Here is an explanation as to why I added the four protection resistors:

Arduino has not yet been programmed with the ArduinoISP softwaer.

There can thus be any program on the Arduino when the programming shield is connected. Lets say pin 13 is an output, and set high in the Arduino code (+5V on the output).

Now, the programming shield is used to program a stand-alone chip, or project, on which pin 13 is also an output. However, this output is set LOW (0V on the output).

There is now a short circuit created between the Arduino pin 13 and the IC to be programmed pin 13.

I added the 470R resistors to limit the current in such cases to prevent damage to either pins.

AdamGadut (author)Eric Brouwer2017-01-20

Thanks Eric... a question about the part that has the crystal on the schematic.... if i want to program it without the crystal, would it work ok just that part cut off?... or how would the schematic look like?..

Eric Brouwer (author)AdamGadut2017-01-20

Oscillator

AtMega328P with bootloader

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

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.

AdamGadut (author)AdamGadut2017-01-19

a little late for me to notice the section where you wrote up "Protection for the IO's"...

IMO, for that purpose, diodes may actually be better since they only let the current flow one way, but i wouldn't know which way to point it to

Eric Brouwer (author)AdamGadut2017-01-20

Hi

No, a diode will not be sufficient for protection,

See my explanation above.

JakeP64 (author)2017-01-03

Do I have to remove the ATmega IC in the Arduino UNO before attaching the shield made?

Eric Brouwer (author)JakeP642017-01-04

Hi, and sorry for my late reply.

No, you must NOT remove the ATMEGA chip from your UNO board. Your UNO board becomes the programmer for the new ATMEGA chip placed in the ZIF socket.

bayuhnr (author)2016-12-20

Can you convert to pcb express file, tanks

Eric Brouwer (author)bayuhnr2016-12-23

Sorry, but I only use Cadsoft Eagle.

You can download the free version of Eagle here:

https://cadsoft.io/

marsekal (author)2016-11-25

Good

Eric Brouwer (author)marsekal2016-11-26

Thank you.

Electromakers (author)2016-07-08

Cant I just insert the atmega328 in uno and upload the sketch and then remove the atmega and put it on the breadboard connecting clock n power supply?

Unfortunately not...
When you buy a new ATMEGA328p, it does not have the bootloader programmed. The blank ATMEGA328p is also configured to run at 1MHz with it's internal oscillator, and not a 16MHz external crystal.
One can buy pre-programmed chips with the Arduino bootloader, but they are normally double the price of a blank chip.

marsekal (author)2016-07-08

Coding mr link

PyrusBoy (author)2016-06-17

The one thing nearly every one forgets is to let the reader aware of the IDE version they used. It took me a while to find the right IDE for it to compile correctly. Also when it come to libraries it again would be useful to have the exact library used, often there are different versions around, zip the wrong one and trouble starts.

Eric Brouwer (author)PyrusBoy2016-06-17

I have been using this programming shield from Arduino IDE version 1.0.5-r2 up to version 1.6.7 without any problems.
However, I have some programming/verify problems using version 1.6.8 & 1.6.9, and can no longer burn the bootloaders. Thus I am back using version 1.6.7.
Regarding the libraries, I always save the library used on each project, with all the project files. This also include PCB and SCH files and other documentation.

owendelong (author)2016-06-11

Could you post the SCH file to go with the BRD files?

Eric Brouwer (author)owendelong2016-06-12

Sorry, but I only have the circuit diagram under step 1. I did not design the PCB using the Eagle SCH file.

owendelong (author)Eric Brouwer2016-06-12

That's OK... I think I managed to create one. I've attached my SCH and BRD which you are welcome to use if you find them useful.

My layout is admittedly significantly different from yours. Probably not any better. Since I use OSH Park for my boards, double-sided is the same as single-sided cost wise, so I went with using the back side of the board as a ground plane. I could shorten some of the routing a bit by putting traces on both sides, but I wanted to try my hand at getting it all on one side.

I also wanted to put the 5V switch and LED near each other with the switch close to the chip release lever for the ZIF and the error LED close to the reset button. I wanted the reset button also conveniently close to the edge of the board.

I hope you find these useful or at least amusing.

owendelong (author)owendelong2016-06-13

For others that are wondering about the Schematic. The top component is an Arduino Duemilanove Shield map component from a library downloaded from SparkFun Electronics called "SparkFun-Boards". The component is listed as "ARDUINO_SHIELDNOHOLES". The pinout for the DUEMILANOVE should be compatible with the UNO and most other Arduinos as well.


The 28-Pin ZIF Socket is also from SparkFUn (SparkFun-Connectors library).

The Resistors and Capacitors come from SparkFun-Passives library.

The reset switch is TACTILE-PTH from SparkFun-Electromechanical library.

The 5V switch is SWITCH-SPDTPTH from SparkFun-Electromechanical library.

The LED (standard 5MM LED package) components came from a library I downloaded from Adafruit. The Crystal (CRYSTALHC49S) also came from the Adafruit library.

I used named lines to keep the drawing somewhat clean. The names are annotated at each apparently open line end. All lines with the same name are electrically connected. Thus, even though RESET in the lower section does not show a green line to RESET on the shield, because they share the name "RESET" they are, in fact, connected.

Since some pins on the Arduino have multiple functions and/or special abilities (such as PWM), those names are annotated accordingly. Thus D10 which is used for D10 or SS and which has the ability to be Pulse Width Modulated (PWM) is labeled D10/PWM/SS to indicate these two uses and the special ability applied to D10.

While the author did not connect pin 7 to pin 20 (Vcc to AVcc), I went ahead and added this connection based on the recommendation from the ATMEGA data sheet which says "AVcc is the supply voltage for the A/D converter... It should be externally connected to Vcc even if the ADC is not used. If the ADC is used, it should be connected to Vcc through a low-pass filter."

NOTE: There is no low pass filter in this circuit as the ADC is not used during programming.

owendelong (author)owendelong2016-06-13

I just noticed... My version does not accommodate a programming cable or pass along the serial lines (RX/TX). This isn't a problem in my case as I only need to program stand-alone chips, but it could be easily added. I might add them and publish updated files at a later date.

JanT14 made it! (author)2016-05-29

Super helpful instructable!

I have no degree in electronics nor computing and still made this work thanks to your clear explanation, Eric. As I have no experience in etching, I chose an Arduino Protoshield to build it. With a little spaghetti, I admit, but whatever, IT WORKS :)

See picture: the blue LED close to pin 3 is fading gently on the rhythm of the Fade sketch (modified: output pin 3 in Arduino IDE, pin 5 of the AtMega328)

Happy :-)))

Jan

Eric Brouwer (author)JanT142016-05-31

I am glad you were able to use the Instructable. Happy programming

ashrafsarameh (author)2016-04-07

Hey,

This is very helpful, thank you for the detailed explanation. I do have a question however. I burnt bootloader into my new Atmega328P using my Arduino Uno as the Programmer, which also is used to upload sketch to my new MCU. However, I am unable to upload sketch to the MCU except using the Arduino as the Programmer. Any thoughts? I know my connection is good because I am able to upload sketch to my other MCU using computer.

msigales (author)2016-02-11

how I can burn a .h, made in atmel studio, to my atmega328 with the arduino?
with this I can?

Eric Brouwer (author)msigales2016-02-13

I am still using Win XP, so I am unable to test this using Atmel Studio. However, I am sure that when you build/compile your project, Atmel Studio will also create a .hex file.

With a hex file, you can upload the file using AVRDUDE:

avrdude -c arduino -p m328p -P com1 -b 19200 -U flash:w:./FILENAME.hex:a

avrdude -c arduino -p m328p -P com1 -b 19200 -U lfuse:w:0xff:m

avrdude -c arduino -p m328p -P com1 -b 19200 -U hfuse:w:0xfd:m

Just replace FILENAME.hex with your .hex file name.

msigales (author)Eric Brouwer2016-02-13

thanx
I've been researching and found information similar to yours.
I use the Arduino as ISP recorder,
with your commands and avrdude I burn the .hex.

I just had not found anything about fuses modifications.
where they interfere?
sorry my english, I speak Portuguese, then it might be difficult for you to read my question.
you are helping me a lot.
att.

marc.deloor.5 made it! (author)2016-01-30

With some shaking hands, I copied your work on a proto-shield. Thanks for that great instructable!

Great job. Glad you liked the Instructable.

doart (author)2015-11-26

Hi Eric Could you please post the eagle Schematic I would like to make changes to put in the crystal and caps. This would be greatly appreciated and save me having to redraw the schematic in eagle.

Eric Brouwer (author)doart2015-11-30

The Eagle file is available under Step 2.

doart (author)Eric Brouwer2015-12-21

Hi Eric Many thanks for this much appreciated

Eric Brouwer (author)2015-06-25

Hi Draige
Hope this image will answer your question. This is my PCB standard layout when I create a new ATMega project. I use the same pin-outs on all my projects.

Draige (author)Eric Brouwer2015-06-28

Hi Eric,

Thanks for the fast reply.

Indeed that awnsers my question.

About This Instructable

56,723views

179favorites

More by Eric Brouwer:ESP8266-01 IoT Smart Timer for Home AutomationInstructables Hit Counter (ESP8266-01)Converting Camping Deep Freezer Into Fridge/Freezer Using AtTiny85
Add instructable to: