Flashing 8u2 using a raspberry pi ?

Hello everyone..
First of all, I hope all of you are well during this trying time.

Since we're also on lockdown (and stuck at home ;)) , I've started on a arduino based HID steering wheel project.
I have one of the older arduino UNO boards (about 5 years old). I was planning to use the UNOJoy library to emulate a USB HID device by reflashing the firmware on the ATMEGA 8u2 USB to Serial chip.
However, my arduino refuses to go into DFU mode (I've tried every tip on the internet.. it just will not go into DFU mode).

After trying unsuccessfully to get it into DFU mode, I decided that I'd try to reflash the 8u2 over it's ICSP connection. Now, ideally I think this should be done with an ICSP programmer, but unfortunately, I don't have an ICSP programmer and I don't have a second arduino board either (which can be used as ICSP programmer)... and because of the current situation, I probably won't be able to order one anytime soon.

However, I do have an old raspberry pi and apparently they can be used as ISP programmers, once AVRDUDE is installed. I'd like to try to use my Raspberry pi to reflash the 8u2 firmware over ISP.

My questions is is this theoretically possible?

[For fellow newbies who may stumble on this thread later on, DFU mode is digital firmware update mode .. the arduino has to be put into DFU mode in order to reflash the firmware on the USB to serial chip. Newer arduinos use the 16u2 chip. My older arduino has the 8u2 chip for USB-serial comunication]

Yes, it's possible. There are a couple options:

linuxgpio, as documented here:

linuxspi, as documented here:
https://learn.sparkfun.com/tutorials/raspberry-pi-stand-alone-programmer

I've documented my experiences using the linuxspi approach here:

I eventually managed to get the AVRDUDE problem that blocked my progress on that project fixed, and Arduino has since released a version of AVRDUDE that has that fix (I don't believe they have yet merged the linuxspi functionality into the official AVRDUDE). Unfortunately, Arduino recently removed the ability to create 3rd party programmer packages, so my plans to make this easily available to all Arduino users via the IDE by installing a 3rd party platform I write have been killed. It would need to be added into each platform's programmers.txt file. So the next step would be to try to get Arduino to accept that programmer addition, as well as some of the more popular 3rd party platforms.

Thankyou. Actually, I had a look at that first link. But it shows the pi being used to program the main processor on the Uni, not the 8u2. So my concern is whether it will work for the 8u2 as well.
Specially , I read that are pi uses 3.3 volts on its pins and that higher voltages could burn it out. I read the data sheets of the 8u2 to try and find the voltages it needs for programming but I couldn't understand most of the information. :confused:

mahela007:
it shows the pi being used to program the main processor on the Uni, not the 8u2.

It will work fine. You're using the Pi as a general purpose AVR ISP programmer. You can program any AVR microcontroller with it. You only need to specify the right chip name in the avrdude command. Actually, most modern Unos use the ATmega16U2, not the ATmega8U2. I think the older boards used the ATmega8U2, because I have see that written in the tutorials. You can program either with the Pi.

mahela007:
Specially , I read that are pi uses 3.3 volts on its pins and that higher voltages could burn it out.

Correct. If you power the ATmega16U2 at 3.3 V, then there is no chance that it will expose the Pi to 5 V. You should not have the Uno powered via the USB cable or barrel jack while you are programming it. Power it with 3.3 V supplied by the Pi.

mahela007:
I read the data sheets of the 8u2 to try and find the voltages it needs for programming but I couldn't understand most of the information. :confused:

Probably, the ATmega16U2 will be out of spec powered at 3.3 V during the programming process, but I'm sure it will work. At worst, you might get the occasional failed programming and just need to run the command again.

The alternative is to use a level shifter between the Pi and the ATmega16U2.

Thank you. I will try and post back.
As you can see in from this photo:

Google Photos

my UNO as an "Ätmel Mega8u2" so it's definitely one of the older boards.

Hi again..
So I noticed something odd..
I hooked up the boards and stared to run avrdude.
However, it stopped and said the signature of the chip was unexpected.
Apparently, the signature of the onboard chip is 0x1e9849

Which is the signature of the 16U2!! But my photo clearly shows that my board has the 8u2 ..
Should I just override the warning and proceed?

mahela007:
Apparently, the signature of the onboard chip is 0x1e9849

Which is the signature of the 16U2!!

The signature of the ATmega16U2 is 0x9489, not 0x9849.

Do you get a consistent signature every time you run the avrdude command?

Sorry.. I think this was a typo on my part The signature it showed was 0x9489.
I changed the part number parameter in the AVRDUDE command to "m16u2" (the part number for the atmega16u ) and ...

IT WORKED! :slight_smile:

So I flashed UNOJOY and i'm currently testing out my arduino as a joystick.

Thank you so much for your help :smiley: I'll update the post with a guide for newbs. (although, I suspect it won't be very useful because this is an old board. )

Still can't imagine why this 8u2 has a 16u2's signature though.

EDIT: Note
AVRDUDE 6.3 has a bug which makes a "GPIO pin already exported" error. I had to use AVRDUDE 6.1

You're welcome. I'm glad to hear it worked!