Collin’s Lab: USB Hacking with Arduino

Arduino Music Technology
Collin’s Lab: USB Hacking with Arduino

collinsUSB

USB devices are so common nowadays, wouldn’t it be nice to use one with your homebrew electronics projects? I wanted to use my compact USB-MIDI keyboard with my homebrew synth circuits. It seemed a simple enough prospect at first – listen to the data output, press buttons, note the changes, and then program a microcontroller to turn those changes into something I could use (like basic serial MIDI data).

After a little investigating, I learned a bit about how USB works and that I’d need some extra hardware capable of playing the role of “USB Host” (a job normally left to a full computer) in order to properly work with my keyboard. Enter the USB Host Shield from Circuits@Home. This Arduino compatible shield uses a MAX3421E peripheral/host controller + supporting code library chip to quickly solve my ‘USB-without-a-computer’ problem.

I used the examples included with the shield’s Arduino library to gather some info from my USB-MIDI keyboard (an Akai LPK25) and then plugged those values into one of the included demo sketches. After figuring out what messages I was receiving, I redirected those bytes to an outgoing serial connection, and voilà – a USB-MIDI to MIDI converter was born!

I did run into a few hiccups in the process, but once I was able to actually read the output from the keyboard’s USB port, I simply applied the basic hacking technique of pressing buttons and observing results. HexDecBin came in very handy for the many binary to decimal conversions I made along the way.


Update:
Almost forgot – the sketch I wrote for use with the LPK25 can be found here

45 thoughts on “Collin’s Lab: USB Hacking with Arduino

  1. sobachatina.myopenid.com says:

    I’ve looked at USB host functionality but the solutions just need to be less expensive.

    The project is a good example. It is awesome and creative but-
    Arduino + USB host shield = $70

    Wouldn’t that pretty much destroy any economic advantage this project might have over commercial products?

    I have been using custom protocols over the serial interface and writing an application to interpret the protocol on the PC. A USB host is a much cleaner implementation.

    Is there any way to do this at prices that make sense?

    1. Collin Cunningham says:

      Well, one could build a new board that incorporates all the components used in the shield + Arduino – cheaper, but a major time investment.

      I did some searching and found no commercial products that handled this kind of functionality (do let me know if I missed any). You could of course use a computer to translate USB to serial/etc, but I’m a big fan of self-contained projects/devices.

    2. Oleg says:

      I make mini shield ($20) which mates with Arduino Pro Mini ($20) – that’s cheaper than full size but harder to work with.

      @Collin – thanks for posting your code!

      1. Collin Cunningham says:

        Ah – I completely forgot about the mini option. Now I want to build a compact version :)

        Thanks for for all the work you’ve done on this project, Oleg. It is very awesome!

  2. peterkirn.myopenid.com says:

    It appears vusb only does client, not host – but there may still be a cheaper way to go, somewhere.

  3. Improviser says:

    I just got a couple of USB to Midi converters on Ebay for $6

    1. Collin Cunningham says:

      Yups, but those will still require something to play the role of ‘USB Host’ in order to be of any use.

  4. WattSekunde says:

    It’s named the iConnectMIDI.
    http://www.iconnectmidi.com/

    And it looks very sexy to me.

    A few month ago I start reading the USB dev doku to do the same thing. ;-(
    My intention also was to connect my USB only equipment to Shruthi-1 and other gear for a live setup without Macbook.

    It depends on the price if I try to make my own, Maybe with Microchip PIC which I am familiar with.

  5. NickNackGus says:

    I am looking for an inexpensive keyboard with two octaves, USB support, and velocity and track bend pitch controls. Track bend pitch cannot be keys as on a QWERTY keyboard, like the Korg nanoKEYB 25 Key USB Controller Keyboard. (I can’t find information on posting links.) Post multiple models if possible, so I can find something I like even if your most recommended keyboard doesn’t work for me.

  6. Anonymous says:

    Hi Collin.
    I have been looking for this device commercialy for several years with no luck. I am very happy to have found yours. Unfortunately, I lack the skills to build it. How much would you charge to build it for me? There are tons of keyboards from Yamaha and Casio that lack the DIN midi jacks opting only for the USB midi. Would it be possible to make a 2-way connection so the device could receive as well? That way, a usb only keyboard could work with a hardware sequencer and sound modules. Thanks for sharing your great projects with us. Thanks…John

    jbsongbuilder@hotmail.com

  7. Paul-Arthur Asselin says:
  8. shantanu says:

    hello Mr. Collin, I think this is an excellent accessory for musicians, both amateur and professionals. I have been looking for a device like this to connect to my Yamaha PSR E-403 keyboard. The idea is to be able to recieve MIDI control / program messages and to be able to send MIDI messages (to change voice, volume, etc.) from the Arduino. I understand from the video and from the text that the code you have developed is able to recieve MIDI messages from a keyboard. My question is: Can this software also send some MIDI data from the Arduino to the keyboard? Thanks a lot for your guidance.

  9. shantanu says:

    Forgot to mention my e-mail in the previous post: shantanup@gmail.com

  10. Anonymous says:

    Would it be possible to connect this to a computer based software synth through a matched set of xbee pro’s thus turning this into a wireless USB connection?

  11. Richard Kjell Kjelleström says:

    Hi Colin!
    I found this video a couple of moths ago and i was inspired to do this myself. :)
    Now when i have all the components i try to upload your sketch to the Arduino board i get an error message that say “EP_RECORD does not name a type”.
    What could be wrong?
    I have no erlier experience in this.

    Sincerely Richard

    richard_kjellestrom@hotmail.com

  12. Richard Kjell Kjelleström says:

    Hi Colin!
    I found this video a couple of moths ago and i was inspired to do this myself. :)
    Now when i have all the components i try to upload your sketch to the Arduino board i get an error message that say “EP_RECORD does not name a type”.
    What could be wrong?
    I have no erlier experience in this.

    Sincerely Richard

    richard_kjellestrom@hotmail.com

  13. Jonathan Pedoeem says:

    Would i beable to use this to hack a magic jack (usb voip thingy) and use it with out a computer?

  14. Anonymous says:

    Picked up one of these and am really interested in getting working.  At the moment I want to make sure that the MidiVox is working, but the library that is linked leads to a 403 dead link.  Anyone have the library that was available here:

    http://timothytwillman.com/itp_blog/?page_id=240

    I’ve crawled the internet all over and that seems to be the only source.  I’m really looking forward to using the LPK25 with it, but currently am a bit disappointed that the MidiVox _requires_ that specific library…

  15. Anonymous says:

    Can you make a video, using the USB Host shield and a usb flash drive to loge temperature data over a week.

    -Vick

  16. Anonymous says:

    Can you make a video, using the USB Host shield and a usb flash drive to loge temperature data over a week.

    -Vick

  17. Steven Noreyko says:

    Colin… any chance you might revisit this project and update it with Oleg’s new version 2 USB Host Shield code?

    1. Christoph Stefan says:

      Any news on collin´s code? I can´t find a way to get it running, always getting errors when compiling :( .

      1. Steven Noreyko says:

        Using the code that Colin put together — you need to go find the original version of the code libraries on Oleg’s site. Oleg’s newer v2 code libraries will not work.

        See comments on this thread: http://www.circuitsathome.com/mcu/hid-support-for-usb-host-shield-library-2-0-released

        legacy code library here: https://github.com/felis/USB_Host_Shield

        1. Christoph Stefan says:

          Thanks for the reply!
          I found this thread & the old code already, but still I did not find out, which data sets I have to copy in which folder…

          If u could write a short “walkthrough” to get the code to work, u would do me a big favour. (I´m using macosx don´t know if it matters)
          everything arduino gave me were errors over errors, so please HELP!

          1. Steven Noreyko says:

            i put the library files in ~/Documents/Arduino/Libraries and renamed the Host Shield folder to “HostShieldOne”

            aside from that I’m not sure what else special I did when i set this up. Sorry I’m not much more help.

          2. bartek rączkowski says:

            works for me with sparkfun.com shield. 

            on macosx: download https://github.com/felis/USB_Host_Shield/zipball/master, unpack, rename so in does not contain any special characters. go to arduino app, right click on app, click “show package”, go to >contents >libraries and move the usb host lib there. load the sketch, delete the line with spi.h. and that’s it!

      2. Christoph Stefan says:

        I don´t get to work the outside connection -> from arduino to midi out. How do I connect the midi jack to the host shields serial out? I´m using DFRobot.com, I didn´t knew I bought no original arduino parts in the first place… So as I said, they keyboard lights up, all buttons work, but I don´t get no signal in my midi interface. Please HELP, there are only few steps from the point where this converter finally works. Thanks in advance, Greetings!

      3. bartreka says:

        this is easy – do it like this http://arduino.cc/en/Tutorial/Midi
        which shield are you using?

    2. Christoph Stefan says:

      Thanks for your reply!
      Still it won´t work. I´m using a DFROBOT.com usb host shield, although they say it´s compatible with arduino.
      Perhaps I have to program the board again…
      All that works right now, is that the akai keyboard has power, but still it doesn´t give out midi signals. I´m going to check every step again from A to Z and then report back! Have a nice weekend, best regards

  18. Scott Campbell says:

    nice! this is exactly what i am looking for (even using the keyboard i would like to use). Is it possible to send or receive midi clock with the arduino? gotta sync that arpeggiator

  19. John Pollard says:

    I’ve updated Collin’s sketch to support MIDI IN (via interrupt), the new MPK-MINI and MIDI program change commands. I updated the code and added some instructions inside because things have changed since this was initially written. You have to use legacy libraries and a legacy Arduino build.

    You can download my sketch here:

    http://www.viralstudios.net/arduino/mpk_mini.pde

  20. sinewave says:

    Hi Collin,

    No replies from you for a long while, but I’ll have a go anyway :) You mention “running into a few hiccups in the process”. I’m hoping it’s the same issue as I’m having – namely that I can’t seem to get input from my Korg NanoKey (Mk I). I’ve successfully parsed the descriptor on my OP-1 and a usb card reader, but I’m getting nothing from the NanoKey (which otherwise is functioning correctly). I see in the code that there are some tweaks to work with the NanoKey but until I can parse the descriptor I won’t get very far with that…please help if you can. Thanks!

    1. John Pollard says:

      Sinewave, if you haven’t please give my sketch a go.

  21. midi boy says:

    hi everyone,
    I know its an old post but still usb host to midi is a great ability and reasonable to do diy. there was the question about an existing comercial product. if you are still looking, here might be the solution:
    http://www.kentonuk.com/products/items/utilities/usb-host.shtml

    but I do like diy better and yes it should be doable for a lot less $ i guess. as well there are usb host boards with bluetooth for arduino what could make a awesome synth-in-the-phone solution. I wonder why there seems to be no projects out there yet…

    thanx for the posting and developement. I wish I would have more Genius to participate. I totally would build a pocketsize, battery powered, 15$, diy, stand alone kit – usb+host+midi+bluetooth : )

  22. marco says:

    Hi Collin!

    When I upload the code and open the Serial Monitor, the program only initialized the Akai LPK25, but when i press a key i don’t receive any data. Do you know what the problem could be?

    I use the USB Host Shield 2.0 and Arduino Duemilanove w/ATmega328.
    Please help me!

  23. siebenhirter says:

    Hi,
    as i know there is an ATmega32-A inside of my Korg Nanocontrol Midi-controller im looking for each information about it.
    Can you help me to modify an Korg Nanocontrol, not to transmit its Midi-commands to an Midi-controlled device over USB-Midi-Hub but only over 5-pin-DIN-connections without Usb-hub.

    http://www.openmusiclabs.com/files/korgNano/

    Is it difficult to complete Nanocontrol with electronic parts to be used with its functions, but without using an USB-Hub? I want to use a Nanoncontrol-Midi-Controller with 5-pin-Midi-Out-connector instead an USB-cable.

    It would be nice to use a midi- keyboard, connected its Midi-In with an DIY-Midi-Out of Nanocontrol, to use functionality of Nanocontrol without USB-data-through and without need of an USB-hub. Could it be possible to send data from Nanocontrol midi-formatted by some hardware-added-components?

    Thank for any informations

  24. Dimitri says:

    Hi Collin, this is a great project!
    I have some questions:
    1) is it true that using the USB Shield you still have RX-TX ports free, so that you could use standard midi too, at the same time?
    2) if you want to use 2 USB-Midi devices at the same time, it is possible to add another USB Shield or it would need some library functions to manage that?

  25. TVulgaris says:

    I’m just wondering if those little USB data transfer devices aren’t sufficient to do the job, albeit possibly requiring a little external power to supplement the small batteries…
    I mean, you have to be host in order to handle the port routing, right? Let alone the input/output devices themselves can be passive (and mostly are), so SOMETHING has to grab the data from one port to another AT LEAST, if it doesn’t actually go into the the input and output data devices and manage the data there…and they were dirt cheap a couple of years ago, but I’m not sure you can even find them easily any more.

  26. Kites Pongan says:

    Howdy, have there been any tests done with Teenage Engineerings OP-1? The ohpeewon community is inquisitive :)

  27. nike pas cher says:

    An individual did not remember one to include Playlist. com, just where it’s not actually even needed for you to definitely sign-up and you will steady stream virtually any tune you need.
    nike pas cher http://www.pclf-epi-54.fr/Files/nike-free/

  28. chaussures nike blazer pas cher says:

    A good music web page, for me, is only one containing EVERY LITTLE THING, and that includes my tunes. We have looked at every site, the only a couple of that happen to be value enough time are 8tracks and also Grooveshark.
    chaussures nike blazer pas cher http://www.frassinea.asso.fr/images/nike-blazer/

  29. DB says:

    HI could you do a fuller tutorial with the hardware steps as well, eg soldering? Maybe some pics would be great :)

  30. Russell Cottier says:

    Hi Collin, great advice. I’m trying to get a Mega to talk to a VOX (korg) Tonelab ST. Simply to send a sysex command to the USB MIDI input on the Tonelab. Whilst I can get my USB host Shield talking to other USB MIDI devices the Tonelab ST is not playing ball. I suspect becuse it is also an audio device. I’m thinking the enpoints might be the issue. Any advice on identifying endpoints and editing them in the script/library?

Comments are closed.

Discuss this article with the rest of the community on our Discord server!
Tagged

ADVERTISEMENT

Maker Faire Bay Area 2023 - Mare Island, CA

Escape to an island of imagination + innovation as Maker Faire Bay Area returns for its 15th iteration!

Buy Tickets today! SAVE 15% and lock-in your preferred date(s).

FEEDBACK