Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 2 1 2 LastLast
Results 1 to 25 of 29

Thread: Teensy 3.6 USB Host support

  1. #1
    Junior Member
    Join Date
    Oct 2016
    Posts
    1

    Teensy 3.6 USB Host support

    I'm keen to make Teensy 3.6 have ADK support. Looking through the current library support, looks like USB host is not supported on the device, though Paul has uploaded some code pointing to how USB Host mode would be supported:

    https://github.com/PaulStoffregen/k6...66_usbhost.ino

    Does anyone else have an interest in USB host support?



    In theory, ADK on Teensy 3.6 should be similar to the original ADK2. The ADK2 ran on Arduino Due, which was 32 bit arm. The source is available at repo and I'm looking through the usb-specific code to port it over:
    https://developer.android.com/adk/ad...l#src-download


    With the demise of Arduino Due (ADK 2 support) and the Arduino ADK Mega (ADK1 support), I'm eager to get Teensy 3.6 to be the canonical board for Arduino ADK support.

  2. #2
    Junior Member
    Join Date
    Oct 2016
    Posts
    1
    I would like to second this motion!

    I'm in the process of moving a project from a Due to a Teensy3.6, and the USB host support is the only thing I'm missing. Ideally, I'd like to ditch the Due as soon as possible.

    So, I'm curious if there is a time frame for getting the USB host working on 3.6.

  3. #3
    Quote Originally Posted by Whee View Post
    Does anyone else have an interest in USB host support?
    Yes. That's one of the reasons I choose the 3.6.

    But I'm prepared to wait for a while, because I think Paul is a busy man right now.

  4. #4
    Junior Member
    Join Date
    Oct 2016
    Posts
    3
    I'm also looking for USB host mode for one of my projects...

    Have you found this thread:
    https://forum.pjrc.com/threads/28173...ighlight=uhs30

  5. #5
    Senior Member johnnyfp's Avatar
    Join Date
    Jan 2014
    Location
    New Zealand
    Posts
    260
    Note, as it stands the UHS30 library doesn't support the 3.6's Second USB port. Only the main USB port.
    I am currently playing around with trying to get it working on the Second port, but looks like most of the naming and registries entries are very different from the first port. Maybe xxxajk will beat me too it

  6. #6
    Quote Originally Posted by Whee View Post
    I'm keen to make Teensy 3.6 have ADK support.

    Does anyone else have an interest in USB host support?
    This is also one of the reasons for my interest in the 3.6. It would open up many new possible applications for the Teensy.

  7. #7
    So, what is the status of USB host mode on the Teensy 3.6?
    I am hoping to use it as a MIDI host. But is it working?

  8. #8
    Just found this library:

    https://github.com/PaulStoffregen/USBHost_t36

    So status is: usbmidi read works and usbmidi write is still a work in progress.

  9. #9
    Member
    Join Date
    Feb 2015
    Location
    Rians in Provence, France
    Posts
    47
    Hi all,

    I am planning to use the USB Host port on TEENSY 3.6 for X Y coordinates inputs from a USB Touchscreen.
    Does anyone has some programming example ?
    Thanks for your help,
    Pascal

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,683
    Quote Originally Posted by LERAY View Post
    I am planning to use the USB Host port on TEENSY 3.6 for X Y coordinates inputs from a USB Touchscreen.
    Does anyone has some programming example ?
    The good news is the library has a full HID parser, so at least you don't need to decode raw HID reports.

    The bad news is there's currently no touchscreen driver in the library. So you'd need to write that. At least the HID parser can deliver the HID fields conveniently decoded with HID usage identified. The mouser driver is probably a good place to start.

    Everything is defined in one big USBHost_t36 header, so start by reading that header and skip past all the low-level stuff. Drivers inherit from the USBHIDInput base class if they're going to let the HID parser do the work of receiving reports from the device. The 5 protected virtual functions are the things you need to implement. The HID parser will call those functions when things happen. You can also inherit USBDriver if you want to talk more directly with the USB device. But for a HID-only device, things are much simpler if you can use only USBHIDInput.

    You job in the crafting of a driver is to take that data you get when the rest of the library calls your 5 functions and turn it into useful stuff for your program to use. The mouse driver is pretty simple. It just stores the data into variables and provides functions the Arduino sketch can use the read them, and uses 1 boolean to implement available() so the sketch can know if the mouse has sent new info.

  11. #11
    Member
    Join Date
    Feb 2015
    Location
    Rians in Provence, France
    Posts
    47

    Touchscreen running on BUYDISPLAY 1.1" but not on FLATRON T1710

    Quote Originally Posted by PaulStoffregen View Post
    The good news is the library has a full HID parser, so at least you don't need to decode raw HID reports.

    The bad news is there's currently no touchscreen driver in the library. So you'd need to write that. At least the HID parser can deliver the HID fields conveniently decoded with HID usage identified. The mouser driver is probably a good place to start.

    Everything is defined in one big USBHost_t36 header, so start by reading that header and skip past all the low-level stuff. Drivers inherit from the USBHIDInput base class if they're going to let the HID parser do the work of receiving reports from the device. The 5 protected virtual functions are the things you need to implement. The HID parser will call those functions when things happen. You can also inherit USBDriver if you want to talk more directly with the USB device. But for a HID-only device, things are much simpler if you can use only USBHIDInput.

    You job in the crafting of a driver is to take that data you get when the rest of the library calls your 5 functions and turn it into useful stuff for your program to use. The mouse driver is pretty simple. It just stores the data into variables and provides functions the Arduino sketch can use the read them, and uses 1 boolean to implement available() so the sketch can know if the mouse has sent new info.
    ------------------------------------
    Thanks a lot for your message !
    The Touchscreen is running fine with the example program "Mouse". It runs as well with a real mouse or with the 10.1" Touchscreen from BuyDisplay
    But don't runs on an LG FLATRON Touchscreen T1710 1280x1024.
    I don't know why ?
    ------------------------------------

  12. #12
    Junior Member
    Join Date
    Dec 2016
    Posts
    10

    Problem using USBHost_t36

    Hi all,
    I am trying to use the library "USBHost_t36" of PaulStoffregen to connect to the teensy 3.6 a mouse and a keyboard to USB1 with the following scheme:

    +-----+ <----- mouse
    teensy 3.6 USB1 -----> | hub |
    +-----+ <----- keyboard

    The software used is:
    ---------------------------------------------------------------
    Code:
    #include <USBHost_t36.h>
    
    USBHost            myusb;
    USBHub             hub1(myusb);
    MouseController    mouse1(myusb);
    KeyboardController keyboard1(myusb);
    
    void setup() {
    	Serial.begin(230400);
    	while (!Serial); 
    	Serial.println("USB Host Testing");
    	Serial.println(sizeof(USBHub), DEC);
    	myusb.begin();
    	keyboard1.attachPress(OnPress);
    }
    
    void loop() {
    	myusb.Task();
    	if (mouse1.available()) {
            Serial.print("Mouse: buttons = ");
            Serial.print(mouse1.getButtons());
            Serial.print(",  mouseX = ");
            Serial.print(mouse1.getMouseX());
            Serial.print(",  mouseY = ");
            Serial.print(mouse1.getMouseY());
            Serial.print(",  wheel = ");
            Serial.print(mouse1.getWheel());
            Serial.print(",  wheelH = ");
            Serial.print(mouse1.getWheelH());
            Serial.println();
            mouse1.mouseDataClear();
        }
    }
    
    void OnPress(int key) {
    	Serial.print("key '");
    	Serial.print((char)key);
    	Serial.print("'  ");
    	Serial.println(key);
    }
    ------------------------------------------------------------------
    But it's not working.
    Could anyone help me?
    Thanks in advance
    Dun46
    Last edited by defragster; 12-02-2018 at 09:24 PM. Reason: add # CODE tag

  13. #13
    Junior Member
    Join Date
    Aug 2017
    Posts
    19
    Hi dun46,

    Add these to your sketch:

    Add
    USBHIDParser hid1(myusb);
    If you are using a wireless keyboard/mouse combo then
    add USBHub hub2(myusb);

    If you are using Arduino 1.87 and Teensyduino 1.44 and a wireless mouse combo there is a problem with keyboard.cpp.
    The mouse probably will not work properly.

    In arduino-1.8.7/hardware/teensy/avr/libraries/USBHost_t36/keyboard.cpp I commented out the following lines in keyboard.cpp
    to make it work with both a wireless keyboard/mouse combo and wired keyboard and mouse:
    Line 142 // mk_setup(setup, 0x21, 11, 0, 0, 0); // 11=SET_PROTOCOL BOOT
    Line 143 // queue_Control_Transfer(dev, &setup, NULL, this);
    It seems to have something to do with the Gigabyte keyboard patch.
    If you are using a wired keyboard and mouse there should not be a problem.
    I am curious to see if others had this problem.
    Your sketch with these modifications worked for me.

  14. #14
    Member
    Join Date
    Feb 2015
    Location
    Rians in Provence, France
    Posts
    47
    Hi all,
    I tried with an example. Complex, but can be largely simplified.
    Runs on a BUYDISPLAY screen but not on a FLATRON Touchscreen
    Runs with mouse anyway.
    You can download it here :
    http://pascal.leray.free.fr/downloads/TOUCHSCREEN.zip

  15. #15
    Junior Member
    Join Date
    Dec 2016
    Posts
    10
    Hello wwatson,
    I have added the line that you suggested:
    -------------------------------------------------- ------------------------------
    #include <Arduino.h>
    #include <USBHost_t36.h>

    USBHost myusb;
    USBHub hub1(myusb);
    USBHIDParser hid1(myusb);
    MouseController mouse1(myusb);
    KeyboardController keyboard1(myusb);

    void setup() {
    while (!Serial);
    Serial.println("USB Host Testing");
    Serial.println(sizeof(USBHub), DEC);
    myusb.begin();
    keyboard1.attachPress(OnPress);
    }

    void loop() {
    myusb.Task();
    if (mouse1.available()) {
    Serial.print("Mouse: buttons = ");
    Serial.print(mouse1.getButtons());
    Serial.print(", mouseX = ");
    Serial.print(mouse1.getMouseX());
    Serial.print(", mouseY = ");
    Serial.print(mouse1.getMouseY());
    Serial.print(", wheel = ");
    Serial.print(mouse1.getWheel());
    Serial.print(", wheelH = ");
    Serial.print(mouse1.getWheelH());
    Serial.println();
    mouse1.mouseDataClear();
    }
    }

    void OnPress(int key) {
    Serial.print("key '");
    Serial.print((char)key);
    Serial.print("' ");
    Serial.println(key);
    }
    -------------------------------------------------- ---------------------------
    But it still does not work.
    I've also tried the library examples and they do not work for me.
    I am using the following configuration:
    Teensy 3.6 -----> Hub <----- mouse + keyboard
    with cables (not combo).
    Hub (Belkin model) 4 USB connectors.
    Mouse (Belkin model) 3 wheels with cable.
    Normal keyboard with cable.
    what am I doing wrong.
    Thank you very much for your answer.
    dun46

  16. #16
    Junior Member
    Join Date
    Aug 2017
    Posts
    19
    Hi dun46,

    Please try this code. I have added "USBHub hub2(myusb);" to it.
    In my previous post I stated:
    "If you are using a wireless keyboard/mouse combo then add USBHub hub2(myusb); ".
    It should have been:
    "If you are NOT using a wireless keyboard/mouse combo then add USBHub hub2(myusb);"

    Here is your code with the added line.
    Code:
    #include <USBHost_t36.h>
    
    USBHost            myusb;
    USBHub             hub1(myusb);
    USBHub             hub2(myusb);
    MouseController    mouse1(myusb);
    KeyboardController keyboard1(myusb);
    USBHIDParser hid1(myusb);
    
    void setup() {
      Serial.begin(230400);
      while (!Serial); 
      Serial.println("USB Host Testing");
      Serial.println(sizeof(USBHub), DEC);
      myusb.begin();
      keyboard1.attachPress(OnPress);
    }
    
    void loop() {
      myusb.Task();
      if (mouse1.available()) {
            Serial.print("Mouse: buttons = ");
            Serial.print(mouse1.getButtons());
            Serial.print(",  mouseX = ");
            Serial.print(mouse1.getMouseX());
            Serial.print(",  mouseY = ");
            Serial.print(mouse1.getMouseY());
            Serial.print(",  wheel = ");
            Serial.print(mouse1.getWheel());
            Serial.print(",  wheelH = ");
            Serial.print(mouse1.getWheelH());
            Serial.println();
            mouse1.mouseDataClear();
        }
    }
    
    void OnPress(int key) {
      Serial.print("key '");
      Serial.print((char)key);
      Serial.print("'  ");
      Serial.println(key);
    }
    Please try it.

    A couple of questions.
    1. What OS are you using?
    2. What version of Arduino are you using?
    3 What version of teensyduino are you using?
    4. What is not working, the keyboard, the mouse or both?

    if you are using Arduino 1.87 and Teensyduino 1.44 the mouse probably will not work properly until
    the two lines 142 and 143 are commented out. This does not seem to affect the keyboard from functioning.

    I have a Belkin mouse as well and it also works.

    Hopefully this helps.

  17. #17
    Junior Member
    Join Date
    Dec 2016
    Posts
    10
    Hello wwatson,
    I have tested your code and it still does not work.
    I have also commented lines 142 and 143 of keyboard.cpp.
    1) My OS is Windows 10.
    2) Version of Arduino 1.8.7
    3) Version of Tennsy 1.44
    4) neither of them work.
    I am using the Teensy USB1 ---> Hub <--- and the Hub connect to mouse and keyboard.
    Is this configuration correct?
    Thank you very much for your help.

  18. #18
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    3,701
    My guess is you probably need 2 or 3 HID objects, as most Keyboards and mice are HID objects... Some actually define multiple HIDS, one for default, some for extended...

    Again without knowing exactly what keyboard and what mice you have it sometimes is hard to know, what is going on. Did you try the Example Mouse.ino and did it work? That would at least let us know if your hardware is properly supported. Things like maybe your HUB is not working. Or maybe your keyboard has a HUB built in, which is using up your hub...

    When I start debugging any of these USB Host issues. I first will go into the file USBHost_t36.h and un comment the define: //#define USBHOST_PRINT_DEBUG
    This helps print out lots of debug information.

    Some of the files may also have some commented out (Or I may have removed them)... But first see what this prints out.

  19. #19
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,066
    A first analytic step could be plugging the questionable mice and keyboards to windows one after the other and note what the device manager reports in detail.

  20. #20
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    3,701
    Forgot to mention: If you use the Mouse.ino example program with your hardware and it works.
    It tries to show you which devices are used for your hardware. It will give a connected message for each one of these with a textual name, plus try to show vendor and product information. You should be able to then deduce from this how many HUB and HID devices are needed...

    But again that assume your hardware works with this example

  21. #21
    Junior Member
    Join Date
    Dec 2016
    Posts
    10
    Hello KurtE,
    I have activated the statement #define USBHOST_PRINT_DEBUG
    and I tried the Mouse.ino example and the Serial print returns me:
    ----------------------------------------------------------------------------------
    USB Host Testing
    960
    sizeof Device = 36
    sizeof Pipe = 96
    sizeof Transfer = 64
    power up USBHS PHY
    port change: 14001403
    connect
    begin reset
    port change: 14001005
    port enabled
    end recovery
    new_Device: 1.5 Mbit / sec
    new_Pipe
    ---------------------------------------------------------------------------------
    The Hub is from the Belkin brand
    the Mouse is from the brand Belkin
    the keyboard is of the Bluesky brand

    Thank you very much for your help.

  22. #22
    Junior Member
    Join Date
    Dec 2016
    Posts
    10
    Hi KurtE,
    the Mouse.ino no work for me.
    Thank out very much

  23. #23
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    3,701
    My first guess is it is not liking your USB HUB.

    You might try a couple of other tests, like, does either of the mouse or keyboard work if you plug them in directly without the HUB?

    So it is a belkin HUB, do you know which one? Is it a current one? i.e. if I or Paul wanted to order one from some place like Amazon can we get them...

    Some of the HUB stuff is a little tricky for me to test as I don't have USB scope, but can see some stuff with Logic Analyzer. I do know that Paul fixed some issues associated with some other HUB, I believe it was for this current release.

    If I get a chance, I will try to take a look, although right now, busy with handling new puppy

    Click image for larger version. 

Name:	seven-week-christmas.jpg 
Views:	3 
Size:	128.2 KB 
ID:	15282

  24. #24
    Junior Member
    Join Date
    Dec 2016
    Posts
    10
    Hello KurtE,
    I connected the mouse directly to the USB1 port of the Teensy 3.6 and it still does not work.
    I send you the printed trace:
    --------------------------------------------------------------------------------------------------
    USB Host Testing
    960
    sizeof Device = 36
    sizeof Pipe = 96
    sizeof Transfer = 64
    power up USBHS PHY
    port change: 10001803
    connect
    port change: 1C001002
    disconnect
    port change: 10001803
    connect
    port change: 1C001002
    disconnect
    port change: 10001803
    connect
    port change: 1C001002
    disconnect
    port change: 10001803
    connect
    port change: 1C001002
    disconnect
    port change: 10001803
    connect
    port change: 1C001002
    disconnect
    port change: 10001803
    connect
    port change: 1C001002
    disconnect
    port change: 10001803
    connect
    begin reset
    port change: 10001005
    port enabled
    end recovery
    new_Device: 12 Mbit/sec
    new_Pipe
    port change: 1C00100A
    disconnect
    disconnect_Device:
    USBDriver (available_drivers) list: 1FFF22A0 -> 1FFF2660 -> 1FFF2020 -> 1FFF2A40
    USBDriver (dev->drivers) list: (empty
    USBDriver (available_drivers) list: 1FFF22A0 -> 1FFF2660 -> 1FFF2020 -> 1FFF2A40
    delete_Pipe 1FFF3400
    shut down async schedule
    Free transfers
    * 536819008 * remove * free
    * 536818816
    * 536818880 * remove * defer free until QH
    Free transfers attached to QH
    * 536818816
    * 536818880
    * 536818944
    * Delete Pipe completed
    removed Device_t from devlist
    disable
    port change: 10001803
    connect
    port change: 1C001002
    disconnect
    port change: 10001803
    connect
    port change: 1C001002
    disconnect
    port change: 10001803
    connect
    port change: 1C001002
    disconnect
    port change: 10001803
    connect
    port change: 1C001002
    disconnect
    port change: 10001803
    connect
    port change: 1C001002
    disconnect
    port change: 10001803
    connect
    port change: 1C001002
    disconnect
    port change: 10001803
    connect
    begin reset
    port change: 10001005
    port enabled
    end recovery
    new_Device: 12 Mbit/sec
    new_Pipe
    port change: 1C00100A
    disconnect
    disconnect_Device:
    USBDriver (available_drivers) list: 1FFF22A0 -> 1FFF2660 -> 1FFF2020 -> 1FFF2A40
    USBDriver (dev->drivers) list: (empty
    USBDriver (available_drivers) list: 1FFF22A0 -> 1FFF2660 -> 1FFF2020 -> 1FFF2A40
    delete_Pipe 1FFF3400
    shut down async schedule
    Free transfers
    * 536818816 * remove * defer free until QH
    * 536818944 * remove * free
    * 536819008 * remove * defer free until QH
    * 536819008 * remove * defer free until QH
    * 536819008 * remove * defer free until QH
    * 536819008 * remove * defer free until QH
    * 536819008 * remove * defer free until QH
    etc
    rest of lines the same as the previous

    ---------------------------------------------------------------------------------------------------
    Thank you very much for your help.

  25. #25
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,683
    I ran the program from msg #16 on a Teensy 3.6. With a regular USB mouse, it seems to work fine.

    Click image for larger version. 

Name:	mouse.png 
Views:	9 
Size:	56.5 KB 
ID:	15284

Posting Permissions

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