Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created August 23, 2022 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cowboy/f764ca1c6ce163f62f06fd0140c932c6 to your computer and use it in GitHub Desktop.
Save cowboy/f764ca1c6ce163f62f06fd0140c932c6 to your computer and use it in GitHub Desktop.
Teensy 4.1 USB MIDI issue: note on/off messages get dropped when enough keys are pressed/released simultaneously (MIDI controller connected to USB host port, PC running MIDI OX connected to micro USB port)
// 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());
}
@cowboy
Copy link
Author

cowboy commented Aug 23, 2022

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

Also posted to https://forum.pjrc.com/threads/70948-Teensy-4-1-USB-MIDI-issue-with-USB-HOST-port

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment