Created
August 23, 2022 04:36
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
Also posted to https://forum.pjrc.com/threads/70948-Teensy-4-1-USB-MIDI-issue-with-USB-HOST-port