Pico RGB Keypad Base as a USB HID device - SOLVED

Afternoon helpful folk. I think I’m missing something in my understanding: I have the Pico RGB Keypad Base working fine, ie: press a key → RGB lights up etc. However I want to use it in Micropython as a USB HID device to control another computer. This is where the problems start. Options:

  1. Use Micropython firmware from Pimoroni but although this now enables me to import and use the pyb module it does not seem to support USB HID devices (or am I missing something?)

  2. Use Adafruit’s CircuitPython. This includes USB HID device (keyboard) support. However I then lose access to the Pimoroni Pico Keyboard modules which defeats the point. Eg: Use your Raspberry Pi Pico as a HID device to give mouse and keyboard input using Adafruit's CircuitPython - Raspberry Pi Pod and micro:bit base

  3. Option 3? Is there an option 3? Is there a Micropython USB HID module hidden away inside Pimoroni’s custom firmware that I don’t know about and couldn’t find online? I tried importing pyusb but that is not available, for instance.

I’ve been googling for several hours recently and the nearest to finding a solution I could find was Raspberry Pi Pico & Pimoroni RGB Keypad HID in Circuitpython 6.2+ · GitHub which does link up the Pico RGB Keypad Base to CircuitPython to some degree but ofc takes me out of Pimoroni’s Micropython where I would ideally like to be.

Thanks in advance.

1 Like

Pimoroni kindly got back to me with this info:

“USB HID isn’t implemented in MicroPython yet but I believe they’re on with it, there’s a Github issue tracking it if you’re interested in keeping an eye on it!”

1 Like

Similar use case to ColinD above, I also have the RGB Keypad and the only reason I bought this was to use it as a HID device. So it would be wonderful if Pimoroni deliver USB HID support soon. thanks!

Ideally Micropython would add USB HID support for Pico which downstream Pimoroni could inherit. I’ll reach out to Raspberry Pi to mention the lack of USB HID; albeit, I expect they are already aware.

Been trying to figure this out as a newbie for the past few days. Came online to post a cry for help, but looks like ColinD beat me to it.

Only bought this thing to work as a funky macro keypad, then move onto adding a display. Turns out I can’t even make it function as a keypad :(.

So all the modelling of a case… wiring… frustration… for naught :(.

Hi Vodzurk. Wow I love the case! 3D printed? Sadly I’ve no printer so can’t make my own. Very impressed.

Luckily there is a solution / workaround for the moment involving using CircuitPython instead of Micropython. See Raspberry Pi Pico & Pimoroni RGB Keypad HID in Circuitpython 6.2+ · GitHub for the code and https://circuitpython.org/ for CircuitPython itself.

Oh and more info on CircuitPython from Adafruit: Overview | Getting Started with Raspberry Pi Pico and CircuitPython | Adafruit Learning System .

I’lll take wildestpixel’s code and see where I can get to it and post back to here to help you in a couple of days. I just need the time to sit in front of Python but ofc don’t feel you have to wait for me.

TBH I reckon USB HID will be supported in Micropython for Pico quite soon. After-all, we’re all asking for it. ;)

I’ll reply here asap I’ve an expanded solution for us. based on the above.

Ok, I’ve figured it out. Here goes…

Instructions to get this board working with CircuitPython:

  1. Download latest release (or lastest stable) from Pico Download .
  2. Copy the UF2 file to the Pico after holding down the onboard button at boot to mount as a USB device
  3. The Pico reboots automatically.

Note for the following instructions that unlike the MicroPython UF2 where to copy files to the Pico you must boot it with the button held down you can just connect it to copy files (providing you select to mount when the option appears).

  1. Head on over to wildestpixel on Github and copy the code from Raspberry Pi Pico & Pimoroni RGB Keypad HID in Circuitpython 6.2+ · GitHub to the Pico and run.

  2. It’ll fail complaining that importing adafruit_dotstar just isn’t cricket.

  3. To fix this and the same regarding adafruit_hid head on over to GitHub - adafruit/Adafruit_CircuitPython_Bundle: A bundle of useful CircuitPython libraries ready to use from the filesystem. and then to the latest release.

  4. It took me a couple of goes but I worked out that even though the instructions say that as I am using CircuitPython 6.x I should download the 6.x bundle that this is not true.
    This is because the named 6.x bundle is for Micropython (hmm… I wonder if this means I coudl get the keypad working with Micropython after-all… I’ll try that).
    Download the non-6.x non-examples bundle. As of today this is adafruit-circuitpython-bundle-py-20210213.zip .

  5. Now, this is one heck of a bundle of libraries (thanks Adafruit, you’re awesome!) However, we just need:
    lib/adafruit_hid directory and all there-in.

  6. Create a lib directory on your Pico and copy the above there. Note if you drag and drop from the zip file it’ll create a dated adafruit directory into which it places the libs. To avoid this I extracted to Documents on my Pi 4 then copied over just what I needed.

  7. This is important: in Thonny create a NEW blank document.

  8. Run the code you downloaded from wildestpixel and press a button, any button. You’ll see the key light up AND text written out to the blank doc. That’s why you don’t want to press buttons when you have Thonny showing your code as the text will get inserted there-in whenever a button is pressed.

Hope that helps. Any problems, do say.


Addendum: when you install CircuitPython it creates code.py in root of the Pico which is executed in preference to main.py . See: CircuitPython Getting Started Guide

Therefore either delete code.py to get your main.py to execute upon connected the Pico or save as code.py.

1 Like

OMG, you’re a genius!

Commencing following of instructions… will edit this post shortly… hopefully with delight!

Edit: OMG! It works!

Are there any “buy this dude a beer” things on the internet these days?

Cheers, you’re welcome. No worries about the beer. Just happy to help a fellow Pico owner.

I love solving conundrums like this. Reminds me of back in 2012ish trying to get VNC working on a Pi 1. Ahh, those were the days…

It’d be worth spending some time going through wildestpixel’s code to see how it works. That’s my next task. Then, I want to write little dinky functions to perform the same as Pimoroni’s library. I reckon porting their code over short be straightforward now.

Oh and lastly I plugged it into my Mac and it worked first time with bits o’text splurting all over the place.

Oh and lastly-lastly I want to figure out how to turn off auto usb mounting in CircuitPython for that truly plug and forget flavour.

PS: being cheeky Vodzurk would you mind sharing your 3D file with me for the great case? I’d like to learn more about casing my Pico and this seems a super place to start. Thanks. OFC if you’d rather not then no problem. It is yours ofc.

PM sent with them… if others are interested, can figure out how best to share (like slapping them on Thingiverse).

1 Like

The auto usb disk thing would definitely be good to get rid of!

Cheers, that’s great!!

Thingiverse of printable box: https://www.thingiverse.com/thing:4761178

1 Like

PS: This is a useful list of codes for keys like CTRL:


For example (and I’m not certain this is the most efficient way, but it works):

elif pressed[15]:
    pixels[15] = colourwheel(15 * 16)  # Map pixel index to 0-255 range

    kbd.press(Keycode.COMMAND, Keycode.Z)
    kbd.release(Keycode.COMMAND, Keycode.Z)

Note that we have to tell the Pico to release COMMAND-Z else it repeats.

Also note that the last line of the file is indented one too many tabs:

time.sleep(0.1) # Debounce

I lifted it up one level, outside the else. Else, it only fires when no key is pressed so if you are pressing a key it’ll just quickly repeat faster than you can release it.

Good link. I’ve now got CTRL+C then CTRL + V onto the bottom left two keys with:

    elif pressed[12]:
    pixels[12] = colourwheel(0 * 16)  

    if not held[12]:
        kbd.send(Keycode.CONTROL, Keycode.C)
        held[12] = 1
elif pressed[13]:
    pixels[13] = colourwheel(0 * 16)  #Red whilst pressed

    if not held[13]:
        kbd.send(Keycode.CONTROL, Keycode.V)
        held[13] = 1

Wanna get some goodies set up on it for FreeCAD usage :D

1 Like

You are awesome - thanks for this! I have followed your instructions and made a repo so I can come back to it as I get time: GitHub - qbalsdon/pico_rgb_keypad_hid

1 Like

Brilliant qbalsdon! You beat me to it. :)

If anyone is interested I have created a pure Python class for communicating with the RGB Keypad.

It works with both MicroPython and CircuitPython so you can use all the HID capabilities of CircuitPython with a lot less bother.

1 Like