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