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:
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?)
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.
“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!”
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.
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.
Instructions to get this board working with CircuitPython:
Download latest release (or lastest stable) from Pico Download .
Copy the UF2 file to the Pico after holding down the onboard button at boot to mount as a USB device
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).
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 .
Now, this is one heck of a bundle of libraries (thanks Adafruit, you’re awesome!) However, we just need:
lib/adafruit_dotstar.py
lib/adafruit_hid directory and all there-in.
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.
This is important: in Thonny create a NEW blank document.
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.
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.
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.
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.
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