Where to find the library usb_hid?

3.3k views Asked by At

With a Rasbperry Pi Pico I make a mouse. I need the usb_hid library but can't find it:

from machine import Pin
import usb_hid  <----
import time as t
from adafruit_hid.mouse import Mouse

pulsador_uno = Pin(3, Pin.IN, Pin.PULL_UP) #declaramos la ubicacion del pin del pulsador uno pulsador_dos = Pin(7, Pin.IN, Pin.PULL_UP)
#declaramos la ubicacion del pin del pulsador dos pulsador_tres = Pin(11, Pin.IN, Pin.PULL_UP) #declaramos la ubicacion del pin del pulsador tres
LEFT_BUTTON= 1 m = Mouse(usb_hid.devices) #creamos un objeto de mouse, para luego utilizarlo en el main()

def main():
    if not pulsador_uno.value() or not pulsador_dos.value() or not pulsador_tres.value():
        print('Button pressed!')
        m.click(Mouse.LEFT_BUTTON)
    else:
        print('Button not pressed!')
        t.sleep(3)

while True:
    main()

Result:

ImportError: no module named 'usb_hid'

3

There are 3 answers

2
Mamed On

you can try this library, usb_hid is the core module of it: https://circuitpython.readthedocs.io/en/latest/shared-bindings/usb_hid/index.html#

1
Lixas On

You have no specified exact microcontroller you have, so I assume you have generic ESP32

There is no native USB HID support on ESP32 DEV KITs on Micropython. You could check other solution to act you device as an input: https://github.com/Heerkog/MicroPythonBLEHID

ESP32-S2 family has required hardware, but i'm not sure about Micropython side.

0
mojochicken On

You will need to install circuit-python to use the hid library. You can download it here https://circuitpython.org/board/raspberry_pi_pico/ Once you download the uf2 file, hold down the "bootsel" button on the pico as you plug it into your pc. It should show up as a mass storage device. Then just drag the uf2 file onto the pico and it should be ejected. Unplug and plug in your pico again to your pc without pressing the "bootsel" button and look for a device named "CIRCUITPY" in the file explorer. in this file there is another file named "lib". You will have to place your library files in here. You can download the adafruit_hid library here https://github.com/adafruit/Adafruit_CircuitPython_HID copy the "adafruit_hid" library to "lib" and then try running your code again. If your code was named "main.py" under micropython so i automatically starts, you will haveto rename the file to code.py if you don't want to manually execute your python script.