For this all one needs is a rpi pico and circuit python for rpi pico.
The Circuit Python for pico can be found over here: https://circuitpython.org/board/raspberry_pi_pico/
Download the uf2 file and drag it over to the pico.
Next: download this as zip from or “git clone” it : https://github.com/adafruit/Adafruit_CircuitPython_HID
Extract it. In there , there is a folder called adafruit_hid , copy that folder to the pico where circuit python is already installed.
remember to transfer the python file with name “code.py” to pico, to run on boot.
This is the example for Mouse:
import time import board from digitalio import DigitalInOut, Direction, Pull import time import usb_hid from adafruit_hid.mouse import Mouse mouse = Mouse(usb_hid.devices) x=0 y=0 mouse.move(x,y) # This will move the mouse from it's current position to x pixels # and y pixels. # So if the current position is (100,200) it'll move to # (100+x,100+y)
This can also be used with a button so that it keeps the screen of pc awake ,like this:
import time import board from digitalio import DigitalInOut, Direction, Pull import time import usb_hid from adafruit_hid.mouse import Mouse mouse = Mouse(usb_hid.devices) btn = DigitalInOut(board.GP14) btn.direction = Direction.INPUT btn.pull = Pull.DOWN i=0 on=False def onRelease(): bState=btn.value released=False if (bState): bState = btn.value while bState: bState = btn.value return True; while True: if onRelease(): on=not on if on: mouse.move(5,5) time.sleep(0.1) mouse.move(-5,-5) time.sleep(0.1) time.sleep(0.1)
This is the example for Keyboard.
import time import usb_hid from adafruit_hid.keyboard import Keyboard from adafruit_hid.keycode import Keycode key_A=Keycode.A key_Shift = Keycode.SHIFT keyboard=Keyboard(usb_hid.devices) time.sleep(2) keyboard.press(key_Shift, key_A) keyboard.release(key_Shift, key_A)
if you have any questions, email me at:
7 thoughts on “Using Raspberry Pi Pico as Hid Device to control Mouse and Keyboard”
Hriday, I am currently working in Krakow, but I am looking for someone familiar with ardouino and raspberry pi. Would it be possible to email and perhaps zoom concerning a possible proposal. Kind regards.
Well I haven’t had any success with an Arduino UNO or nano, It can be done using a Pro Micro. And I don’t have much experience with rpi single board computer. Email me your whole problem and I’ll let you know if I can help.
I read this blog with interest. Does solution act as an HID Proxy so I can use the Pico to wake up a sleeping PC?
Never tried it, but i figure it won’t be that hard. Just try a normal mouse test script and run it while your PC is sleeping