Intro: Burn Custom Firmware Using ArduinoISP
If you want to burn custom firmware onto your Arduino, you'll need an ISP, or In-System Programmer. But why waste money on a name-brand ISP when an Arduino can do the same thing? This tutorial shows you how to install custom firmware on your Arduino using a second one as an ISP.
Step 1: What You'll Need
- Breadboard Jumper Wires (2x M to M and 4x M to F)
- A 10 to 40uF Non-Polarized (goes in either way) Capacitor
- 2x Arduino Boards
- Arduino IDE Software
- A Computer (Duh)
If the firmware you want to burn is for the serial chip, the Arduino being burned must be a recent revision. Only the latest versions of the Arduino use an Atmel ATmega 8U2 or 16U2 microcontroller as the serial chip, rather than an FTDI serial converter. Check the markings on your chip to confirm; the serial chip is the chip right next to the USB port.
If the firmware is for the main MCU, you can use any Arduino with a compatible microcontroller. Make sure to use the correct ICSP header.
We'll be using the HIDUINO firmware, which runs on the serial chip, in this example, so make sure your Arduino has the Atmel serial chip.
Step 2: Wire Your Circuit
First, get out the Arduino you want to use as an ISP. You can use any Arduino for this. I'm using an Arduino Deu... Deyo... The one before the Uno. Notice how it only has one ICSP header, because the FTDI serial converter is not reprogrammable.
Since the firmware we are downloading uses the serial chip, we'll use the ICSP header near the USB port of the second Arduino (In this case a Mega 2560).
The pins should be connected as follows:
- (ISP Arduino -> Arduino to Burn)
- Pin 10 -> RST (on ICSP)
- Pin 11 -> MOSI (on ICSP)
- Pin 12 -> MISO (on ICSP)
- Pin 13 -> SCK (on ICSP)
- Any 5V Pin -> Any 5V Pin
- Any GND Pin -> Any GND Pin
An ICSP pinout diagram is provided in the images above. Pay attention to which pin is marked as '1' on your board.
You'll also want to put a 10 to 40uF capacitor between the Reset and GND pins of your ISP Arduino. If the capacitor's leads are too short, or if your Arduino only has one 5V pin, you may need to use a breadboard.
Step 3: Install the Software
Now that you've finished the circuit, you can plug your Arduino into your computer. Next, we need to download the actual HIDUINO USB-MIDI firmware from here. After downloading and unzipping, you'll find the file under hiduino-master/compiled_firmwares/arduino_midi.hex.
You'll also need a way to burn the firmware to the Arduino. You actually don't need to install anything to do this, because avrdude is included inside Arduino. To make things easier, you can use this node.js script I wrote. You'll need Node.js in order to start the script, but after that it will auto-install all it's dependancies.
Don't forget to upload the ArduinoISP sketch (located under 'examples' in the IDE) to the Arduino you're using as an ISP.
Step 4: Burn the Firmware
Woah, not so fast! Before running the script, you need to adjust some of the variables to match your configuration. You might need to do some digging to find the location of avrdude in your Arduino install. For details on what each variable means, read the project's README on GitHub.
After the script is done installing dependancies, it will close automatically. Run it again and it will list available ports. The Arduino should have a brand name listed next to it, either 'FTDI' or 'Arduino', depending on the serial chip. Once you select it, you should see lots of text, and then a progress bar. After two full progress bars, the burning should be finished, and the script should say "Finished burning file". Now your Arduino has custom firmware on it. Yay!
You might also want a good MIDI library to interpret and send MIDI data. Try this one... that I totally picked at random, for no reason whatsoever...
Step 5: Upload to Arduino
But wait, what if you want to upload a new sketch to your Arduino? It's not listed in the menu when plugged in anymore.
Don't worry, the Arduino IDE supports uploading sketches using an ISP too! Just setup your ISP Arduino again (this time connected to the Main MCU's ICSP header) and select Arduino as ISP under the 'Tools/Programmer' menu. This will tell Arduino to upload through a programmer instead.
EDIT: Oh! I forgot to mention, you need to select Upload Using Programmer under the 'File' menu for Arduino to upload with the programmer you have selected.