Teensy 4.1 USB MIDI issue with USB HOST port

cowboy

New member
I'm having a major problem with my Teensy 4.1. Random MIDI Note On and Off messages coming in on the USB HOST port are getting dropped. I've noticed this with occasional "stuck" notes (presumably because a Note Off message was dropped), but have only been able to reproduce it consistently by pressing and releasing a bunch of keys (10 seems to be the "sweet spot").

Steps to reproduce:

1. Solder a USB A female connector to a Teensy 4.1 USB HOST port
2. Connect a USB MIDI controller to that port (I'm using an Arturia Minilab Mk2)
3. Connect the micro USB port to a PC
4. Open this sketch in the Arduino IDE (I used 1.8.19) and upload the sketch
5. Run MIDI OX or other MIDI monitor software
6. Press 10 keys on the USB MIDI controller all at once
7. Check MIDI monitor software to verify that all 10 Note On messages were received
8. Release 10 keys on the USB MIDI controller all at once
9. Check MIDI monitor software to verify that all 10 Note Off messages were received
10. Repeat steps 6-9 until dropped messages are observed

Here's the sketch:

Code:
// Settings:
// Tools > Board = "Teensy 4.1"
// Tools > USB Type to "MIDI"

#include <USBHost_t36.h> // access to USB MIDI devices (plugged into 2nd USB port)

// Create the ports for USB devices plugged into Teensy's 2nd USB port (via hubs)
USBHost myusb;
USBHub hub1(myusb);
MIDIDevice midiDevice(myusb);

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWriteFast(LED_BUILTIN, HIGH);
  delay(100);
  digitalWriteFast(LED_BUILTIN, LOW);
  delay(100);
  digitalWriteFast(LED_BUILTIN, HIGH);
  delay(100);
  digitalWriteFast(LED_BUILTIN, LOW);

  myusb.begin();
}

void loop() {
  // Read messages arriving from the (up to) 4 USB devices plugged into the USB Host port
  while (midiDevice.read()) {
    uint8_t type =    midiDevice.getType();
    uint8_t data1 =   midiDevice.getData1();
    uint8_t data2 =   midiDevice.getData2();
    uint8_t channel = midiDevice.getChannel();
    usbMIDI.send(type, data1, data2, channel, 0);
  }

  // Read messages the PC (upstream host) sends and ignore them
  while (usbMIDI.read());
}

Thanks!
 
Back
Top