Teensy 3.6 USB Host support

Whee

New member
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/k66_usbhost/blob/master/k66_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/adk2.html#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.
 
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.
 
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 :)
 
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.
 
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?
 
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
 
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.
 
Touchscreen running on BUYDISPLAY 1°.1" but not on FLATRON T1710

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 ?
------------------------------------
 
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 a moderator:
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.
 
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
 
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.
 
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.
 
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.
 
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.
 
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
 
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.
 
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 :D

seven-week-christmas.jpg
 
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.
 
Back
Top