I'm trying to control my KVM using a Raspberry Pi by sending HID keystrokes like ScrollLock + ScrollLock + <number> to switch ports.
The Pi runs Bitfocus Companion and a Stream Deck, which I want to use to trigger those key combos. Ideally, it could also send macros to the currently active computer.
HID support on the Pi (especially the 4B) is pretty rough. It supports OTG over USB-C, but that port is also used for power. The Pi Zero handles OTG better, but it's too underpowered. There aren't many libraries for this either — most solutions rely on shell scripts.
My workaround is to use GPIO 14/15 to send UART to a microcontroller that can act as a USB HID device. Coding this is easy enough, but the electrical part is giving me trouble.
I came across the Adafruit CH9328 UART to HID breakout, which seemed perfect — even has example wiring with GPIO 14/15.
For testing, I used a USB 3.3V UART adapter. It works if USB power is connected first, but if serial is already connected when USB is plugged in, the board fails to enumerate. I see unstable voltage around 3.1–3.5V instead of a clean 5V. That worries me, especially if a power outage causes a weird boot sequence with the board always connected inside the Pi enclosure.
I also have a Seeed XIAO SAMD21 and an Adafruit ItsyBitsy M0 Express. The ItsyBitsy has a VBAT pin that can take 3.7–6V, and it should switch between VBAT and USB automatically. I thought I could power it from the Pi’s 5V rail, but someone pointed out that it might not handle USB D+/D- properly if the cable isn’t unplugged.
For context, I’m a beginner with electronics — decent with a soldering iron, but not great at reading schematics.
I’m open to using other microcontrollers too. I looked at the Waveshare RP2040-ETH to do this over Ethernet, but if I can get UART working reliably, I’d prefer that route.
Does anyone have advice on how to handle the power/backfeed issue or suggestions for a better approach?