Presto - USB_HID support

Hi all

On a previous post, I made mention of the fact that I want to use my Presto as a macropad, but I’ve since learned that USB_HID support isn’t included in the Presto micropython image.

Are there plans to add this any time soon?

If not, can anyone guide me on how to go about trying to do this?

The upstream RP2 port of MicroPython does not support USB_HID. CircuitPython does support USB_HID, but there is no CP support for the Presto (I doubt there will ever be). So I don’t think this is the way to go.

If you really need a macropad with a such large touch display, I would go for a CYD (“cheap yellow display”), check if it supported by CircuitPython and then just use that.

Having said this: without experience this is a non trivial task, especially because those CYD are cheap, so you pay the price elsewhere: you have to read schematics, google for chips and check the availability of drivers and so on.

I think dynamic USB devices are now supported in MicroPython (as of v1.23.0)?

I’ve not done anything with it myself yet, but here’s a keyboard / HID example.

2 Likes

Thanks, I missed this. This is not part of MicroPython, but MicroPython-lib (so it is pure Python). That is why it does not turn up in the MicroPython docs. I was not aware of that.

@scouser_27 You should give this a try. Maybe you have to do some code-installs. Not sure if the MicroPython-lib is installed by default. If not, it should not be more than a copy and paste at worst.

1 Like

Thank you @bablokb and @hel for your replies!

I’ll give this a go, see how I get on and try to report back

OK, it works. Sort of

Having installed the usb → device [hid and keyboard], I cobbled together a simple script based on the examples available.

import usb.device
from usb.device.keyboard import KeyboardInterface, KeyCode
import time

class SimpleKeyboard(KeyboardInterface):
    pass  # No need to override anything for basic usage

# Initialize the USB keyboard interface
keyboard = SimpleKeyboard()
usb.device.get().init(keyboard, builtin_driver=True)

# Wait until the USB interface is ready
while not keyboard.is_open():
    time.sleep_ms(3000)

# Send the letter "A"
keyboard.send_keys([KeyCode.A])
time.sleep_ms(1000)
keyboard.send_keys([])

The 3000mS delay is to give me time from when I start the script to switch to a text editor.
running it from Thonny, the device disconnects but reconnects as a USB keyboard (as seen in dmesg)

It then sends the letter A, but continues to send it.

It’s possibly a limitation of my code or a limitation of the keyboard implementation, but in any case it’s progress!
I’ll play with it some more in the coming days (weeks?) and update this thread further.

3 Likes

I’m wanting to try this on a Pimoroni RGB Keypad, but got lost in what to do first? IE, Make sure usb-device-keyboard is installed via: mpremote mip install usb-device-keyboard. << From where do I do that?

mpremote is a tool that is distributed with stock MicroPython. It runs on your computer. No idea if it runs on any OS though. Think of “pip for pico”.

I would not go through the hassles of installing mpremote and figuring out how it actually works just for this one use case. Mpremote is a tool for commandline based workflows. If you are using Thonny, just fetch the MicroPython-libs manually and copy them to your device.

1 Like

Ok, will have a look see at this latter on today. Thanks for the reply. I currently have one RGB Keypad setup with Circuit Python using the PMK library. One issue is it seems to mess with other Pico’s when I put them in Boot mode. I get unknown device errors that persist until I turn off or unplug the RGB Keypad. Very annoying when i’m in the mood to tinker around. The other issue is I have to put a delay in or it won’t get detected as my Windows PC boot up. That I think is more of a Windows issue. Anyway, I’m hoping switching to Micro Python helps get rid of the unknown device errors.

I think these unknown device errors are also a Windows problem. Windows seems to cache some USB-device information and this causes problems like this. There is a cleanup tool for this: Troubleshooting | Welcome to CircuitPython! | Adafruit Learning System

1 Like

Thanks for the link. =) It is likely Windows, but it only ever happens when that one Circuit Python device is active on the USB Bus, and I put another Pico in Boot mode. If I disable it via the Run pin, all is good. I’ve tinkered with near a dozen different Micro python flashed Pico’s and had no issues. It’s not the end of the world, it’s just annoying. And it’s what I usually use to launch Thonny, Putty etc. =(

MicroPython usually only exposes a serial device to the host (CircuitPython exposes a serial device, a mass-storage device and a HID-device and could also expose a MIDI device). Once you start with MicroPython and HID, Windows will also cache the USB-device information from your MicroPython devices. It will be interesting to see how Windows behaves in this context (all Picos share the same USB vendor id and USB device id and I think this is what is confusing for Windows).

1 Like

I haven’t done anything related to this just yet. My Chronic Pain has flared up and put me in a cranky mood. Might have a go latter on today. Will have to see how the day goes. I just got back from a nice long walk in the woods with my dog Missy. That always puts me in a good mood. ;)

All the best wishes! I also like to go outside, but currently it is very wet and windy here and so I can’t do anything except hacking on some new programs 😂️. I am always glad I can keep myself busy inside and outside of the house.

Ok, I finally got back to this.
@bablokb I downloaded and ran the Device Cleanup utility. Then tagged and removed the Circuit Python entries. My RGB Keypad still worked and no unknown device error. =) I’m thinking I’ll be good until I reboot the PC. Or restart the Circuit Python RGB Keypad.

I then Flash Nuked my spare RGB Keypad and flashed it with Pimoronies custom uf2.

MPY: soft reboot
MicroPython v1.25.0, pico v1.25.0 on 2025-05-12; Raspberry Pi Pico with RP2040

Type "help()" for more information.

>>> 

Launched Thonny > Tools > Manage Packages.
Then searched for and installed usb.device, and usb.device.keyboard.
Now it’s on to editing the KEYS= and `LEDS+'.
I’ll post back how that works out.
Thanks all. =)

1 Like

Hmm, this may be harder than I expected? The keypad is on an IO Expander, and the LED’s are APA102’s.
pico-matrix-keypad.sch
Time for a another break and some thinking.

You probably need to take this as the basis: pimoroni-pico/micropython/examples/pico_rgb_keypad/demo.py at main · pimoroni/pimoroni-pico · GitHub and merge it with the usb.device.keyboard example.

And here is the reference: pimoroni-pico/libraries/pico_rgb_keypad at main · pimoroni/pimoroni-pico · GitHub

That’s the plan. ;)
I ran the demo after the uf2 flash just to make sure all the buttons and LED’s worked as advertised.

1 Like