USB HID keyboard not working in RetroPie
-
Hello everyone!
I'm working on a project that has RetroPie running on a Pi Zero 2, and i was planning on using a Pi Pico to act as the "controller" by setting it up as a HID keyboard.
This is the code I'm running on the Pico and in Raspberry PI OS it works, i ground pins on the pico, and the OS registers keypresses.
However, I then powered down the Pi, and swapped the SD card for one with RetroPi flashed, i got to the "configure controller" prompt, grounded a pin on the pico, and nothing!
the codes running on the Pico, an LED flashes on the Pico to indicate a key is pressed (GPIO pin grounded) but RetroPi appears to completely ignore it. if i hold down a button on my regular USB keyboard, that is detected by RetroPie.
Im sort of amazed I have got this far, and not I'm not sure what should be the next thing to check, does anyone have experience with USB HID devices controlling a RetroPie instance? would be super grateful for any assistance :)
Thanks!
-
Can you run the following commands and post the output:
cat /proc/bus/input/devices udevadm info -q all /dev/input/eventX
(where
/dev/input/eventX
is the device file corresponding to your HID keyboard).EmulationStation uses SDL for input processing, if you can test your device with
testevdev
from the SDL distro (https://github.com/libsdl-org/SDL/blob/main/test/testevdev.c) that would help to determine if SDL recognizes your HID device as a keyboard or not.EDIT: corrected the commands.
-
@mitu fantastic!!
Thanks so much, this is exactly the sort of next step troubleshooting I was hoping to find.
In the office today, so will get back to you tomorrow with the results.
Thanks again!
-
OK, the OS can definitely see the HID device, but it still does not have an effect in Retropie
@mitu quitting out of emulation station, my HID can enter text in the terminal, and it shows up with
cat /proc/bus/input/devices
I: Bus=0003 Vendor=239a Product=80f4 Version=0111 N: Name="Raspberry Pi Pico Keyboard" P: Phys=usb-3f980000.usb-1.4/input3 S: Sysfs=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.3/0003:239A:80F4.0003/input/input1 U: Uniq=E4620C18C3225D39 H: Handlers=sysrq kbd leds event1 B: PROP=0 B: EV=120013 B: KEY=10000 7 ff9f207a c14057ff febeffdf ffefffff ffffffff fffffffe B: MSC=10 B: LED=1f I: Bus=0003 Vendor=239a Product=80f4 Version=0111 N: Name="Raspberry Pi Pico Mouse" P: Phys=usb-3f980000.usb-1.4/input3 S: Sysfs=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.3/0003:239A:80F4.0003/input/input2 U: Uniq=E4620C18C3225D39 H: Handlers=mouse0 event2 B: PROP=0 B: EV=17 B: KEY=1f0000 0 0 0 0 0 0 0 0 B: REL=903 B: MSC=10 I: Bus=0003 Vendor=239a Product=80f4 Version=0111 N: Name="Raspberry Pi Pico Consumer Control" P: Phys=usb-3f980000.usb-1.4/input3 S: Sysfs=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.3/0003:239A:80F4.0003/input/input3 U: Uniq=E4620C18C3225D39 H: Handlers=kbd event3 B: PROP=0 B: EV=1f B: KEY=302ff 0 0 0 0 483ffff 17aff32d bfd44446 0 0 1 130ff3 8b17c000 677bfa d9415fed 9ed680 4400 0 10000002 B: REL=1040 B: ABS=1 0 B: MSC=10
And then
event1
returns:P: /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.3/0003:239A:80F4.0003/input/input1/event1 N: input/event1 L: 0 S: input/by-path/platform-3f980000.usb-usb-0:1.4:1.3-event-kbd S: input/by-id/usb-Raspberry_Pi_Pico_E4620C18C3225D39-if03-event-kbd E: DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.3/0003:239A:80F4.0003/input/input1/event1 E: DEVNAME=/dev/input/event1 E: MAJOR=13 E: MINOR=65 E: SUBSYSTEM=input E: USEC_INITIALIZED=7136158 E: ID_INPUT=1 E: ID_INPUT_KEY=1 E: ID_INPUT_KEYBOARD=1 E: ID_VENDOR=Raspberry_Pi E: ID_VENDOR_ENC=Raspberry\x20Pi E: ID_VENDOR_ID=239a E: ID_MODEL=Pico E: ID_MODEL_ENC=Pico E: ID_MODEL_ID=80f4 E: ID_REVISION=0100 E: ID_SERIAL=Raspberry_Pi_Pico_E4620C18C3225D39 E: ID_SERIAL_SHORT=E4620C18C3225D39 E: ID_TYPE=hid E: ID_BUS=usb E: ID_USB_INTERFACES=:020200:0a0000:080650:030000:010100:010300: E: ID_USB_INTERFACE_NUM=03 E: ID_USB_DRIVER=usbhid E: ID_PATH=platform-3f980000.usb-usb-0:1.4:1.3 E: ID_PATH_TAG=platform-3f980000_usb-usb-0_1_4_1_3 E: LIBINPUT_DEVICE_GROUP=3/239a/80f4:usb-3f980000.usb-1 E: DEVLINKS=/dev/input/by-path/platform-3f980000.usb-usb-0:1.4:1.3-event-kbd /dev/input/by-id/usb-Raspberry_Pi_Pico_E4620C18C3225D39-if03-event-kbd E: TAGS=:power-switch:
so it's been detected by the OS, this immediately leaves me to believe my code running on the Pico is causing the issue.
I have just realized that the circuit python example HID code is applyingshift
to every keypress, I'm going to go in now and remove theshift
to see if that helps.
edit: removingshift
didn't helpUpdate: I tried the HID after RetroPie had gone to "sleep" and the display dimmed, and the display woke back up, so the input is getting into Emulation Station, but the configure input tool is stubbornly refusing to register any keypresses. very odd.
-
@jameth Just to check you're keeping the key pressed for a few seconds in the input configuration dialog, right ?
You should also check withtestevdev
to see if your device is detected by SDL as a keyboard ? -
yeah at the configure input screen, with every other controller I have ever used, you see the type of the controller "fade in" and that happens pretty much immediately. but I have also tried holding a key pressed for several seconds.
I also cant navigate around the Emulation station with the HID, although the HID did "wake" emulation station from its dimmed "sleep" state.
Ill give
testevdev
a go after the kids gone to sleep, I'm only just about dangerous with the command line,testevdev
looks like it's written in C, so ill need to compile that before I can execute it? if you know a good tutorial that would be appreciated, but I'm sure I'll work it out.Thanks for all your help so far.
-
@jameth said in USB HID keyboard not working in RetroPie:
Ill give testevdev a go after the kids gone to sleep, I'm only just about dangerous with the command line, testevdevlooks like it's written in C, so ill need to compile that before I can execute it? if you know a good tutorial that would be appreciated, but I'm sure I'll work it out.
Actually, trying to produce some easy install instruction I see that
testevdev
doesn't actually do any live testing, just queries the system for some known devices.Can you run EmulationStation with debugging enabled:
emulationstation --debug
then try to configure your input, exit and then post the log file from
$HOME/.emulationstation/es_log.txt
? -
right, cracked it, everything is working as far as RetroPi is concerned.
Looking really closely, as I held down a HID button the word "keyboard" very very briefly appears.
Clearly, I was working too late the other night, I can scroll up and down a menu with my HID keyboard, I was sure I had tested that, but the output is erratic sometimes the keypress happens as I am releasing the key, sometimes a press registers as many discrete keypresses. so I think the code I am running on the pico is not cleanly emulating how a real keyboard handles button presses.
the log output from Debug didn't contain any mention of controller config, so I guess there were no errors there? all I saw was a long list telling me there were no ROM's for any emulators, and then a "cleanly shut down" message.
I'm now happy the issue is in my HID. going to find an actual keyboard project using python, and reprogramme my Pico.
Thanks so much for your help @mitu
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.