My sketch ( Gammon Forum : Electronics : Microprocessors : Atmega bootloader programmer ) gets mentioned frequently on this forum, so to save people having to remember the "magic number" 11635, I have installed a redirect for that page:
If you haven't seen that page, it describes a sketch that can run on a Uno (or similar), Mega2560, or Leonardo (or similar) which can be used to program a bootloader onto another Atmega chip, from the following list:
- Atmega8 (1024 bytes)
- Atmega168 Optiboot (512 bytes)
- Atmega328 Optiboot (for Uno etc. at 16 MHz) (512 bytes)
- Atmega328 (8 MHz) for Lilypad etc. (2048 bytes)
- Atmega32U4 for Leonardo (4096 bytes)
- Atmega1280 Optiboot (1024 bytes)
- Atmega1284 Optiboot (1024 bytes)
- Atmega2560 with fixes for watchdog timer problem (8192 bytes)
- Atmega16U2 - the bootloader on the USB interface chip of the Uno
The only hardware required is the programming board (mentioned above), some connecting cable (6 wires) and a PC/Mac/Linux box to run the terminal monitor on, to control the programming process.
Programming is fast, it takes one second to program the Uno bootloader, three seconds to program the Mega2560.
A clock source is provided in case the chip being programmed does not have a functioning crystal.
Also see Gammon Forum : Electronics : Microprocessors : Atmega chip stand-alone programmer to upload .hex files which lets you upload an arbitrary hex file (from an Arduino compile) onto various chips. This can be either a bootloader or "end-user" code.