Can I use a Leonardo for serial programming an AMEGA328p(that has bootloader)

I'm revisiting an old project that uses 328's with a bootloader that I ordinarily program using a FTDI USB-Serial adapter.

Unfortunately I've lost my FTDI USB-Serial adapter and was wondering if I can temporarily use one of my leonardo's as a replacement until I get another adapter?

Obviously it's possible but the main thing is enabling it in a way that is easy to revert afterwards.

So what precisely do I need to do? Google only shows me how to program it not how to program it as a programmer.

I suppose I could try and load the firmware for the atmega16u onto it but i'm worried that won't work due to the chips being different plus there are 3 different versions of firmware ( dfu, serial and combined)

If I do that then I need to know that I can get it back to being a leonardo and I cannot see any info related to doing that.

In the meantime I'm programming using ICSP but need the convenience of not having to disassemble my project to swap out the micro.

Some guidance would be much appreciated.

You should be able to use a Leonardo as a replacement for your FTDI by uploading the File > Examples > 04.Communication > SerialPassthrough to the Leonardo and then connecting pin 0 of the Leonardo to Arduino pin 1 of the ATmega328, pin 1 of the Leonardo to pin 0 of the ATmega328, 5V to 5V and ground to ground.

You will need to manually reset the ATmega328 during the upload as soon as you see something like this in the black console window at the bottom of the Arduino IDE window:

Sketch uses 444 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.

Thanks. I'll give that a go.

I'll need to mock up a external reset button but the serial part was the tricky bit so thanks for the suggestion.

I forgot one thing. You need to change this line:

  Serial1.begin(9600);

to the baud rate of the bootloader on your ATmega328. If you don't know it, you can see it when you upload if you turn on File > Preferences > Show verbose output during upload and then do an upload:

avrdude: Version 6.3-20171130
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\per\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino15/etc/avrdude.conf"

         Using Port                    : COM68
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200

You can see the baud rate in this case is 115200.

Thanks for the consideration.

I'm set up for 115200 for the FTDI and also my Sparkfun Red Boards so I agree it's something i'll need to take into account.