import sensor, image, time, math
import pyb
# I've tried both modes here but neither works, so moved it to a separate boot.py script
#pyb.usb_mode('VCP+HID', hid=pyb.hid_keyboard)
#pyb.usb_mode('CDC+HID', hid=pyb.hid_keyboard)
hid = pyb.USB_HID()
red_led = pyb.LED(1)
green_led = pyb.LED(2)
blue_led = pyb.LED(3)
ir_leds = pyb.LED(4)
red_led.off();
green_led.off();
blue_led.off();
ir_leds.off();
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.VGA) # High Res!
sensor.set_windowing((640, 10)) # V Res of 80 == less work (40 for 2X the speed).
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must turn this off to prevent image washout...
sensor.set_auto_whitebal(False) # must turn this off to prevent image washout...
clock = time.clock()
while(True):
clock.tick()
img = sensor.snapshot()
codes = img.find_barcodes()
for code in codes:
img.draw_rectangle(code.rect())
print_args = (code.type(), code.payload(), (180 * code.rotation()) / math.pi, code.quality(), clock.fps())
print("Barcode {}, Payload \"{}\", rotation {} (degrees), quality {}, FPS {}".format(*print_args))
green_led.on()
for c in code.payload():
buf = bytearray(8)
buf[0] = 0x00 # no modifier keys
buf[2] = 0x17 # just send char 'T' for now
hid.send(buf)
pyb.delay(5)
buf[0] = 0x00 # no modifier keys
buf[2] = 0x00 # release key
hid.send(buf)
pyb.delay(5)
if not codes:
green_led.off()
I’ve got both of these files on an SD card with the thinking that I’d need to remove it to get back access to the internal flash.
The green light flashes when a barcode is detected, so the script seems to run fine without errors (although I’m not sure if boot.py is running beforehand), but it’s not passing an HID data to my laptop (Mac OS)
We honestly don’t support HID mode. Ibrahim however, added it I think to the firmware but it’s not something I believe if operational or tested or that we care even to add… Ibrahim, can you expand on this? Is this feature in the firmware, does it work?
I’m coming back to you because it still does not work …
I use win 7 and win10 and do not work either.
can you tell me step by step what to do. because I’m leaving an open MV cam V7 empty
I tested in the boot.py:
#boot.py
import machine
import pyb
pyb.main('main.py') # main script to run after this one
#pyb.usb_mode('VCP+MSC') # act as a serial and a storage device
pyb.usb_mode('HID')
and
#boot.py
import machine
import pyb
pyb.main('main.py') # main script to run after this one
#pyb.usb_mode('VCP+MSC') # act as a serial and a storage device
pyb.usb_mode('VCP+HID')
and
#boot.py
import machine
import pyb
pyb.main('main.py') # main script to run after this one
#pyb.usb_mode('VCP+MSC') # act as a serial and a storage device
pyb.usb_mode('VCP+HID'), hid=pyb.hid_keyboard)
and
#boot.py
import machine
import pyb
pyb.main('main.py') # main script to run after this one
#pyb.usb_mode('CDC+MSC') # act as a serial and a storage device
pyb.usb_mode('CDC+HID'), hid=pyb.hid_keyboard)
and
#boot.py
import machine
import pyb
pyb.main('main.py') # main script to run after this one
#pyb.usb_mode('CDC+MSC') # act as a serial and a storage device
pyb.usb_mode('CDC+HID')
main.py
import pyb, time
kb = pyb.USB_HID()
buf = bytearray(8)
while(True):# Sending T
# key down
buf[0] = 0x02 # LEFT_SHIFT
buf[2] = 0x17 # keycode for 't/T'
kb.send(buf)
time.sleep(10)
# key up
buf[0] = 0x00
buf[2] = 0x00
kb.send(buf)
time.sleep(1000)
This works fine on Linux, however it may need an .inf file/driver on Windows. I’ll test it and get back to you. In the mean time you should check MicroPython’s documentation or search for their driver.
Tested again on Windows 10, the keyboard works fine, and the mouse kinda works, scrolling works but I can’t move the cursor, not sure why maybe because I’m testing on a virtual machine.
Hello
Thank you for such grate device.
Tested HID mode for windows 7 and it`s working with both mouse and keyboard but at a time only one HID device showing How can we use HID mouse AND HID keyboard at same time ?
Thanks