Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Receive MIDI via USB Host Pads?

  1. #1
    Junior Member
    Join Date
    Jun 2020
    Posts
    14

    Receive MIDI via USB Host Pads?

    Hi Folks,

    Am I mistaken in thinking that the USB Host pads on the bottom of a teensy (4.0 in my case) is where usbMIDI.read() looks?

    One mechanic of the project I'm working in is for my device to act as a USB host and display the MIDI message that the peripheral MIDI device outputs. The D+/D- pads are connected to a USB A connector via a PCB. Is there a better way of doing this? Am I completely misunderstanding the role of USB host/peripheral when it comes to MIDI?

    Any insight would be most appreciated!

    Thanks!

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,207
    Quote Originally Posted by MIDIMinion View Post
    Am I mistaken in thinking that the USB Host pads on the bottom of a teensy (4.0 in my case) is where usbMIDI.read() looks?
    Yes, that's a mistaken understanding. usbMIDI.read() tries to receive whatever messages your PC has sent over the normal USB connection.

    To use the 2nd USB port, you would use the USBHost_t36 library.


    Am I completely misunderstanding the role of USB host/peripheral when it comes to MIDI?
    Sounds like you're close. The main thing to know is "usbMIDI" accesses the main USB port running in device mode. The most common use is to send MIDI messages to your PC, but it can work in ether direction. Your PC can send MIDI messages, which you receive with usbMIDI.read() or the callback functions.

    Everything about the host port is done with the USBHost_t36. Again, there is a most common use where Teensy receives messages from USB MIDI instruments. But like the device port, MIDI messages can flow in both directions. For example, if you connect a Novation Launchpad to the USB host port, you can receive the messages as the buttons are touched AND you can transmit messages to change the color of the buttons.

    Click image for larger version. 

Name:	novation_launchpad_mk2_live_kontroller-768x510.jpg 
Views:	63 
Size:	54.5 KB 
ID:	21474

    Even though 1 direction of data flow is the most common (from device to host), USB MIDI supports messages in both directions. Both USBHost_t36 and usbMIDI allow bidirectional dara flow. Just keep this image in your mind and remember the launchpad sends MIDI as you play, but also receives MIDI so you can control the color of every button as it is used. Most instruments like MIDI keyboards only transmit messages as you play, but some devices do receive messages too.

  3. #3
    Junior Member
    Join Date
    Jun 2020
    Posts
    14
    Thanks for the info! 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!

    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? 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?

    My device is a tester for all things MIDI, I've got the DIN5 messages squared away, as well as usbMIDI via the main USB port on the teensy (when the message comes from my PC).

    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?

    Thanks again for the help!

  4. #4
    Junior Member
    Join Date
    Sep 2018
    Posts
    13
    Quote Originally Posted by MIDIMinion View Post
    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
    Last edited by scjurgen; 08-26-2020 at 05:50 PM. Reason: code added, cleanup

  5. #5
    Junior Member
    Join Date
    Jun 2020
    Posts
    14
    Wow, so much great info here. Thanks for the help everyone! I think I'll poke around USBHost-t36!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •