HID Mouse and Keyboard Issue

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
onlyram27
Posts: 1
Joined: Thu Feb 03, 2022 7:37 am

HID Mouse and Keyboard Issue

Post by onlyram27 » Thu Feb 03, 2022 8:20 am

Hi
I'm following the MicroPython tutorial, but having trouble with the "Making the pyboard act as a USB mouse and keyboard" .
[Using MicroPython v1.13 on 2020-09-02; PYBv1.1]

1] For mouse:
The controller does not seem to work when pyb.usb_mode('VCP+HID') is uncommented in the boot.py file.
In main.py have put following code-

import pyb

switch = pyb.Switch()
accel = pyb.Accel()
hid = pyb.USB_HID()
while not switch():
hid.send((0, accel.x(), accel.y(), 0))
pyb.delay(20)

After saving codes, ejected the pyboard and then had reset it as mentioned in MicroPython documents. After this green LED is continuously blinking and in devices(in windows os) it's showing com connected as mouse FS mode but the code in main.py is not reflecting.

2] For keyboard:
The controller does not seem to work when pyb.usb_mode('VCP+HID', hid=pyb.hid_keyboard) is uncommented in the boot.py file. Also tried with pyb.usb_mode('HID').
In main.py have put following code-

import time

h = pyb.USB_HID()
def kb_press(x):
b = bytearray(8)
b[2] = x # key press
h.send(b)
time.sleep_ms(25)
b[2] = 0 # key release
h.send(b)
kb_press(4) # press "a" once

After saving codes, ejected the pyboard and then had reset it as mentioned in MicroPython documents. After this green LED is continuously blinking. But not able take input. In this connection is also not showing in device(in windows os).

Am I missing something here to use it properly, please suggest.

Thank you.

Post Reply