Teensy 3.1 (Multiple USB Device) Functionality?

Status
Not open for further replies.

balistreri.nick

Active member
Hello,

I am new to using the Teensy 3.1 and also the Arduino environment.

I would like to create a project that includes USB keyboard, and USB Serial
functionality.

I would like to have a selector SPDT switch to choose USB Keyboard mode or USB Serial mode.

How can I force the Teensy 3.1 to RESET and Re-enumerate a different USB device
when the SPDT switch position changes to a different USB mode?
 
I would like to create a project that includes USB keyboard, and USB Serial
functionality.

I would like to have a selector SPDT switch to choose USB Keyboard mode or USB Serial mode.

It's much easier to have Keyboard AND Serial than to have Keyboard OR Serial.

To get both at the same time, you'd edit usb_desc.h. There's comments near the top of the code to explain the process.

If you run into problems or get stuck, of course you can ask for help here. Please follow the "forum rule", and post clear screenshots of Linux "lsusb -v" output, or Mac system profiler, or Window device manager properties. We can try to help you if you post complete code and good details about what your PC is really seeing.


How can I force the Teensy 3.1 to RESET and Re-enumerate a different USB device
when the SPDT switch position changes to a different USB mode?

Probably the simplest way would involve turning off the USB peripheral. Then wait a brief time, to allow your PC to recognize it, and then write to the ARM AIRCR register to force the chip to reboot.

Reading the switch is pretty simple, but the USB code is really designed to enumerate as a single fixed function device. You'll need to hack the USB code quite a bit to make it give 2 different sets of descriptors, depending on the switch. At the very least, I'd recommend getting Keyboard AND Serial serial working first, and then use that as a starting point for trying to get Keyboard OR Serial to work.
 
Last edited:
Hi Paul,

Thank you for the help..
I'm new with this and still "green".

Just to make sure I understand..

So, the Teensy 3.1 enumerate USB keyboard "and" USB Serial at the same time so BOTH USB devices are ACTIVE within the operating system?
 
Just to make sure I understand..

So, the Teensy 3.1 enumerate USB keyboard "and" USB Serial at the same time so BOTH USB devices are ACTIVE within the operating system?

Yes, exactly.

Before you dig into USB code, set Tools > USB Type to "Serial + Keyboard + Mouse + Joystick". Then upload any sketch.

Teensy will become a 4-way composite device. All 4 work simultaneously.

If you want to trim away the mouse and joystick, you'll have to edit the USB code, since there isn't a "Serial + Keyboard" option in the menu.
 
WOW !!!!
That is THE COOLEST deal EVER !!!!

So, just t be clear, by selecting set Tools > USB Type to "Serial + Keyboard + Mouse + Joystick"
I can switch between these USB devices seamlessly ?

Send "HELLO" out as a USB Keyboard
then
Send "HELLO" out on a serial COM port
 
Hi Paul,

Ok, I know I'm pushing the envelope here, but regarding the USB TYPE setting, would I be
able to select the following USB devices to operating simultaneously?
SERIAL + KEYBOARD + MOUSE + MIDI + FLASH DRIVE
 
Send "HELLO" out as a USB Keyboard
then
Send "HELLO" out on a serial COM port

Yes. They work simultaneously.


Ok, I know I'm pushing the envelope here, but regarding the USB TYPE setting, would I be
able to select the following USB devices to operating simultaneously?
SERIAL + KEYBOARD + MOUSE + MIDI + FLASH DRIVE

"Flash drive" is complicated.

On Teensy 2.0, I made a first attempt at this. You can find it in the USB Type menu, when Teensy 2.0 is selected.

Internally, it uses MSC protocol. The problem with MSC is it works at the block level, so it's very difficult to share files and have awareness on the Teensy side of what the PC is doing. I made some initial attempt at locking layers and media management, but it's poor at best. Those functions are undocumented, and never will be documented, because it just never worked out great.

Later this year, I'm going to redo the disk drive stuff using MTP protocol, on Teensy 3.x and LC. That's still in the planning phase, but I have great hope that it will turn out much better than my early MSC-based attempt.
 
Hi Paul,

Ok, I knew the FLASH drive was asking for trouble :)
I would be OK with using a SPDT mode selector to toggle between thr FLASH drive and the other USB devices if that is do-able?
 
Hi Paul,

Just wanted to let you know I took your advice and got the multiple USB device test working..
I wanted to post it somewhere to help NEW users like me in the future.

Basically, I have (3) push buttons wired up and each button outputs to a different USB device.
Keyboard, Serial, and RIGHT-MOUSE click..

Not anything to write home about, but thought it would be helpful to post the DEMO project somewhere for NEW if you could point me to where and how?
 
If you have some time to put into it, a video on YouTube is usually the most effective way to show this sort of thing. Especially for people really familiar with Arduino's "everything is a serial port" paradigm, actually seeing and hearing talk as you do it can get the message across like no text+pictures page can.
 
Hi ...I'm pretty new to all this .... I was wondering if I can use usb midi and the usbkeyboard at the same time ...At the moment, I have usb midi code that triggers (in the arduino ide) 'you need to use type usbmidi device" and of course when I do that, it says my usb keyboard code needs the usb keyboard type ....Am I asking too much to expect a usbmidi / keyboard composite device??? I guess I could always go serial midi .... But can I change usb_desc.h and get there with a composite device??? would save me a bit of soldering time, and clean up my project box .... no need for nasty din plugs
 
HEYHEY, I changed usb_desc.h to insert code from the Keyboard interface into the 'MIDI' section, and low and behold I got a clean compile... have to see how things go hooking up to a host .... Great instructions in the usb_desc.h comments .... thanks
 
On my Linux system, it is located in:
Code:
${dir}/hardware/teensy/avr/cores/teensy3/usb_desc.h

Where ${dir} is the directory I installed the Teensy in.
 
Status
Not open for further replies.
Back
Top