USB-MIDI to Serial MIDI withUsb Host Shield - Success... But...

Hello people!
Firstly I'd like to say I'm not an advanced user so please be patient with me if I say stupid things ! :slight_smile: and thanks in advance!!

I've been trying to use USB-MIDI Devices without computer (using standard Serial MIDI with 5 pin DIN conectors) for my Music Gigs. I recently managed to do so using the USB Host Shield V2 from Circuit at home.

The USB Host Shield:
http://www.circuitsathome.com/products-page/arduino-shields/usb-host-shield-2-0-for-arduino

Using the Library and Example that Yuuichi Akagawa provided in this link:

The circuit is very basic, Arduino UNO, with USB-Host Shield on top, and a MIDI output from Arduino TX using an 220ohm resistor.

With the example from Yuuichi Akagawa, I managed to recieve successfully and "translate" to standard MIDI a few USB-MIDI controllers already... I thought everything was working 100% perfect untill I recieve the other day my new MIDI Controller, The Quneo by Keith McMillen: QuNeo USB MIDI Drum Pad Controller for Music Production | Keith McMillen Instruments

The special thing about this controller is that is capable of sending multiple MIDI values from each button (or sensor). Each of the buttons can send Note on-off + Velocity, CC of the pressure applied, X and Y position also using CC´s (Midi Control Changes). In total is capable of sending 4 MIDI values simulateously...

Using MIDI-OX which is a MIDI Monitor application for PC, I can visualize the Stream of MIDI data recieved by the controller. Using the controller with the provided USB straight in to the computer, the MIDI Stream shows how certain MIDI values arrive all at the same time. All the values are recieved as expected.

www.inspektorgadjet.com/Downloads/Using-USB.jpg

However if I use the Arduino solution, many values are missed, and some not recieved at all... I think this is due to the fact that the Controller is sending some of this values exactly at the same time, and Arduino is listening to just one MIDI message at a time. In this case the MIDI Monitor shows that the stream of values is unconsistent... and all the values are recieved in different times, there is no 2 values hapening at the same time.

www.inspektorgadjet.com/Downloads/using-arduino.jpg

So my question is, how can I manage this multiple values simultaneously?

Thanks a lot!!

/*
 *******************************************************************************
 * USB-MIDI to Legacy Serial MIDI converter
 *
 * Idea from LPK25 USB-MIDI to Serial MIDI converter
 *   by Collin Cunningham - makezine.com
 *******************************************************************************
 */

#include <Usb.h>
#include <usbhub.h>
#include <usbh_midi.h>

USB  Usb;
USBHub  Hub1(&Usb);
MIDI  Midi1(&Usb);
MIDI  Midi2(&Usb);

void MIDI_poll();
void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime);

void setup()
{
  Serial.begin(31250);

  if (Usb.Init() == -1) {
    while(1); //halt
  }
  delay(200);
}

void loop()
{
  unsigned long t1;

  Usb.Task();
  t1 = micros();
  if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
  {
    MIDI_poll();
  }
  doDelay(t1, micros(), 10);
}

// Poll USB MIDI Controler and send to serial MIDI
void MIDI_poll()
{
    byte outBuf[ 3 ];
    uint8_t size;

    if( (size=Midi1.RcvData(outBuf)) > 0 ){
      //MIDI Output
      Serial.write(outBuf, size);
    }
    if( (size=Midi2.RcvData(outBuf)) > 0 ){
      //MIDI Output
      Serial.write(outBuf, size);
    }    
}

// Delay time (max 16383 us)
void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime)
{
    unsigned long t3;

    if( t1 > t2 ){
      t3 = (4294967295 - t1 + t2);
    }else{
      t3 = t2 - t1;
    }

    if( t3 < delayTime ){
      delayMicroseconds(delayTime - t3);
    }
}

Ok so I will answer myself...

Allthough the MIDI protocol is serial, and the same goes for USB, no more than one MIDI values should arrive at the exact same time to the Arduino from the MIDI controller.... but this is exactly whats hapening with the QuNeo. QuNeo sends more than one value in the same USB Packet... the current code allows just for one MIDI message per USB packet.

The developer of the library is working on it... so thankfully this issue will be solved soon... Will post results once is working!!
Cheers!

Hi,
I would like to achieve exactly the same result and I found your post extremely useful to me. Thank you!

I have an Arduino Leonardo (Olimexino) and I've just ordered the same USB HOST shield V2. Hope the header pinout doesn't require any modification. Do you need to connect the ICSP too?

My question is about the power: does it work with 5V or 3.3V? I would like to make both of them working with 5V.

Since you successfully implemented this library i would like to ask a question about where to use the USB Vendor ID and USB Product ID. Where in the class should these be implemented and how?

Help would be much appreciated!

Cheers,
Tim

Could this solution also convert Legacy serial midi to USB midi? I want to send midi messages from a POD HD500 to a Zoom MS-70. The POD only has serial midi and the Zoom only has USB. I don't want to use a computer, I want to fit it on my pedal board. Thanks!

Multiman, do you know if the USB Host MIDI library now supports concurrent packets mentioned in your original post? I'm having similar issues from an Arturia keyboard that may send multiple note on/off messages simultaniously and I lose some and therefore the notes get "stuck" (keep playing because the llibrary didn't get one of the note off messages).

Multiman is now shown as a guest which means that sometime in the last four years he left the forum and will not get notification of your message.