Skip to content

HIDUINO via ISP Method

ddiakopoulos edited this page Feb 27, 2012 · 3 revisions

Table of Contents

Introduction

This guide will direct a user through configuring a new Arduino UNO or Mega2560 as a class-compliant MIDI device. There are several different tools and methods for performing many of these steps, but this guide is an attempt to outline one of the easiest ways.For an excellent guide on the changes in the 2010+ Arduino redesign which makes this project possible, see http://www.ladyada.net/library/arduino/unofaq.html.

Many of the test steps are optional for users who are familiar with reprogramming AVRs with an ISP & avrdude.

The primary Arduino Atmega328 chip cannot be flashed while an alternate firmware (such as HIDUINO) is loaded on the 8u2 chip. To this end, many users will find themselves flashing the 8u2 between a HIDUINO firmware and the default Arduino usbserial firmware quite often, since Arduino sketches need to be loaded through the virtual serial port. This guide uses an ISP to flash the 8u2.

Unimportant side-note that affects very few users: HIDUINO firmwares are compiled without the DFU bootloader. Once any HIDUINO firmware is flashed onto the 8u2, the ability to use any DFU functionality is temporarily lost. To restore, simply re-flash the 8u2 with the DFU firmware bundled with Arduino.

Prerequisites

Arduino Hardware Modifications (Pre-2011 Models)

Note: Most Arduinos produced in 2011 come with the ISP headers presoldered, making this step unnecessary. To install the header pins, locate the block of six solder-filled holes near the USB jack (same location for both the Mega2560 and Uno). You must use a solder-sucker or other device to remove the solder. Once finished, re-solder a standard 6-pin header in place.

ISP Software Setup

We used the Atmel AVRISP MKII programmer.

Windows

The AVRISP2 drivers are included in the WinAVR package -- avrdude will _only_ work with these drivers. These drivers are found within a libusb directory in the WinAVR install path. Windows 7 x64 users might go through driver-hell during this process. This guide helps a lot.

Mac

CrossPack comes bundled with drivers for the Atmel AVRISP2. Once installed, it's pretty much plug-and-play. Development with CrossPack was tested on OSX 10.6 Snow Leopard.

Both Platforms

Make sure both the Arduino and ISP are powered over USB, otherwise the flashing process will not work. The Arduino board comes printed with a very small dot indicating the directionality of the ISP cable. The AVRISP will blink orange if the cable orientation is wrong and green if correct; other programmers may not provide this feedback!

Testing avrdude

The Arduino source download comes with the firmware preloaded loaded on the ATmega 8u2 chip. It’s located in

     arduino-00xx/hardware/arduino/firmwares/

Look through the README.txt file located in this directory. It mentions that that the 8u2 is preloaded with the DFU bootloader and virtual serial port firmware. The file in this directory is a combined version of both, ready to flash. The readme contains the directions for flashing the 8u2 with an ISP:

      avrdude -p at90usb82 -F -P usb -c avrispmkii -U flash:w:UNO-dfu_and_usbserial_combined.hex -U lfuse:w:0xFF:m -U hfuse:w:0xD9:m -U efuse:w:0xF4:m -U lock:w:0x0F:m

Navigate to the above directory and execute the command. Assuming the ISP cable is connected and the firmware can be found in the same directory, avrdude will take about 4-5 seconds to flash the 8u2. This test will be successful if it is still possible to upload a sketch to the board via the Arduino IDE. Good luck!

Optional: Setting up LUFA & Compiling

For most users, compiling HIDUINO is unnecessary. One of the most useful reasons for doing so is to rename a HIDUINO device. The precompiled HIDUINO firmwares enumerate to a computer as "HIDUINO." Compiling from scratch lets users rename their devices by changing a single string located in the Descriptors.c file, located on line 266 (or close by).

Make sure LUFA 101122 has been downloaded. Drop the entire LUFA directory in the HIDUINO folder

     HIDUINO\LUFA 101122

The HIDUINO firmwares are located in

     HIDUINO\src\project-name

Take the entire project folder and move it into

     HIDUINO\LUFA 101122\Projects

This is necessary for the makefile to find LUFA.

Once a HIDUINO project directory (in this case HIDUINO_MIDI) has been moved into the LUFA Projects directory, navigate to that folder and execute

     make

Both WinAVR and CrossPack come with AVR-GCC; the entire project should compile in 5-10 seconds. Once complete, it will output as an intel-formatted .hex, ready to flash with avrdude.

Flashing Arduino Sketches

Since the Arduino will no doubt be interfacing with your own electronics/sensors/robots, you'll want to flash your Arduino sketch first. For the primary Arduino ATmega328 chip to communicate internally with the ATmega 8u2, we use old-school serial-based MIDI. This is done through the most popular Arduino MIDI library (listed at the top of the guide).

Once the Arduino MIDI library is downloaded, drop the MIDI folder into your Arduino\libraries folder (located in Documents on OSX or My Documents on Windows) -- you may have to create the libraries directory first. Then add it to your sketch using the menu in the Arduino IDE. Arduino will only see new libraries after it has been restarted. See the FAQ for a question related to the MIDI-thru functionality of the MIDI library.

See the examples for a better idea.

     HIDUINO\Arduino Example Sketches\

As any alternate firmware running on the 8u2 removes the ability to contact the primary ATmega 328 chip using a virtual serial port, you will find yourself re-flashing the 8u2 with the default usbserial firmware and HIDUINO firmwares quite often during development.

Some people find it easier to burn Arduino sketches using an ISP as well, instead of switching between HIDUINO and usbserial. Doing so is incredibly easy and is documented on the Arduino website here.

Flashing HIDUINO

The file

     HIDIUNO\ISP_COMMANDS

has several example commands for flashing HIDUINO using an AVRISP MkII (or similar) programmer. The pre-compiled firmwares are located in

     HIDIUNO\Compiled Firmwares\

and are ready to use out of the box. In the case that you compiled a HIDUINO firmware from scratch, you'll simply navigate to the project directory and use that file as the .hex file to flash.

Finishing Up

Congratulations! If all went well, you should have a fully class-compliant MIDI device via Arduino. Open your favorite music software and have fun.

Don't forget, in order to re-program Arduino sketches you will need to switch back to the default usbserial firmware.