Receiving data (MIDI) from digital keyboard

I am attempting to control a RGB light strip with my Yamaha P71/P45 using an Arduino Uno. I figured a good place to start would be to see if I could read data coming from my keyboard.

As a side note, I’m not sure if my keyboard is outputting MIDI or not. A quick google search gives us…

“The P45 doesn’t have a built-in MIDI or audio recorder, which would allow you to record and playback your performances. However, you can still use USB (MIDI ) connection and, using certain music software, record your music.”

I did some research and found that I may need a USB Host Shield, so i ordered this one.

I soldered the correct jumpers on the shield and installed the suggested library.

The only example project included with the library which I found to give me any output on the serial monitor was “USB_MIDI_converter” (code included below). Unfortunately the “output” is nothing but a stream of question marks only broken up by random symbols which outputted whenever I pressed or released a key.

Code for “USB_MIDI_converter” included example:

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

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>

#ifdef USBCON
#define _MIDI_SERIAL_PORT Serial1
#define _MIDI_SERIAL_PORT Serial

// Set to 1 if you want to wait for the Serial MIDI transmission to complete.
// For more information, see

// MIDI Pin assign
// 2 : GND
// 4 : +5V(Vcc) with 220ohm
// 5 : TX

USB Usb;
USBH_MIDI  Midi(&Usb);

void MIDI_poll();
void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime);

void setup()

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

void loop()
  uint32_t t1 = (uint32_t)micros();
  if ( Midi ) {
  doDelay(t1, (uint32_t)micros(), 1000);

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

  do {
    if ( (size = Midi.RecvData(outBuf)) > 0 ) {
      //MIDI Output
      _MIDI_SERIAL_PORT.write(outBuf, size);
  } while (size > 0);

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

  t3 = t2 - t1;
  if ( t3 < delayTime ) {
    delayMicroseconds(delayTime - t3);

Originally I thought perhaps baud rates are not matching. I noticed in the code there is the line


At first I wanted to change the serial monitor baud rate to 31250 but I quickly noticed that I can only select a few baud rates for the serial monitor and 31250 was not one of them. Also when i did change the baud rate of the serial monitor, I did not get any output.

Sorry for the lack of direction here, I’m mostly looking for either a fix for this example or a better solution altogether. Either way thank you for any help.

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