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

Thread: Teensy 3.1 (Multiple USB Device) Functionality?

  1. #1

    Teensy 3.1 (Multiple USB Device) Functionality?

    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?

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,929
    Quote Originally Posted by balistreri.nick View Post
    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 by PaulStoffregen; 05-27-2015 at 04:10 PM.

  3. #3
    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?

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,929
    Quote Originally Posted by balistreri.nick View Post
    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.

  5. #5
    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

  6. #6
    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

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,929
    Quote Originally Posted by balistreri.nick View Post
    Send "HELLO" out as a USB Keyboard
    then
    Send "HELLO" out on a serial COM port
    Yes. They work simultaneously.


    Quote Originally Posted by balistreri.nick View Post
    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.

  8. #8
    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?

  9. #9
    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?

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,929
    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.

  11. #11
    Senior Member adrian's Avatar
    Join Date
    Oct 2015
    Location
    Wellington, NZ
    Posts
    504
    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

  12. #12
    Senior Member adrian's Avatar
    Join Date
    Oct 2015
    Location
    Wellington, NZ
    Posts
    504
    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

  13. #13
    Senior Member adrian's Avatar
    Join Date
    Oct 2015
    Location
    Wellington, NZ
    Posts
    504
    Works perfect...

  14. #14
    Junior Member
    Join Date
    Mar 2013
    Posts
    9
    Excuse sirs, I'm interested in usb_desc.h but I can't find it. Would anybody mind to point me, please?

  15. #15
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    2,952
    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.

Posting Permissions

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