Difficulty getting Nick Gammon's 'uploader' code onto Arduino MEGA board

Hi there,
I'm a newbie when it comes to Arduino, SD Card coding, and using bootloaders in general so.. Bare with me!

What I'm trying to accomplish is this:

Store .hex files onto a FAT16 SD or MicroSD card. - These will be my arduino sketches (i.e. "BLINK.hex")

Create an LCD menu to View/scroll through the (likely many) .hex files that are on my SD card, VIA a 20x4 LCD Screen and rotary pot/pushbutton (If it can show text files/directories as well that would be amazing).

Load a .hex file from my SD card onto my Arduino Mega2560 (WHILE away from my Windows computer - just the SD card and Arduino MEGA, and an extra Arduino if necessary).

I've tried about half a dozen methods, and I've just been getting constant errors (mostly "error loading bootloader" errors). Most of the methods I've tried were written 5+ years ago, so they're all seemingly outdated.

I've recently come across some of the examples by Nick Gammon, but I haven't been able to adapt this yet.

So what I'm asking is this - Can anybody recommend a starting point for me so I can properly begin this endeavor?

I've successfully created a .hex file (;

I'm using this hardware (listed only the ones that are relevant to this project):
Arduino MEGA2560
DS1307 Data Logging Shield (with slot for Large SD Card)
Rotary/Pushbutton potentiometer
20x4 I2C LCD Screen

I've also got a couple of spare Arduino Uno's, if I need an extra

Thanks for any help!

  • Zach

Break your project into smaller, more managable chunks. First you create a sketch, where you implement reading a file from sd card. Second, you take a look at how to write to the arduino's flash memory. Then you can take a go at a lcd menu. If everything works, you just have to merge it together into one sketch.

Not sure if you are wanting to program through the serial connection, or the ICSP connector. If the ICSP connector is acceptable, have a look at this project on Adafruit's website, it uses a modified version of the Arduino as ISP sketch, but stores the bootloader hex file on the arduino being used as the programmer. It probably could be modified to read the file off an SD card.

LightuC:
First you create a sketch, where you implement reading a file from sd card

How might I do that?

This site looked promising:
http://legacy.gamebuino.com/forum/viewtopic.php?f=12&t=3640

Though unlike that person I wasn't able to 'burn the bootloader' as per this link:

If it is possible to burn ^THAT bootloader to an Arduino MEGA, I'd like to start here.

That second link mentions altering the boards.txt file, which I was unable to do successfully. Perhaps that's where the root of my problems have been?

I have a standalone Programmer that moves user selected .hex file from SD card into flash. It runs Nick Gammon's code.
Is that what you are attempting?


Details here.
http://www.crossroadsfencing.com/BobuinoRev17/Programmer.html

CODE POSTED BELOW

Hey CrossRoads

I've seen that, but I didn't see the updated code from Nick Gammon - that has some C++ concepts that I've never seen before - intriguing!

That chip is very close to what I'm hoping to accomplish, sans an LCD Screen.
I'm hoping that I can use the components that I've already purchased and implemented into my project (listed in my first post), and create a code that works with those.

I'm going to do a bit more work trying to get one of those bootloaders to install onto my Arduino MEGA.

^^No luck so far - any suggestions? Issues posted below.

Thanks so much for any help! Very much appreciated

Ok, so here's one of the issues I've been having.

I connected two Arduino UNO's together (one as 'target', one as 'programmer')
I uploaded "Arduino as ISP" to one of the Arduino's

Then I tried about a dozen configurations trying to get the Gamebuino bootloader to upload.

This is the error I got (when using their pre-configured 'Arduino 1.8.5' file):

Arduino: 1.8.5 (Windows 10), Board: "Gamebuino Meta"

Please select a programmer from Tools->Programmer menu

I had 'Arduino as ISP' set as the programmer.
I've also tried:
AVR ISP
AVR ISP mkII
USBTinyASP
ARDUINOISP
ARDUINOISP.org
USBasp
Parallel Programmer

It seems it doens't matter which programmer I try to use, none of them are working

The reason I used their pre-configured file, is because it was the only way I could get "Gamebuino Meta" to show up in the Tools-Boards tab.

My arduino is plugged into port 4 - cable works, arduino works.
I also tried another cable, another arduino, and another bootloader - I was able to get my arduino to load a bootloader when I switched back to the regular Arduino UNO board - but that does me no good with my project.

Any suggestions?

Or perhaps someone can help me with uploading Nick Gammons code?
I can't get the "Atmeg_hex_uploader.ino" file to finish compiling.

I was able to get the "Atmega_Hex_Uploader_Fixed_Filename.ino" file to upload onto my Arduino! But.. That wasn't the file I wanted to upload so...

It looks like it is a problem in "Atmeg_Hex_Uploader.ino" that has to do with the "file.getFilename(name);" command, which isn't something SdFat recognizes.

I downloaded that code from a link found at the bottom of this page:

Ok. I found a fix for THAT problem (more listed below) - if anyone else is having the same issue, I deleted all files relating to SdFat.h library from my Documents->Arduino->libraries folder, and replaced it with the older version found just above the center of this page:

The file is called: "SdFat-master.zip"

www.gammon.com/au/uploader.

I ALSO had to reupload the libraries to the code. The only combination that worked for me was this:

#include <SPI.h>
#include <EEPROM.h>
#include <SdFat.h>

Those must replace the original lines in the code

After doing that - file finally uploaded!

NEXT PROBLEM:
Now I'm getting errors on my serial monitor.

This is what shows up in my Serial monitor:


Atmega hex file uploader.
Written by Nick Gammon.
Version 1.37
Compiled on May 12 2019 at 15:50:23 with Arduino IDE 10809.
Reading SD card ...
Can't access SD card. Do not reformat.
SD errorCode: 0X8,0X5D

--------- Starting ---------

Attempting to enter ICSP programming mode ......................................................
Failed to enter programming mode. Double-check wiring!
Halted.
Programming mode off.

I have my Arduino's wired like he has on his page (except I'm using two arduino's, instead of an arduino and a ATmega328 pin).

With the addition of a wire jumper going from pin 9, to pin 9 (as suggested on that same page)
And 4 additional jumpers going from pins 4-7 on both boards, respectively.

I'll try to reload the sketch with a few different sd cards and see what happens.

If anyone has any experience using/writing/building this code, please chime in

Thanks for any help!

  • Zach

AND I fixed the SD Formatting issue! As mentioned in the error, I needed to re-format my SD card to actually be FAT16 (just labeled FAT in the formatter)- it WAS FAT32, which as I now know is entirely different, and while it still was readable by my Arduino, it didn't work to read .hex files.

Still learning.

However, that did NOT fix the ICSP programming mode error.

At least I'm getting somewhere, albeit VERY slowly

Anybody have a fix for the 'Failed to enter programming mode. Double-check wiring!' error?

I'm assuming that the code is telling me correctly, that there is an issue with my wiring, but I'm not sure where. I'll go back through Nick's site and forum posts to see if maybe I missed something - now that the SD card is ACTUALLY reading.

OK! I've figured out exactly how to do this with my Arduino UNO. While Nick's site is layed out well, it really makes it difficult to see all of the posts that relate to each other.

Since I couldn't find all of the info in one place (And since I'm basically a lone wolf on this thread). I'll turn this into an organized, updated how to (as of 2019). Also, I'll do some reorganizing of all of the previous posts later, now that I've got a point 'A' to point 'Z' way of doing it.

First things first: To upload this bootloader onto any board, I recommend you follow the directions in this order. It may not work otherwise.

STEP 1:
https://www.gammon.com.au/forum/?id=11633

This post describes setting up/using the 'AT MEGA Board Detector' file. This is the first step to ensuring all of your wiring is correct. Download the file in that link
"arduino_sketches-master"

  • Open the sketch "Atmega_Board_Detector"
  • Set your programming board to "Arduino as ISP" - This was a necessary step
  • Set your board/port as you normally would for that arduino
  • Upload onto a BARE Arduino first - if it works, start adding the jumpers/cabling as per the 'target/programmer' image in the link.
  • Follow the instructions on that page (post 11633).
  • If it uploads and you can read your serial monitor, go ahead to STEP 2.
  • If it doesn't work, check the baud rate in your serial monitor - it should be at 115200.
  • If it STILL doesn't work, take out all of your wires, and start again.

This page is 7+ years old, BUT it still applies.

STEP 2:
Upload the 'Atmega_Board_Programmer' sketch

https://www.gammon.com.au/forum/?id=11635 vv Read Below!

NOTE: The MAJORITY of this page is outdated, and (for me) did not work with the updated Arduino IDE (1.6.4+).
You MUST change the wiring so that you are connected to your Arduino's 6 ICSP pins. Look towards the bottom 3/4 of that page to find the updated post by Nick Gammon.

  • Also be sure to set the Programmer to 'Arduino as ISP' - This is the LAST sketch where you will have to use this to upload the bootloader.
  • The COM settings will have 2 identically named boards show up - make sure that your arduino name is showing up after the COM number (i.e. "COM4 (Arduino/Genuino UNO)" - instead of just "COM4". If not, Disconnect your USB cable, save the sketch under a new name and close the Arduino program completely. Plug your USB cable back in and wait for it to recognize your Arduino. When it does, open the IDE again and select the port that your arduino is connected to.

I'll post 3-5 later today. This is enough to get you through the next few posts:

How to make your own programmer:
https://www.gammon.com.au/forum/?id=11637

The MAIN page (where you likely started, if you're like me and searched for 'Arduino as .hex Bootloader'
https://www.gammon.com.au/forum/?id=11638

Sometimes to go forward, you must go 2 steps (or in this case 3) back.