KB2040 HID problem in Raspbian

Hi all,

Lately I’ve been cobbling together a few bits and pieces into something silly, but I’m running into an issue with a KB2040 “KeyBoar” that’s interfacing to a button matrix.

The setup is:
Buttons → KB2040 running CircuitPython -USB-> 4-port USB hat for Pi Zero → Pi Zero 2W running Raspbian -HDMI+USB-> 5" LCD touchscreen

The problem I’m having is the KB2040 isn’t detected as a keyboard on boot; if I unplug and replug after boot it works fine, but that’s not going to be possible for my project. I know the USB connections and power are good because Raspbian mounts the CircuitPy directory as a USB drive, and I can even view the source code that’s running on the KB2040.

Running lsusb in the console shows that it is detected as a keyboard HID on boot, but oddly it also enumerates as a separate mouse device; not sure how to stop that as it’s not part of my code (don’t think it’s mentioned in the KB2040 docs either, it would be really handy if it could run a mouse and keyboard!). There’s no keyboard hardware config options I could find in Raspbian either, unless I’m missing something really fundamental. The touchscreen from the LCD works on boot without issue, through the same hub hat, so I think it’s got to be something with the KB2040?

So far I’ve tried every USB port on the Pi and Hat, including connecting through an external hub, I’ve even tried a couple different OS’s for the Zero but they had the same issue.

Does anyone have any ideas? I was thinking of programmatically rescanning the USB bus after boot but wasn’t sure how to actually do that in Raspbian, Linux is yet another of my weak points 😁

I have a Pico RGB Keypad Base, with a similar issue. It’s running Circuit python and setup as a USB HID device.
It’s not detected when I boot up my Windows PC. If I do a reset, or unplug plug back in its then good to go. My bodge fix was to put in a time deley before it runs its code. It’s like plugging it in after the PC is booted up to the login screen. Now it works OK.

import time
time.sleep (25)

import usb_hid

from pmk import PMK
from pmk.platform.rgbkeypadbase import RGBKeypadBase as Hardware
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode

1 Like

Thanks for your response, this seems like just what I need! I’ll give it a go this evening and see what happens, I guess I’ll come up with a typical boot time for Raspbian and start with that as my delay.

That’s about what I did. I watched my boot time with a watch, then played with my delay to make it as short as possible. My keypad lights up when its ready to go. No wondering when, or if it turned on.

1 Like