0

I am doing a school project, which involves making a program that with the help of a Rasbperry pi pico and some push buttons, make a mouse. But apparently I need the usb_hid library to host my usb but I can't find it.

I've been looking for the library for days to do the pip install, but I can't find it anywhere

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'

Lixas
  • 6,938
  • 2
  • 25
  • 42

3 Answers3

0

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#

Mamed
  • 95
  • 4
  • 16
  • Thanks for your answer, but I need the pip to install it. It would be a great help – Jeremias Davison Nov 30 '21 at 16:37
  • CircuitPython is an alternative to MicroPython which lacks some features but may be easier to use and has a well organised driver library for external components. You don't need `pip` to install CircuitPython libraries, just copy them to the target device - this is explained in the documentation. – nekomatic Dec 15 '21 at 11:58
0

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.

Lixas
  • 6,938
  • 2
  • 25
  • 42
  • OP indicated they use a Rasbperry pi pico]https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html – Jos Verlinde Feb 02 '22 at 21:45
0

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.