Teensy 4.1 - how many USB ports w/o hub?

b2020

Member
I asked about a Teensy-based HID-over-UDP solution a while back
https://forum.pjrc.com/threads/60638-Wanted-one-way-HID-over-UDP-IP-solution

Teensy 4.1
* has UDP/IP
* can act as a USB host and USB device at the same time
give or take getting the adapters and SDK issues pending.

I see mention that, due to being able to run as USB host, a hub could be used to attach more devices.
I can't use a hub for various reasons.

T41 covers my main use case out of the box:
* UDP in
* T41 acts as USB host sending Raw HID to attached device
* on-board USB for debug/dev PC connection


My future extension is:
* UDP in
* T41 acts as USB host polling attached HID device
* T41 acts as USB HID input device being polled by another host (onboard USB)

But another serial interface acting as COM for debug/dev PC and IDE would be nice.
Question 1: what's the best option for getting COM over any other I/O not in use?

Finally, I have an auxiliary use case:
* T41 acts as USB host polling attached HID device
* T41 acts as USB HID input device being polled by a host
* T41 acts as USB Raw HID device receiving from same host
* UDP would be really handy

Question 2: how do I get the 3rd USB connection?
- can I re-use the Ethernet somehow?
- should I use whatever serial I/O I found to use as COM w/ dev/debug PC?
- can I find another (4th) serial connection I could use instead/as COM?
If all fails, Printf Debug over UDP is an option

tl;dr: is it possible to add 1-2 more USB ports to the Teensy 4.1, for a total of 3-4 ?
 
The thing about USB is you can have many interfaces running down the same cable. Look at the "USB Type" menu in the Arduino IDE when you have a Teensy selected. You can have Serial + Mouse + Joystick and many other combinations. So if all of those things you mentioned are going to one PC host then you're done.

You've never seen two PCs plugged into a hub together have you? It's really rare because they can't both be hosts. If you need to send the same (or different) data into two hosts then you've already started the work on making UDP to USB. One Teensy per host feeds it the data it needs from the network.

Now if the Teensy is hosting many devices, then you must have a hub. For example the flight simulator I'm working on right now will probably have a joystick and pedals plugged into the Teensy, which then sends modified data to the simulator PC. That uses a hub for the two off-the-shelf USB devices.
 
On the USB device port, you click the Tools > USB Type menu in Arduino to select the combination of interface you want.

sc.png

You can also edit usb_desc.h to create other combinations of these interfaces. So if you want RawHID + Serial, you certainly can get that by editing the header file.

On the USB host port, you use the USBHost_t36 library. In your program, you create instances of its drivers. When a USB device with more than 1 supported interface is plugged in, those driver instances will take control of each interface. So if you have a USB device that is both HID (compatible with the library's several HID drivers) and Serial, you can plug it into Teensy 4.1's USB host port and use its multiple interfaces, pretty much the same way you can on a PC.

But physically speaking, Teensy 4.1 has only 2 USB ports. While both are capable of either device or host mode, the software only supports device mode on the 1st port and only host mode on the 2nd port.

If you have 1 physical device with all the interfaces, then this should work. But if you want to connect more than 1 physical USB device to the host port, you need a hub. The host port is only 1 physical USB port. If you absolutely can't use a hub (for whatever reasons I don't understand) then the only way for the multiple types of communication is if the 1 device you connect has all the interface you need.

But if you are looking for actual serial communication, you might also consider Teensy 4.1 has 8 hardware serial ports with 3.3V TTL level signals. Those are all fully independent from the USB.
 
But if you want to connect more than 1 physical USB device to the host port, you need a hub. The host port is only 1 physical USB port. If you absolutely can't use a hub (for whatever reasons I don't understand) then the only way for the multiple types of communication is if the 1 device you connect has all the interface you need.

Thanks for the detailed reply!

Yep, up to 3 concurrent physical USB connections, several use cases, e.g.
- T41 attached to target host, plus to 2 devices attached to T41-as-host
- T41 attached to target host *twice*, plus one device attached to T41-as-host
That's assuming dev/debug PC can be attached over non-USB serial (even for sketch upload).
Yes, connected as two different devices (two different PID/VID) to the same host, one I cannot modify.
Not clear whether target host permits whatever composite/TLC you and MorganS have in mind - I'd rather not depend on that.

I don't really want to use a 3rd party hub, because I might have to deploy a few hundred of these at locations w/o convenient maintenance.
The closer I can get to a black box off-the-shelf fixed function solution, the better. I'll juggle too many cables and power supplies as it is.

My ideal Arduino MCU hardware would come factory-equipped with RJ45 and at least 3 USB connectors on board.
Not a common config - more what I see w/ RPi-type parts that also have video output.

Once the per-seat cost gets high enough, I might just as well consider something like this
https://www.udoo.org/docs-x86II/Introduction/Introduction.html

Barring that, I'd like to cut it down to something like
Teensy 4.1 + custom made-to-order shield
or
Custom made-to-order carrier PCB + multiple 4.1

Without an all-in-one solution, I'd need a custom PCB anyway.
Would it be reasonable to try and add a hub to that?
Borrowing wiring from e.g.
https://www.retrocution.com/2020/01/15/easy-diy-tiny-usb-hub-for-raspberry-pi-projects/
https://oshpark.com/shared_projects/cQOybiUe
https://github.com/felis/USB_Host_Shield_2.0/blob/master/usbhub.h
after using the off-the-shelf for a proof of concept?

I saw in other threads that neither the Teensy 4.1 RJ45 nor its USB Host connector can work with a shield?
Cable connectors will always have to be used?

Thanks again!

p.s.:
But if you are looking for actual serial communication, you might also consider Teensy 4.1 has 8 hardware serial ports with 3.3V TTL level signals. Those are all fully independent from the USB.

I separated the serial inquiry out to
https://forum.pjrc.com/threads/60915-Debug-and-sketch-upload-over-serial-UART

Basically, I am hoping I can use one of the non-USB serials to connect PC host for debug and sketch upload.
 
My ideal Arduino MCU hardware would come factory-equipped with RJ45 and at least 3 USB connectors on board.

You might be waiting a while for that hardware! While that's common in the SBC world like Raspberry Pi, most microcontrollers have only 1 physical USB port. The chip we're using on Teensy 4.0 & 4.1, probably the most powerful off-the-shelf microcontroller on the market today, has 2 of them. So do several similar high-end chips from ST. Maybe someone makes a microcontroller with more physical USB ports, but I have not see such a chip.
 
Yeah, this

https://store.arduino.cc/usa/arduino-yun

was the closest product I have found so far, so the Teensy 4.1 is just-in-time and very welcome!

So breakout / shield for RJ45+Host USB (or carrier PCB for several T41) it will have to be.

I must have misread / misremembered
https://forum.pjrc.com/threads/60846-T4-1-Ethernet-board
and the 4.1 beta thread - on 2nd pass I can't find anything indicating that RJ45 and USB host couldn't be put directly on a single breakout with the necessary components, matching the T4.1 holes including 5-pin USB and 6-pin Ethernet blocks.
 
Last edited:
I don't see the problem then...

You can have several USB interfaces on both USB ports. HID+Serial+Keyboard+Joystick+Mouse... whatever you want.

On the host side of the Teensy, if you're plugging in off-the-shelf devices like a keyboard and a mouse then you need a hub, because you can't just cut the cords and splice the wires together. If space is the problem then it must be possible to put a hub chip on a PCB that's no bigger than the connector.

I'm not exactly sure when it appeared but the latest TeensyDuino that I'm using does let me have more than one Serial interface to the PC. I'm on 1.52 Beta 4.
 
If space is the problem then it must be possible to put a hub chip on a PCB that's no bigger than the connector.

Space is not the problem.
The problem I started with was having to use separate hub boxes etc. or a custom shield/breakout in the first place.

I am basically trying to make sure there is no off-the-shelf MCU, and no off-the-shelf shield for an existing MCU, that could be used.
Once I accept there has to be custom hardware combined with off-the-shelf, sure, a lot becomes possible.
Which is where I am now.

Now I am basically settling on open-source parts I can buy off-the-shelf to put together proof-of-concept builds, which I can also hope to get combined into a single shield for (limited run) scale.
 
But if you want to connect more than 1 physical USB device to the host port, you need a hub.
[..] you might also consider Teensy 4.1 has 8 hardware serial ports


How about connecting the Teensy 4.1 device to more than 1 Host?

Similar to a protocol analyzer:

Code:
Host - Teensy4.1 - Device
               |
          Analyzer

Two hosts, two physical connections, plus one device with the 3rd physical connection.

Teensy 4.1 has 2 out of 3. Use one of the other hardware serial ports to attach a serial-to-USB part? Any off-the-shelf recommendation?
 
Back
Top