Disguising board as Arduino IDE compatible board

Hello,

I wish to use the Arduino IDE to program an Atmel chip that is not listed in the usual boards on the Arduino IDE. Is there anyway that I can disguise it as a different board (such as an Arduino Uno) and be able to program it through USB and ATmega16U2 to UART?

Let me know. I am using the ATmega128 as my MCU.

Thanks in advance.

No, that's not the way to do it. You just need to install MegaCore to add legitimate support for the ATmega128: https://github.com/MCUdude/MegaCore Installation instructions are in the readme at the link above. If you have any problems, let us know here and we'll help you out.

Understandable.

I got the MegaCore library downloaded and now can chose the ATmega128. However, the USB to serial adapter I am using (ATmega16U2) does not let the code flow through it to the ATmega128, do I have to upload specific firmware to the ATmega16U2? Please let me know if that is the right way to go about it and/or if I should be using a different USB to serial converter.

Thanks.

You need to burn a bootloader into the m128 using some sort of ISP or JTAG programmer before you can upload via serial.

In theory, it should not matter which USB/Serial converter chip is used - FTDI, CH340, CP2101, whatever. Note that an ATmega16u2 is NOT a USB/Serial converter until you load the correct firmware into it (again, using an ISP programmer.)

Thanks for the response.

I have burnt the bootloader on the ATmega128 and I can successfully program the ATmega128 via an external Arduino as ISP. I have also been attempting to burn the correct bootloader/firmware on the ATmega16U2 via hex code that is provided with the Arduino IDE download. However, I can only upload hex code that will then associate the ATmega16U2 with either an Arduino Uno or an Arduino Mega.

You are suggesting that I must upload the correct bootloader/firmware to associate the ATmega16U2 with an ATmeg128? IF so, do you know how to find/edit the code to burn the ATmega16U2 to correspond to the ATmega128?

Could I also just upload firmware to the ATmega16U2 to essentially program it as a USB/Serial converter?

Thanks.

will then associate the ATmega16U2 with either an Arduino Uno or an Arduino Mega.

AFAIK, The "association" of the USB info in the "Port" menu with a board type is strictly a cosmetic feature designed to assist the user. There shouldn't be anything to prevent a port that identifies as "Uno" with some other board type in the "board" menu (in fact, there have been instructions posted on how to use the 16u2 on an Uno to upload to other (non-ATmega328p) stand-alone-chips in a breadboard, over the years.) So it sounds like what you have so far should "just work" - your 16u2 is already "disguised" as an Uno, but you should be able to upload using the megacore m128 board type... See also https://hackaday.io/project/62511-revive-wiring (though that doesn't use a 16u2.)

That makes sense to me, thanks for the response.

I have uploaded the firmware to the Atmega16U2 to be read in as an Arduino Uno when plugging into the computer. Then, within the Arduino IDE I attempt to upload a sketch to that port while using the ATmega128 board. That didn't work and just mentioned that there was an error uploading the sketch, no other details. I also attempted to upload the same sketch to the same port, but this time with the board as an Arduino Uno, same error.

Does this mean that I need to look into how the Arduino IDE perceives the board/COM port? Or is it still on the firmware side concerning the program loaded onto the ATmega16U2?

Thanks for all the recent advice, I really appreciate it!

overholt: I can successfully program the ATmega128 via an external Arduino as ISP.

When you did this you erased the bootloader. After doing an "Upload Using Programmer", you will no longer be able to upload via the ATmeg16U2 USB to serial adapter until you have done a Tools > Burn Bootloader.

overholt: I also attempted to upload the same sketch to the same port, but this time with the board as an Arduino Uno, same error.

You're just wasting your time trying to upload to an ATmega128 with Tools > Board > Arduino Uno selected. It will never work. Forget about the fact that the port is labeled as "Arduino Uno". It is completely irrelevant, as westfw already explained.

overholt: Does this mean that I need to look into how the Arduino IDE perceives the board/COM port? Or is it still on the firmware side concerning the program loaded onto the ATmega16U2?

No. Everything is fine between the IDE and the computer and the ATmega16U2. The problem is either with the bootloader on the ATmega128 (or lack thereof), or the wiring between the ATmega16U2 and the ATmega128.

Thanks for the response.

So just to clear up the whole process:

1). Upload firmware so that ATmega16U2 can be detectable as an Arduino board (I'm using the Uno in this case) 2). Make sure the bootloader is burned on the ATmega128 and do not upload any code onto it using an external Arduino Uno and using the sketch Arduino as ISP. 3). Chose the port on the Arduino IDE and select whichever one is associated with how the ATmega16U2 is disguised as. Fix the other parameters to the ATmega128 board, my set up (concerning clock, BOD, etc), except hit Bootloader: Yes (UART0). 4). Click upload and the sketch should upload through the Arduino Uno port (the port the ATmega16U2 is connected to) and to the ATmega128.

I attempted this process and the Arduino IDE continued to get hung up on when trying to upload to the board. What am I doing wrong?

For reference, I have connected the ATmega16U2 to the ATmega128 exactly alike how the Uno and Mega boards are hooked up. I know the ATmega128 is somewhat different due to the fact that uploading anything (or burning the bootloader, in this case) requires the TXD0/RXD0 pins instead of the MISO/MOSI pins like the Uno and Mega, and those pins are the ones directly connected to the ATmega16U2. Could this be the reason why I cannot upload to the ATmega128 by any chance?

Thanks so much for all the recent assistance, it has been really informational and useful.