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?
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?
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
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.
Yes.
That is, it is possible to program it without the Arduino bootloader, but not through the serial port. Without the bootloader you must use ISP to upload code and data into the flash and EEPROM; once the bootloader is in place it is possible to use the serial connection instead.
Note that fuses and lock bits cannot be programmed through the serial port but only through ISP, so you'll probably want to invest in a ISP programmer regardless.