Turn Your Arduino Uno Into an USB-HID-Mididevice

156K12622

Intro: Turn Your Arduino Uno Into an USB-HID-Mididevice

While building an Arduino Uno based Midi-Controller for Ableton Live, I came across the HIDUINO project ( http://code.google.com/p/hiduino/ ). It allows you to turn your Arduino Uno (or any other device using an AVR-USB chipset like the 8u2) into a driverless HID/Midi device. It's much more comfortable than using a software based serial to midi converter which has to run in the background all time.
The only downside is that you loose the ability to upload your sketches over USB while using the custom firmware. Therefore an ISP programmer is helpful!

This is just a short Instructable describing how to set up your Arduino as an HID/Midi device with the help of an ISP programmer.

More informations are avaliable under: http://code.google.com/p/hiduino/w/list

STEP 1: Gather Your Materials

Things you need:
- A compatible Arduino board. I'm using the Arduino Uno here.
- An AVR-ISP programmer. The AVRISP mkII works great and is used here.
- Software to use your ISP programmer; up and running. I'm using the AVR crosspack with avrdude on my MacBook Pro.
- The HIDUINO software from here http://code.google.com/p/hiduino/downloads/list

To get ready for the next steps you have to unpack the HIDUINO archive.

In the unpacked file move to the folder "Arduino Libraries". Inside you will find another folder called "HIDUINO_MIDI_Lib".
Move this folder into your Arduino - Libraries folder.
The final result should look like this /Users/phil/Documents/Arduino/Libraries/HIDUINO_MIDI_Lib

We haven't moddified the original USB firmware yet, so it's still intact and you can use it to flash an example sketch to your Arduino.
Try the first sample from the HIDUINO archive. It's located under "Arduino Example Sketches" and really easy to understand.
You don't have to do this yet, but it allows you to test your device immediately after reflashing the USB firmware.

STEP 2: Programming the New USB Firmware

Okay, the first thing we want to do is to reflash the Uno's 8u2 chip.
Therefore we need to do the following:

- Connect your ISP to your Arduino. (Be sure to connect it in the right way! The pinheader should be marked with a little white dot! It marks pin number one! On the ISP cable it's marked with a little arrow.)
- We want to flash the following file: HIDUINO/CompiledFirmwares/HIDUINO_MIDI_Uno.hex
- I'm using avrdude in a terminal window on my Mac. I used the following command  for an Arduino Uno and an AVRISP mkII:
avrdude -p at90usb82 -F -P usb -c avrispmkii -U flash:w:HIDUINO_MIDI_Uno.hex -U lfuse:w:0xFF:m -U hfuse:w:0xD9:m -U efuse:w:0xF4:m -U lock:w:0x0F:m

- after 6-10 seconds the new firmware should be flashed successfully! Your device should show up in your system profiler now! If not just unplug it and replug it back again :) Then you can move on to the next step! :)

- In case you want to restore the original frimware of the 8u2 you can find it in your Arduino application folder. On a Mac its located under:
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/firmwares/UNO-dfu_and_usbserial_combined.hex
- Reflash it using avrdude an this command:
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

There are tons of instructables and tutorials on how to flash an AVR using avrdude. This is just a short sum up of paths and commands ;)

STEP 3: Programming the Uno Using ISP

After successfully flashing the USB firmware you can't upload sketches over usb anymore.

I wanted to keep the ability of using the Arduino software to upload the sketches over ISP.
Therefore you have to edit the boards.txt located under: /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/boards.txt

Add the following code to the textfile and save it.

##############################################################

avrispmkii.name=AVRISP mkII w/ ATmega328

avrispmkii.upload.protocol=avrispmkii
avrispmkii.upload.maximum_size=32256
avrispmkii.upload.speed=19200
avrispmkii.upload.using=avrispmkii

avrispmkii.bootloader.low_fuses=0xff
avrispmkii.bootloader.high_fuses=0xde
avrispmkii.bootloader.extended_fuses=0x05
avrispmkii.bootloader.path=optiboot
avrispmkii.bootloader.file=optiboot_atmega328.hex
avrispmkii.bootloader.unlock_bits=0x3F
avrispmkii.bootloader.lock_bits=0x0F

avrispmkii.build.mcu=atmega328p
avrispmkii.build.f_cpu=16000000L
avrispmkii.build.core=arduino


##############################################################


Now it shows up in the Arduino software.

Just choose the newly created board, connect your ISP the right way and upload your sketches like you always do :)

Browse to your HIDUINO folder and upload the following example (if you haven't done it already ;)): /Users/phil/Downloads/HIDUINO/Arduino Example Sketches/HIDUINO_MIDI_Example01/HIDUINO_MIDI_Example01.pde

Thats it!! Fire up Ableton Live or any other music program and listen to your Arduino generated notes!! (Don't forget to configure you music program to talk to your device.)

It's my first Instructable and I hope it helped you a bit to get the HID/Midi running :)

In a few weeks I'll show you how to create the hardware for a  4-channel midi controller :)

21 Comments

Hi, is it possible to upload the hiduino he's file to the chipset by dfu mode?
Looking forward for your reply.

Hi,

this is an awesome project. I can't get mine to work though. I am trying to flash an arduino mega2560

I
am using a mac on OSX 10.11.3 I went to "Pimpmyhiduino" page and got
my custom hiduino, which was titled "output.hex". I have an
avrispmkII. I opened a terminal window, navigated to the folder where
output.hex was.

then I typed in:

avrdude -p at90usb162 -P usb -c avrispmkii -U flash:w:output.hex -v -F

I got the following message:

avrdude: stk500v2_command(): command failed
avrdude: stk500v2_program_enable(): bad AVRISPmkII connection status: Target not detected
avrdude: initialization failed, rc=-1
avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x000000 (retrying)
avrdude: Device signature = 0x000000 (retrying)
avrdude: Device signature = 0x000000
avrdude: Yikes! Invalid device signature.
avrdude: Expected signature for AT90USB162 is 1E 94 82
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.

avrdude done. Thank you.

I also tried this:

avrdude -p at90usb82 -P usb -c avrispmkii -U flash:w:output.hex -v -F

and
received the same message. I had my arduino connected to a USB port to
bus power it, and I had the avrispmkII plugged into the headers.

Let me know if you have any suggestions. I'm pretty sure the arduino and avrispmkII were connected, but I didn't see the arduino mega listed as a USB device when i did a system report but I did see the avrispmkII.

thank you.

Hey!

For all of you that wish to name your HIDUINO firmware whatever the name you want, we've made this web tool that lets you compilo your own version of HIDUINO. That way, the Arduino will be seen as the Device and Manufacturer name you choose.

http://pimpmyhiduino.yaeltex.com

Did anyone use an arduino clone when doing this and did it work?
The reason I'm asking is because the clones use a CH340 chip instead of the standard arduino FTDI one (for usb serial comm).

If so, did it also work on computers which don't have the CH340 driver installed?
Thanks,
Iftach

I wish it was possible! Just with boards with ATmega8U2, or similar it can be done. No CH340...

Yeah I've actually figured that out the hard way...
Anyhow, I *would* suggest using a Teensy for anyone who's willing to pay some extra $$$ for saving time and/or has a limited project physical size. ;)

Hi, did you have any luck with CH340?

If i use kit Burn-e to flash type ISP. How I should config (fulse bit....etc...) ?. (I'm using google translate ??)

Hello, does anyone knows if it's possible to une the midi over usb AND the sparkfun midi shield (connected to rx/tx)? I have searched google but could find an answer...

Thanks!! This is exactly what I was looking for to build my handless midi controller.

and for the Arduino Due?
Can this be used with TRAKTOR DJ I am planning to make ne with ARDUINO MEGA board.

And thanks for the tutorial

Sid
could u plz post the board files with the attiny85 and atting45
Hey, take a look at this site: http://hlt.media.mit.edu/?p=1229
You will find the files there :)
ur arduino is ....somethings wrong coz the atmega 8u2 is kept side ways ?????? wat does that mean??
Yeah you are right! I haven't noticed it before! I don't know why it's place side ways. The Arduino I'm using is really new. Maybe it got redesigned in newer versions?!
How is the lag between triggering a note on a controller (e.g., midi keyboard) and hearing a note on the computer? Is it quick enough for live playing?

Also, I don't have an ISP programmer. Can I assume HIDUINO would keep me from using, say, an FTDI programmer connected to Tx/Rx pins on the UNO?
Momentarily I'm using 4 linear sliders and 12 potentiometers to control Ableton.
It works quite fast. There is no noticable lag ;)
Working live with it should be no problem :)

There is a tutorial on how to flash the new USB firmware without an ISP adapter, but i haven't tried it yet. Working with an ISP is far more comfortable. Check out this link: http://code.google.com/p/hiduino/wiki/UsingHiduinoDFU

But then you have to restore the original USB firmware every time you want to upload a sketch to your Arduino over USB.
Afaik can not use your FTDI to program the USB chip. But you can use it to upload sketches to your Arduino.
More Comments