Pages: [1]   Go Down
Author Topic: USB-MIDI to Serial MIDI withUsb Host Shield - Success... But...  (Read 1846 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 !  smiley 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:
https://github.com/YuuichiAkagawa/USBH_MIDI

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: http://www.keithmcmillen.com/QuNeo/tour

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!!

Code:
/*
 *******************************************************************************
 * 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);
    }
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Rome
Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.



Logged

Pages: [1]   Go Up
Jump to: