The USB Host feature is not working on my Teensy 4.1 board.

Hey folks,
I'm attempting to connect a keyboard to my teensy 4.1, but it doesn't seem to recognize it for some reason.

To begin, I'm quite certain that I connected the GND, +5V, D-, and D+ pins correctly (I even attempted inverting D- and D+ just in case).

And I'm running my tests with the code below.
Code:
#include "Arduino.h"
#include "USBHost_t36.h"

USBHost host;
KeyboardController keyboard(host);

void setup() {
    Serial.begin(115200);

    while (!Serial);

    USBHost::begin();

    keyboard.attachPress([](int key) {
        Serial.print("Pressed ");
        Serial.println((char) key);
    });
}

void loop() {
    USBHost::Task();

    delay(1000);
}

I also uncommented the following in order to display debug information.

Code:
#define USBHOST_PRINT_DEBUG

Anyway, when I run the program, I get this at first:

Code:
USB2 PLL running
 reset waited 6
USBHS_ASYNCLISTADDR = 0
USBHS_PERIODICLISTBASE = 20003000
periodictable = 20003000

Then when I connect the keyboard, the following shows up:

Code:
port change: 10001803
    connect
  begin reset
port change: 10001005
  port enabled
  end recovery
new_Device: 12 Mbit/sec
new_Pipe

And that's pretty much it. (To be honest I'm not sure what to expect in the debug logs, so maybe its totally normal)

I tried running the HIDDeviceInfo example to check if it was just me misusing the library, but it too doesn't find any devices (I tried a lot of different usb devices btw, ranging from usb sticks, keyboards, mouses, etc..)
 
Looking at USBHost example: {local install}\hardware\teensy\avr\libraries\USBHost_t36\examples\KeyboardForeward\KeyboardForeward.ino

Plugging in a keyboard to USB Host pins works as a good example perhaps:
Code:
USB Host Testing
960
*** Device KB 46d:c31c - connected ***
  manufacturer: Logitech
  product: USB Keyboard
*** Device HID1 46d:c31c - connected ***
  manufacturer: Logitech
  product: USB Keyboard
key 'a'  97 MOD: 0 OEM: 4 LEDS: 0
OnRawPress keycode: 4 Modifiers: 0
OnRawRelease keycode: 4 Modifiers: 0
key 's'  115 MOD: 0 OEM: 16 LEDS: 0
OnRawPress keycode: 16 Modifiers: 0
OnRawRelease keycode: 16 Modifiers: 0

NOTE line 17 has a bug this code:
Code:
#ifdef KEYBOARD_INTERFACE
uint8_t keyboard_last_leds = 0;
[B][U]uint8_t keyboard_modifiers = 0;  // try to keep a reasonable value[/U][/B]
#elif !defined(SHOW_KEYBOARD_DATA)
#Warning: "USB type does not have Serial, so turning on SHOW_KEYBOARD_DATA"
#define SHOW_KEYBOARD_DATA
#endif

Needs to be edited to this:
Code:
[B][U]uint8_t keyboard_modifiers = 0;  // try to keep a reasonable value
[/U][/B]#ifdef KEYBOARD_INTERFACE
uint8_t keyboard_last_leds = 0;
#elif !defined(SHOW_KEYBOARD_DATA)
#Warning: "USB type does not have Serial, so turning on SHOW_KEYBOARD_DATA"
#define SHOW_KEYBOARD_DATA
#endif
 
I believe you misunderstood my problem; At the beginning of my post I showed my code that I was trying to use, then I stated that HIDDeviceInfo was not seeing the keyboard either which suggests that the board appears to be unable to communicate with any type of USB device. (In this case I'm trying to communicate with a keyboard).

Apologies if I worded it poorly; I'm not a native English speaker.
 
If you want to know what happens when I run the keyboard example, this is what I get (The keyboard is plugged in, and I'm spamming random keys):
unknown.png
 
I believe you misunderstood my problem; At the beginning of my post I showed my code that I was trying to use, then I stated that HIDDeviceInfo was not seeing the keyboard either which suggests that the board appears to be unable to communicate with any type of USB device. (In this case I'm trying to communicate with a keyboard).

Apologies if I worded it poorly; I'm not a native English speaker.

Some confusion indeed.

The p#1 also suggested unsure of USB Host connection/function. That is the Keyboard in use is wired to the INTERNAL USB HOST pins.

Testing here as noted in p#2 showed keyboard connection and activity. Not noted was it did not work when I plugged BACKWARDS into USB Host port :(

When USB Host adapter was properly wired and a functional 'recognized' keyboard was plugged in that worked showing the hardware and USB Host code to be functional on a T_4.1 here.

Until that works as indicated in p#2 - nothing else is likely to work.

Once that works - perhaps some element of that example code would show the missing USBHost interface details to connect the keyboard.
 
Hi

How are you connecting to the Host port ?, "I even attempted inverting D- and D+ just in case" suggests somthing adhoc. Have you tried anything like below. I have a few of these and have good results with the 4.1.
TeensyUSB_.jpg
 
I soldered some jumper wires to a USB A female connector, then soldered pin headers to the teensy 4.1 and plugged it in.
That worked perfectly when I tested it a few months ago on my earlier teensy board (which I tragically ruined while soldering), but it now doesn't work on my new one that I recently got.
 
Sounds like it might be a electrical connection issue then. Have you checked for dry joints, broken wire, excessive resistance, shorts ? Do you have a scope or Logic analyser so you can see the signal ?
Personally I would use headers as they are easy to solder reliably on the teensy and a flying lead for the USB as you can easily replace it.
 
Connections wise, I'm quite confident it's well soldered and that there is a good connection because:
- When measuring the voltage across GND/+5V I read somewhere around 5.02/5.05V
- And anytime I plug in a device, I receive the following debug log:

Code:
port change: some numbers here
    connect
  begin reset
port change: some numbers here
  port enabled
  end recovery
new_Device: 12 Mbit/sec
new_Pipe

which leads me to believe that the data lines are also well connected, and that some form of successful communication is happening.


As far as it goes visualizing the signal, I don't have a scope or any kind of logic analyser at home
 
Using a PJRC 5 pin (2 GND) version like p#7 here and it works as in p#2.

If p#2 code with PJRC example doesn't work to show results as posted:
> wiring is bad
> keyboard is bad, or not recognized as the logitech there did.
> perhaps there is source code install corruption or wrong library version in use (TeensyDuino version 1.56).

<EDIT>: p#2 only has USB Type: Serial
> not sure that would change anything affecting the USB Host hardware
> but p#5 does not show expected results for keyboard as in p#2
 
Oh looks like you were right about the connection, I stole a female USB type A port from another component, soldered it to jumper wires and now its working :facepalm:
20220427_225007.jpg

So the old one I made must have been defective in some way

Anyway thank you so much for your support and your time :eek:
 
You are welcome, Jakub, glad it worked out.

Also, I see Paul took the post #3 PR#88! That was a good example to see the needed function.
 
Back
Top