Does uploading through ICSP overwrite the bootloader?

I have not done this yet but am working on a prototype built around an ATmega328P-PU. I have ten of this chip and they are all pre-programmed with a bootloader and the blink sketch. I can take any of these and put them in my Arduino UNO board and everything works as expected. Up until now this is how I have been loading sketches onto the chip that goes into my prototype.

It is my understanding that the ICSP header is used for programming if you don't have USB or your controller doesn't have it ETC and you can omit the bootloader if you plan to program your controller in this way.

What I'm wondering is if there is a way to leave the bootloader intact when programming through the ICSP or if that is overwritten? I'd like to keep it intact if I can, should I elect to move the 328P back to one of my genuine Arduino boards for easier programming.

Yes. If you "upload using programmer" you will have to burn a fresh bootloader before you can do a serial upload.

There is no provision to include a bootloader when you do Upload Using Programmer. To upload a sketch and bootloader at the same time you would have to edit the .hex file to merge in the bootloader and then use 'avrdude' to upload the combined .hex. I think it can be done but I have never done it nor seen it done.

Okay that makes sense, sounds like uploading a sketch and a bootloader is probably more hassle than it's worth. Though I suppose if I wanted to take the programmed chip with no bootloader and put it into, say, an Arduino UNO later, intending to use it there permanently, I would use the same sort of programmer to burn a bootloader back onto it right?

I'm starting to wonder if I could just incorporate an AVR into my project. What I'm currently working on is a prototype that uses the ATmega328P-PU and essentially functions just like my Arduino UNO. In-fact, when i want to put a new sketch on the chip, I've been pulling it out of the prototype and putting it into my UNO board.

I've found an instructable for building a USB AVR programmer using the Atmel ATtiny45. If I were to build that circuit on the same board as the rest of my prototype, could I just make the connections to the ATmega328 as you would to program it in this way and leave it as an ICSP or will the board not function normally with that circuit connected?

I followed the instructions here for building an Arduino on a breadboard, with the only exception being that I used a ceramic resonator instead of a crystal oscillator because they're.. better? :wink: The whole plan here is to make a "DIY arduino compatible kit" that somebody interested in the inner workings of the whole thing could pick up and put together themselves. This will be all through-hole components as they are easier to work with and identify.

For the instructions on creating the programmer, currently I'm looking at this guy's how-to DIY $5 USB AVR programmer
it would be great to have the USB progammer part of the integrated project. I've also got a 5v regulator and optional DC-DC step-up circuit onboard so the controller can be powered from a smaller battery if desired. Other than that, the only other thing I'm considering adding to the final product is maybe a dual H-bridge, but might save that for a "Robot builder's" version of the kit.

Lastly, I'm not trying to get rich off of these kits, any money outside the cost of the parts is planned to go to a non-profit that wants to build a makerspace.