Arduino Mega to Repair Trinket Bootloader

While working on one of my projects, which used a Trinket, I managed do damage the bootloader. In fact I did this to two of my three 5V Trinkets. Luckily for me, Adafruit has a great writeup on repairing the bootloader using an Arduino Uno, all you need to do is upload the program to the board and connect a few wires. The only problem is I don’t have an Uno, I have Mega. Its is even written on the Adafruit learning system that, “This loader isn’t tested to work with any other kind of Arduino.” Still I knew there had to be a way.

This issue is the same as using a mega to burn a bootloader on any arduino chip, you have to use the right pins. On an Uno, MOSI is pin 11, MISO is pin 12 and SCK is pin 13. These pins are different on the Mega. I found that you only had to change a small amount of code to get the loader to work correctly.


/*
* Pins to target
*/
#define SCK 52//was 13
#define MISO 50//was 12
#define MOSI 51//was 11
#define RESET 53//was 10

Also, I found in the, “start_pmode ()” function a reference to pin 13, so that needs to be changed.


Change

pinMode(13, INPUT); // restore to default

to

pinMode(SCK, INPUT); // restore to default

Now when connecting the Trinket, wire it like this:

  • Trinket VBAT+ pin to Arduino 5V
  • Trinket GND pin to Arduino GND
  • Trinket RST to Arduino #53
  • Trinket #0 pin to Arduino #51
  • Trinket #1 pin to Arduino #50
  • Trinket #2 pin to Arduino #52

After that, you are good to go. Power the Mega up and either open a Serial console window (if connected to the computer) or press the reset button on the Trinket. The LED on the Trinket will flash a few times and it will be done.

Download:

If you would like to download the TrinketLoader, and change the code to work with a Mega, head over to there article HERE.

If all you want to do is upload and go, here is the code already prepared with the changes.

Download “Trinketloader_mega.zip”

trinketloader_mega.zip – Downloaded 1598 times – 10.28 KB

Disclaimer:

I have found this method to work fine for me, and have fixed my Trinkets many times with my Mega, thought it should still be said, your mileage may vary.

Have fun with your newly fixed Trinket!

Arduino, Arduino C, Hardware, Programing , , , , , ,

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.