Mouse/Keyboard Forward Examples From USBHost_t36 Not Working as Expected

KVM Nerd

Member
Hello,

I am trying to get the mouse and keyboard forwarding examples from the USBHost_t36 library to work as expected (or at least I expect them to).

My Software setup:
Arduino IDE v2 (Flatpak Version from Flathub)
Version: 2.3.4
Date: 2024-12-03T10:51:12.539Z
CLI Version: 1.1.1
Board: Teensy 3.6
Latest Teensyduino
Ubuntu 24.10

Which examples I have tried so far from the Arduino IDE examples menu:
  1. Examples/USBHost_t36/KeyboardForeward
  2. Examples/USBHost_t36/MouseKeyboardForward
They compile and upload flawlessly. I tried connecting a keyboard (1.) and keyboard and/or mouse (2.) to the Teensy, but all I get are outputs from the serial monitor showing the appropriate inputs from the devices like keyboard press/release, mouse movement and clicks and also device connect/remove (even hubs which work fine with mouse + keyboard), so both the USB host side of the examples (software) and the Teensy itself (hardware) seem to work fine. I also tried setting the USB type to all of the following types for both examples:
  • Keyboard
  • Keyboard + Touch Screen
  • Keyboard + Mouse + Touch Screen
  • Keyboard + Mouse + Joystick
  • Serial + Keyboard + Mouse + Joystick

However, the PC the Teensy is connected to lists the appropriate USB devices, but does not receive any inputs from them, no matter what I've tried. Shouldn't the PC receive the keyboard and mouse inputs from the Teensy which should forward it from the devices connected to it, as the name of the examples imply? Am I missing something? And which USB type should be chosen? The example does not give any hints.

The Examples/_Teensy/USB_Keyboard/Simple example works absolutely fine and the PC receives keystrokes from it, so I assume the USB device part of the Teensy works fine as well.

Thank you in advance!
 
Maybe someone can confirm the example is working or not?
Sorry, I don't have my Teensy stuff out right now... will try to get something out later.
It used to work. Should work.

There is stuff at the start of the sketch:
Code:
#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

All of the interfaces that include the keyboard type, should define the KEYBOARD_INTERFACE in the
core source code (usb_desc.h) which is included by lots of things which is included by Arduino.h...

If it is not defined you should see the warning shown in the code above.

Currently busy, having fun on another platform, trying to get:
SPI1 code working again on Arduino GIGA built using current beta code that is built around zephyr, instead of
the current GIGA code that was built using MBED.
 
Sorry, I don't have my Teensy stuff out right now... will try to get something out later.
It used to work. Should work.

Thank you very much for your reply! Don't get me wrong, I did not mean anybody to rush. I was hoping for anybody answering that she/he was or wasn't successful with the examples on her/his setup.

There is stuff at the start of the sketch:
Code:
#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

All of the interfaces that include the keyboard type, should define the KEYBOARD_INTERFACE in the
core source code (usb_desc.h) which is included by lots of things which is included by Arduino.h...

If it is not defined you should see the warning shown in the code above.

Now here comes something interesting: I tried setting the USB type to "serial" only (so no keyboard or mouse) and it compiles without any warning on Linux and Windows. Maybe this is already a hint where things are going wrong?

Currently busy, having fun on another platform, trying to get:
SPI1 code working again on Arduino GIGA built using current beta code that is built around zephyr, instead of
the current GIGA code that was built using MBED.

Ugh, I can't follow you! :LOL: I'm not very much into µC programming, but it sounds thrilling!
 
I tried it with a MicroMod and I was on Ubuntu at the time:
1738283942645.png

And I entered the text shown in the Serial Monitor input area with the keyboard plugged into the USBHost port

I have not tried things in a while on T3.6 might be a while for me to dig one up. They are in a box inside my cabinet. I
organized things a few times, so it is now guaranteed that I cannot find anything. :D

Edit: Forgot to say, that I had the USB type configured as Keyboard
 
I tried it with a MicroMod and I was on Ubuntu at the time:

And I entered the text shown in the Serial Monitor input area with the keyboard plugged into the USBHost port

I have not tried things in a while on T3.6 might be a while for me to dig one up. They are in a box inside my cabinet. I
organized things a few times, so it is now guaranteed that I cannot find anything. :D

Edit: Forgot to say, that I had the USB type configured as Keyboard

Thank you very much for testing! So the example itself seems to be valid.

To me it really looks like it is a device specific issue. It compiles with no issues on my side whichever USB type I select (if I remember correctly, will prove this again), which makes no sense. Maybe there's something wrong in the initialization/configuration file that KEYBOARD_INTERFACE and maybe other definitions always get defined, but the corresponding USB code parts do not work correctly.

If it is proven to work on a Teensy 4.1, it would be an option to upgrade in case this cannot be fixed.

Edit: Changed code to inline code for definition for improved displaying.
 
To me it really looks like it is a device specific issue. It compiles with no issues on my side whichever USB type I select (if I remember correctly, will prove this again), which makes no sense. Maybe there's something wrong in the initialization/configuration file that KEYBOARD_INTERFACE and maybe other definitions always get defined, but the corresponding USB code parts do not work correctly.

I tried compiling it with different USB types like "Audio" and "MIDI" which should not contain keyboard functionality, but the code still compiles without any errors, I even could not find the "USB type does not have Serial, so turning on SHOW_KEYBOARD_DATA" warning in the debug output. Switching the board type to "MicroMod" or "Teensy 4.1" does not change this behavior. I guess this is not as intended?
 
Last week I was able to test the examples with the Teensy 4.1 and am able to confirm the examples are working with this version. For me this confirms it should neither be a problem of my software setup nor a problem with the Teensy 3.6 itself, but a problem with the current Teensy 3.6 USB implementation in Teensyduino. Maybe someone could take a look at this, that would be very nice!
 
should neither be a problem of my software setup nor a problem with the Teensy 3.6 itself, but a problem with the current Teensy 3.6 USB implementation in Teensyduino. Maybe someone could take a look at this, that would be very nice
Note: the example can work very easily. Just force tell it, that it has KEYBOARD Interface.
Example: update the code in the example to manually define it like:
Code:
// Simple USB Keyboard Forwarder
//
// This example is in the public domain

#include "USBHost_t36.h"

// You can have this one only output to the USB type Keyboard and
// not show the keyboard data on Serial...
#define SHOW_KEYBOARD_DATA
#define KEYBOARD_INTERFACE
...

The issue, is with the T3.x builds of Core.... The code is setup that you can check for what USB Type string that the build passes in to the compiler, but you can not simply ask, does this build support USB Keyboard? Like: HAS_USB_KEYBOARD or some such define..
What you have to do instead, is to find every .... USB type that contains keyboard and change your test to look for any of them. Which I always hated as, when new USB types are created which include Keyboard capabilities, like hypothetically maybe: Keyboard with dual serial...
You then need to update every example sketch (and user sketches) to now include whatever the define that was added to boards.txt

So, if someone wanted to make it work correctly, they could update the sketch something like:
Near the start of the sketch before we test if it has KEYBOARD_INTERFACE

Code:
#if defined(USB_KEYBOARDONLY) || defined(USB_HID) || defined(USB_SERIAL_HID) || defined(USB_EVERYTHING)
#define KEYBOARD_INTERFACE
#endif
Warning: no guarantees that I did not miss some, typed in on the fly so...

And if it works, then maybe issue a Pull request to update it on github.
 
Back
Top