Another popular USB peripheral code for USB Host Shield has been implemented! Collin Cunningham from Collin’s Lab @ MAKE found a neat way of interfacing USB MIDI devices with Arduino. The video above demonstrates using Akai LPK25 keyboard and USB video game guitar to play music on Arduino. Quoting Collin, his setup is “USB MIDI to old-school MIDI converter”.
Make sure to check out Collin’s code – it’s one-piece sketch, short, clean and easy to understand. It is Richard Ibbotson’s PS3 code, re-purposed to parse MIDI data. While not a textbook implementation of USB MIDI, Collin’s code can be used to talk to MIDI keyboards, guitars, and consoles, to name a few. Good job, Collin!
Oleg.
would it be possible to make this usb host to midi adapter using the Arduino mini pro and the host shield for the mini pro? if so, could the same code that Collin put together still be used? i’d like to do what Collin did but embed the arduino and shield inside of a device (so smaller would be better).
It would depend on a particular device – some don’t like 3.3V on VBUS, others do.
ah, i see that the mini usb host shield is 3.3V
How about using a USB Teensy?
http://adafruit.com/products/199
Could be built into a small, dedicated box for less than $25
–tom
hello Oleg, i’m trying to do this usb to midi interface, but i have some problems. i’m using sparkfun shield (http://www.sparkfun.com/products/9947) which seems to be compatible with yours, but the troubles are with the libraries. Colin, the autor of this script (http://blog.makezine.com/archive/2010/11/usbhacking.html) uses old libraries with spi.h, and he mentions that he uses an alternate Spi Library from Circuitsathome.com. but i cannot find them. can you help?
with new libraries and spi.h commented out the machine starts, but nothing more – it simply doesn’t react
thanks
and cheers from Poland
Spi is part of legacy library -> https://github.com/felis/USB_Host_Shield, you need to use it with Collin’s code.
thank you for the answer
as i understand form this article http://www.circuitsathome.com/mcu/updated-usb-host-library-uploaded-to-github
i should delete the line with spi.h ?
but then colin’s code compiles and uploads, the akai keyboard (i’ve got exactly the same) initializes but nothing more. no reaction when i press the keys
do you have any idea?
thanks!
i don’t know much about MIDI, sorry.
Also, check this page -> http://electronicdelectables.blogspot.com/2011/02/lunch-project-midi-keyboard-and-usb.html
still nothing. i returned the sparkfun board. do you think v2 will work? or any from lipoly.de?
thanks
V2 will surely work with USB code. I can’t say anything about MIDI.
I’ve been poking at this for a while now (2-3 weeks, everyday), and I keep getting sporadic results. The three devices I’ve been testing are the Akai MPK mini keyboard, the Korg nanoPad, and the Teenage Engineering OP-1. My final straw that has officially driven me insane was a moment where after days of searching usb specs, looking through the library, and looking for examples, I reverted to the basic example provided with this link and got the OP-1 talking. About 10 minutes later, I reset the arduino and tried it again with the same code, and now I’m getting nothing. I tried switching back to the Akai (which I had gotten working before with the same basic code), and now it was hanging up, with Usb.getUsbTaskState() returning 0x12, 0xf, and 0x3e, switching between these randomly on resets.
Does anyone have any insight? Anyone have examples of usb-midi with the new library for this? I’m at my wits end trying to break through this, especially after 2 weeks of nothing.
ignotuscaligo… Please see my sketch linked on Collin’s blog.
http://electronicdelectables.blogspot.com/2011/02/lunch-project-midi-keyboard-and-usb.html
SORRY, this is the right link. http://blog.makezine.com/2010/11/30/usbhacking/#comment-480909
Hello Oleg, I develop V2 based MIDI Library.
https://github.com/YuuichiAkagawa/USBH_MIDI
Thank you for your great project.
Thank you very much!
Здравствуйте, Олег!
Очень заинтересовался данным проектом и решил реализовать его у себя дома, но столкнулся с некоторыми проблемами.
За основу естественно взял код Collin’а, слегка его модифицировав под свое пианино, с помощью этой статьи http://electronicdelectables.blogspot.ru/2011/02/lunch-project-midi-keyboard-and-usb.html.
Задача стояла в том, чтобы помимо получения данных о клавишах, можно было выполнять еще некоторые действия в основном цикле. При отключенном usb-устройстве, код в основном цикле работает без проблем, однако при подключении usb-midi клавиатуры у меня возникает задержка порядка 2-х секунд (точнее 2286мс)
Все очень похоже на проблему пользователей Konrad и Darnok – пост February 26, 2013 at 3:22 am (http://www.circuitsathome.com/mcu/hid-support-for-usb-host-shield-library-2-0-released/comment-page-1#comments)
Я решил покопаться в коде и поискать место, в котором возникает данная задержка. Путем выставления временных меток и отображения их в “serial monitor”, я в итоге нашел проблемную строчку, следующего вида:
rcode = Usb.inTransfer( LPK25_ADDR, ep_record[ INPUT_EP ].epAddr, LPK25_01_REPORT_LEN, buf );
Честно говоря, мне не хватает знаний, чтобы копнуть глубже и разобраться. Не могли бы Вы мне помочь, а то я в тупике))
Если это поможет я использую: Freaduino UNO V1.8.1, USB Host Shield 1.0 (ITEAD STUDIO) и библиотеку USB Host Shield 1-ого релиза.
Первый релиз был очень давно. Я уже не помню, какие там были плюхи. Может быть, девайс слишком медленно отвечает, но с этим ничего сделать нельзя, нужно просто поллить пореже.
А что такое “NAK” в файле Usb.h библиотеки?
#define USB_NAK_LIMIT 32000 //NAK limit for a transfer. o meand NAKs are not counted
Я так понимаю эта строчка за количество повторов при неудачных попытках в каком-либо процессе.
Предполагаю, что у меня где-то неверно указаны данные, необходимые для обработки моей строки, и весь процесс из-за этого тормозится
rcode = Usb.inTransfer( LPK25_ADDR, ep_record[ INPUT_EP ].epAddr, LPK25_01_REPORT_LEN, buf );
Я сменил значение с 32000 на 5, и теперь задержка составляет приемлемые для меня 2мс)))
И в остальном все работает нормально – нужные данные поступают.
Спасибо за хорошую работу и потраченное на меня время))
Все правильно, это количество повторов. Можно поставить 1, будет еще быстрее.
Здравствуйте, Олег!
Не подскажите, пожалуйста, можно ли реализовать подобное на Arduino Due? Один из USB портов этой платы может работать как USB Host, но в интернете пишут только о подключении стандартной периферии, такой как клавиатура и мышь. А вот как дело обстоит с нестандартными устройствами – не понятно. Может вы сталкивались или слышали что-нибудь об этом?
Спасибо!
Я не пишу ничего специально для Due. Проект переноса текущего кода идет, но не очень быстро.
is it possible to send AND receive midi data with these board ? which code should you use ? i think ps3 code is just one way …
try this code -> https://www.circuitsathome.com/mcu/midi-support-for-usb-host-2-0-library