I came across the USBHost_t36 library, but got tripped up a bit on getting it loaded into the Arduino IDE. So I'll have to take a closer look at that!
The USBHost_t36 library is a sure way to get midi-monitor running on the host connector.
If I were to connect the main USB port on the teensy to the USB A I have on my PCB, would usbMIDI still read a MIDI message sent by a MIDI instrument? like a simple MIDI keyboard?
Most likely not, your PCB would need to be usb class compliant (plug'n'play) using midi and understand the protocol. Pc's (windows, mac, linux) already contain drivers that are midi class compliant. That's the reason it is so easy to hook keyboards/DAWS/controllers to them and they get instantly recognised, they speak the same language
When I send a message from PC to the teensy via the main USB port, the teensy shows up as a device on my PC. Does that mean there are drivers my PC is using that a MIDI keyboard wouldn't have, since it's a peripheral?
Yes and no. Some keyboards have that option (usb and usb host port), but usually they work as a slave device using the USB Type B plug. The teensy can look just like any midi-keyboard (or audio card, HID, and many other peripherals). On the other hand, the usb host of teensy offers the driver the same as a PC. Once you use the correct objects the USB part will be powered and accepting class compliant keyboards, plug in a keyboard do the magic.
Code:
#include "USBHost_t36.h"
USBHost usbHost;
MIDIDevice midiDevice(usbHost);
void ControlChangeHandler(uint8_t channel, uint8_t cc, uint8_t value) {
// do stuff
}
void NoteOnHandler(uint8_t channel, uint8_t height, uint8_t velo) {
// more stuff to do
}
void setup() {
midiDevice.setHandleControlChange(ControlChangeHandler); // setup handlers
midiDevice.setHandleNoteOn(NoteOnHandler);//[...]
usbHost.begin();
// [...]
}
void loop() {
midiDevice.read(); // handlers will be called if data is available
}
Do you think it would be easier to simply connect the main USB port on the teensy to the USB A port on my PCB?
If you are out to monitor that kind of traffic (one device connected to the teensy) it is a good idea just to connect the midi device to the second USB and teensy hosts the midi device.
However, the same work can be done with a PC on its own and using i.e python-rtmidi to analyse/route all sorts of midi messages. The best infrastructure depends actually on your specific use case. Is it monitoring, is it exploring, grabbing sysex stuff, manipulating midi data, using teensy as synth, effects pedal, even displaying karaoke text etc.
HTH
Cheers