Flashing micro controllers with Arduino IDE or Platform.io are fairly simple when you have the source code of your sketch but there are times where all you have is the HEX file and you need a simple way to program your Pro Micro or other micro controllers quickly.
Both Arduino and Platform.io use a program called AVRDude in the background for flash but figuring our all the parameters and what come ports to use with AVRdude can also get quite complex standalone.
So, I found a much easier way to to use a minimal version of AVRDude and I created a simple command you can run at the command prompt to flash your Pro Micro.
All you have to do is:
- Download this zip file and unzip it to a folder on your drive
- Copy your HEX file to the same folder
- Open a command prompt and go to the same folder
- Attach your Pro Micro to your PC USB port.
- Next, the command you type depends if you have ever previously programmed the attached Pro Micro before or it its blank.
- If the attached Pro micro is not blank and previously programmed, Type PROG followed by your Hex file name and hit enter
- If the attached Pro Micro is blank, type PROGB followed by your Hex file name and hit enter
That’s it. You will see something like below and you are DONE!
If you are wondering how this works or if you have trouble, here is a step by step details of what the PROG command does. PROG and PROGB are batch files PROG.BAT and PROGB.BAT in the same folder that runs a series of commands. In short:
PROG looks for the Pro Micro attached to your PC by searching for a device called “USB Serial Device” to see what COM port it is. If you open up your device manager, you will see something like this. As you can see mine is on COM8.
If it was a Blank one, it would instead say “Arduino Leonardo” and why you need to use PROGB instead as it searches for Arduino Leonardo instead of USB Serial Device.
Now that it knows which COM port the device is on, it resets that port with command: mode COM8: baud=12 > nul
This causes the Pro Micro to go into bootloader mode for about 8 seconds. If you have device manager open, you will see the device change to something like this:
As you can see, it now in boot loader mode and its on COM4.
If for some reason it does not go to bootloader mode, you can manually force the Pro micro into this mode by shorting RST and GND pins for a quick second while its plugged in.
So next the PROG command will look for this device in the list searching for a device with Leonardo in the name and it figures out what COM port it is.
Next, the PROG command will execute the avrdude command: avrdude.exe -pm32u4 -cavr109 -D -PCOM4 -b57600 -Uflash:w:firmware.hex
Replace COM4 with your port and firmware.hex with your file name if you are doing this manually