USB MIDI - not much info available

Status
Not open for further replies.

NuttyMonk

Well-known member
Hi all,

i am wanting to connect a small USB keyboard to a Teensy 3.2 which should only SEND data to the Teensy 3.2. No data needs to be sent to the keyboard. I can power the keyboard using my supply rails (+5V and Ground) but then the info needs to come from the keyboard to the Teensy and that is where i am getting into problems.

How is the data sent from the keyboard to the Teensy using USB? There are two data lines in the USB connector, D- and D+. Is the data sent down just one of the pins, the same as using the 5-pin DIN connector? If so, i can just wire up the USB in the same way as the 5-pin DIN then can't i? I am using the Nuts and Volts schematic for the 5-pin DIN connection to the Teensy 3.2.

https://www.notesandvolts.com/2015/02/midi-and-arduino-build-midi-input.html

Does the USB connection need to be made using BOTH the D- and D+ lines to the Teensy 3.2? If so, how does the code for that work?

I hope that for the uses i want it for, and because i am powering the keyboard using an external power supply, the Teensy doesn't need to be a USB host.

Any help would be appreciated

Cheers

NM
 
Thanks for your quick reply Paul.

So if i connect a USB MIDI device to the Teensy pins then i need the Teensy to have USB Host support? I can't just read the input from the USB MIDI connection like any other input? Why is USB Host support needed in this situation and not when using a 5-pin DIN connection?

Cheers

NM
 
USB has 3 roles: Host, Device, & Hub.

Typically the USB host is your PC or Mac, and USB devices are all the various peripherals you buy, including USB MIDI instruments & controllers.

USB devices can not communicate with each other. They only talk to a USB host. If you want to learn why, you can dive into the USB specs and learn the deep technical background about how USB really works. But the fact remains, this is simply the way USB was designed, and that design is why USB achieves such low cost for common devices which made it the huge commercial success.

USB just doesn't work like simple serial communication where you can connect an output signal to an input signal. USB has these specific roles, where communication is always between the 1 and only USB host and each USB device (or hub).

You can't directly connect 2 USB devices. You also can't directly connect 2 USB hosts. There must be exactly 1 host in a USB bus, and all communication is between that 1 host and each device.
 
To more specifically answer this question...

Why is USB Host support needed

Here is a copy of the USB 2.0 spec.

https://www.pjrc.com/teensy/beta/usb20.pdf

You can also get this at www.usb.org but it's buried inside a huge zip file with lots of other documents (like connector mechanical specs).

To understand the USB architecture, read chapter 4. This PDF is huge with lots of highly technical info, but chapter 4 is short and easy to read.

If you want to dive deeper, then read the couple dozen or so pages in chapter 5. Then it you *really* want to get into the nitty gritty, chapter 8 has the complete info about the various data tokes the host transmits and the devices reply, and how those tokens are exchanged in sequences to form the data transfers described in chapter 5.

If you connect 2 USB devices to each other, they will just forever sit there doing nothing. All USB communication (except remote wakeup) is initiated by the USB host transmitting tokens.
 
Thanks again Paul, detailed enough for me to understand why my assumptions were wrong.

So, assuming i have a Teensy with USB Host functionality, how do i connect the USB connector to the Teensy? I will be using other USB connectors than the one that is attached to the Teensy. Is it just a case of using two Rx/Tx pins to connect to the USB D-/D+ pins?

Cheers

NM
 
Like this: https://www.pjrc.com/store/cable_usb_host_t36.html

teensy41_usbhost2.jpg
 
I've just been checking over the pinouts for the 3.6, 4.0 and 4.1 and i can see D- and D+ pins there so i know where to connect to. The only final question i have is with regards to the 3.3v tolerance of the pins on those 3 boards. Will the D- and D+ pins be ok with a potential 5V coming into them from the USB port or do i need to attenuate the voltage before it gets to those pins if the data coming from the USB connector is 5V?

NM
 
Will the D- and D+ pins be ok

Yes, it will be ok.

with a potential 5V coming into them from the USB port or do i need to attenuate the voltage before it gets to those pins if the data coming from the USB connector is 5V?

USB doesn't use 5V on the signal wires.

As with most things USB, "it's complicated" and you can dive into the USB spec if you really want to know the finer details.

Also know the signal level are lower and very different if communicating at 480 Mbit versus only 12 Mbit speed.
 
If you use Teensy 4.0, know that you don't get the current limit switch and 100 uF capacitor which Teensy 3.6 & 4.1 have (unless you build your own), or you cut the VIN-VUSB pads apart and power Teensy 4.0 from a strong 5V power supply.

Without those parts, USB hot-plugging can cause a power drain which reboots Teensy 4.0. See section 7.2.4 on page 177 in the USB 2.0 spec for details.
 
Thanks very much for all of your help Paul.

I think i've decided on the Teensy 3.6 for this project and the USB Host cable. Will be easier to set up. I will just need to cut the VIN-VUSB pads apart to power the USB Host separately from the Teensy even though they will both be powered from 5V. That way i can still have the normal USB cable plugged in for debugging purposes using the serial port.

Cheers

NM
 
Status
Not open for further replies.
Back
Top