No midi received with USB Host Shield + Uno

Hi,

I'm trying to receive the notes played on a MIDI piano. For this, I used an Arduino Uno R4 Wifi and a usb host shield, as well as the UHS2-MIDI library. It worked without a hitch, just by plugging the keyboard into the shield.

Then I fried my Uno R4 and the shield (unrelated test with motors) :frowning: And I'm trying to get the same setup with a Uno R3. I've changed the shield, and even tested 2 of them, thinking that the first might have a fault, because I'm having very strange behavior with this code similar to the "Callbacks" example (with debug print) :

#include <UHS2-MIDI.h>


USB Usb;
UHS2MIDI_CREATE_DEFAULT_INSTANCE(&Usb);

// -----------------------------------------------------------------------------

// This function will be automatically called when a NoteOn is received.
// It must be a void-returning function with the correct parameters,
// see documentation here:
// https://github.com/FortySevenEffects/arduino_midi_library/wiki/Using-Callbacks

void handleNoteOn(byte channel, byte pitch, byte velocity)
{
  // Do whatever you want when a note is pressed.

  Serial.println("NOTE");
}

void handleNoteOff(byte channel, byte pitch, byte velocity)
{
  // Do something when the note is released.
  // Note that NoteOn messages with 0 velocity are interpreted as NoteOffs.
}

// -----------------------------------------------------------------------------

void setup()
{
  Serial.begin(115200);
  Serial.println("Start Pianocktail");
  // Connect the handleNoteOn function to the library,
  // so it is called upon reception of a NoteOn.
  MIDI.setHandleNoteOn(handleNoteOn);  // Put only the name of the function

  // Do the same for NoteOffs
  MIDI.setHandleNoteOff(handleNoteOff);

  // Initiate MIDI communications, listen to all channels
  MIDI.begin(MIDI_CHANNEL_OMNI);

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

  Serial.println("INIT OK");
}

void loop()
{
  Usb.Task();
  // Call MIDI.read the fastest you can for real-time performance.
  MIDI.read();

  // There is no need to check if there are messages incoming
  // if they are bound to a Callback function.
  // The attached method will be called automatically
  // when the corresponding message has been received.
}

When I connect my sound board or my keyboard, I've the "INIT OK" but no "NOTE" when I pressed the keys. Except if I press a specific button on the sound board ("NR Config"), then the note played are received! Very weird, but it seems that there is no hardware issue? This button seems to send a midi signal which is not a note. I tried to use usbh_midi.h / usbhub.h and the dump example and the pressing of this button give the following trace:

11:28:59.631 -> 0000175B: 64: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
11:28:59.663 -> 0000176D: 64: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
11:28:59.663 -> 0000177E: 64: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
11:28:59.694 -> 00001790: 64: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
11:28:59.727 -> 000017A1: 24: 0B B0 0C 00 0B B0 0F 0E 0B B0 0C 01 0B B0 0F 0D 0B B0 0C 00 0B B0 0C 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
11:28:59.727 -> 000017B3:  4: 0B B0 0C 00 00 00 0F 0E 0B B0 0C 01 0B B0 0F 0D 0B B0 0C 00 0B B0 0C 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
11:28:59.760 -> 000017C4:  4: 0B B0 0C 01 00 00 0F 0E 0B B0 0C 01 0B B0 0F 0D 0B B0 0C 00 0B B0 0C 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
11:28:59.793 -> 000017F6:  4: 0B B0 09 11 00 00 0F 0E 0B B0 0C 01 0B B0 0F 0D 0B B0 0C 00 0B B0 0C 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

But do no detect other note played before or after, weird again... And I can't make my keyboard work. There is nothing else attached to the boards and they are brand new.

I've some doubt about the compatibility of the Uno R3 with the librairies, but it's not easy to understand the compatibility list (for example Uno is listed here MIDIUSB - Arduino Reference) when the usb host shield is added to the board.

Thank you in advance for your help :slight_smile:

A Uno can not send MIDI data without the use of a helper application. Typically Hairless was used to translate the serial data a Uno sent into a MIDI interface for the rest of your code.

The problem here is that Hiarless is a very old 32 bit application so it will not work on PC or Macks that can not cope with a 32 bit application. On the Mac the last OS that could do that was macOS Mojave Version 10.14.6.

What are you running on?

Yes but look at the compatibility note. It is not the same function as some of the others in that list.

Thank you for your answer!
Yes I‘ve seen the compatibility note but I was wandering if the usb host shield would have change the parameters… Seems not! But is it not weird that I succeeded to get some notes in a specific situation?
Is there something different in the Uno R4 WiFi that explains I easily received notes in the past?

Thanks in advance :slight_smile:

I’m running the tests on a MacBook M1 (Ventura) but the final project will have no computer connected, the midi received will trigger motors :slight_smile:

The R4 is a totally different processor, with support for reading and writing external devices like keyboards and mice. This facility does not exist on a Uno.

I see, thanks!
Not the first time I’m mistaken by the R3 / R4 which in fact describe very very different devices ^^
I’ll wait for my new R4 WiFi then :slight_smile:

Oddly enough most of the complaints I have seen are about Arduino Uno stuff not working on the R4, not the other way round. :wink:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.