Electronic – arduino – What’s the deal with a bootloader

arduinoatmegabootloader

I am planning to buy an ATmega328 chip from Atmel, place it in my Arduino board, program it, detach it later, then solder onto a PCB.

Can I just buy the chip and program it on the Arduino board, or does it need to have an Arduino bootloader?

Best Answer

No, you can't "... just buy the chip and program it on the Arduino board"

Unless you buy a pre-programmed ATmega328, you will need an In-Circuit Serial Programmer.

Atmel sell the AVRISP mkII. Just for guidance, you might pay over 30 GBP for one of those.

There are lower-cost option based on the Open Source USBtiny

It has been improved and turned into a kit by Ladyada

A friend bought one from a well-known marketplace web site, and it works fine. I just did a quick check and found it ready made for under £5 without the plastic case. YMMV

There is also a Ladyada DIY-shield project to turn the Arduino into a programmer

There are several projects which are even simpler, e.g. Mega-ISP using breadboard as the socket to hold the unprogrammed ATmega

I would recommend you either

  1. put a 2x3pin ISP header onto your new PCB, connect it to the chip correctly, so that it can be used to program the chip when its on-board; this implies RESET and SPI can be used without causing the embedded system to break or misbehave, or
  2. don't solder the chip into the board, but use a socket instead, so that you can extract it

Then it will be straightforward to reprogram the chip if you find a bug in the code, or need to make a change; both are very common. Otherwise it will be hard to fix it.

Summary
If you already have an Arduino and breadboard, then you have everything you need to program an ATmega. You don't need to buy an In-Circuit Serial Programmer (ISP), and you will not put the unprogrammed ATmega into the Arduino. However, if you are going to do this a lot, an ISP is a reasonable investment.