# USB HID mode

**URL:** <https://forums.openmv.io/t/usb-hid-mode/786>\
**Category:** OpenMV Boards\
**Created:** [June 18, 2018, 4:11am UTC](https://forums.openmv.io/t/usb-hid-mode/786 "2018-06-18T04:11:14Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![haar\_matey](https://avatars.discourse-cdn.com/v4/letter/h/f4b2a3/32.png) [@haar\_matey](https://forums.openmv.io/u/haar_matey)\
**Post date:** [June 18, 2018, 4:11am UTC](https://forums.openmv.io/t/usb-hid-mode/786/1 "2018-06-18T04:11:14Z")

</div>

Is it possible to use USB HID mode with OpenMV? It’s mentioned on this page, but I can’t seem to get it to work

[http://docs.openmv.io/library/pyb.USB\_HID.html](http://docs.openmv.io/library/pyb.USB_HID.html)

Here’s the code I’m using

```python
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()

```

And I’ve also tried it in boot.py

```python
import pyb
#pyb.usb_mode('HID', hid=pyb.hid_keyboard)
pyb.usb_mode('VCP+HID', hid=pyb.hid_keyboard)
#pyb.usb_mode('CDC+HID', hid=pyb.hid_keyboard)

```

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)

Thanks

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [June 18, 2018, 4:27am UTC](https://forums.openmv.io/t/usb-hid-mode/786/2 "2018-06-18T04:27:04Z")

</div>

HID mode is not enabled, I’ll see if I can enable it before the next release.

Note: main.py and boot.py can run from SD or Flash the same, but we don’t use boot.py so it’s ignored.

---

<div class="post-metadata">

**Author:** ![haar\_matey](https://avatars.discourse-cdn.com/v4/letter/h/f4b2a3/32.png) [@haar\_matey](https://forums.openmv.io/u/haar_matey)\
**Post date:** [June 18, 2018, 4:41am UTC](https://forums.openmv.io/t/usb-hid-mode/786/3 "2018-06-18T04:41:02Z")

</div>

Thanks that would be awesome!

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [June 18, 2018, 5:39pm UTC](https://forums.openmv.io/t/usb-hid-mode/786/4 "2018-06-18T17:39:54Z")

</div>

Mmm, the documentation generator included that file in the doc tree even though there are no links to it.

Not sure how to hide these files. I disabled them in the index but they still show up.

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [June 19, 2018, 11:53pm UTC](https://forums.openmv.io/t/usb-hid-mode/786/5 "2018-06-19T23:53:53Z")

</div>

I re-enabled boot.py, you’ll be able to use it as usual (note only VCP+MSC and VCP+HID are tested and working, I wouldn’t try anything else).

---

<div class="post-metadata">

**Author:** ![haar\_matey](https://avatars.discourse-cdn.com/v4/letter/h/f4b2a3/32.png) [@haar\_matey](https://forums.openmv.io/u/haar_matey)\
**Post date:** [June 20, 2018, 1:04am UTC](https://forums.openmv.io/t/usb-hid-mode/786/6 "2018-06-20T01:04:16Z")

</div>

Thanks iabdalkader, do I need to update firmware for this to take effect?

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [June 20, 2018, 1:39am UTC](https://forums.openmv.io/t/usb-hid-mode/786/7 "2018-06-20T01:39:51Z")

</div>

Yes from github if u don’t want to wait for the next release.

---

<div class="post-metadata">

**Author:** ![Julo7139](https://avatars.discourse-cdn.com/v4/letter/j/a183cd/32.png) [@Julo7139](https://forums.openmv.io/u/Julo7139)\
**Post date:** [July 26, 2018, 7:31pm UTC](https://forums.openmv.io/t/usb-hid-mode/786/8 "2018-07-26T19:31:00Z")

</div>

Hello i’m French  
do you have an example to send data using the mouse mode?

Thank you

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [July 27, 2018, 12:38am UTC](https://forums.openmv.io/t/usb-hid-mode/786/9 "2018-07-27T00:38:15Z")

</div>

> [@](#):
>
> Hello i’m French  
> do you have an example to send data using the mouse mode?
> 
> Thank you

[https://docs.micropython.org/en/latest/pyboard/pyboard/tutorial/usb\_mouse.html?highlight=hid](https://docs.micropython.org/en/latest/pyboard/pyboard/tutorial/usb_mouse.html?highlight=hid)

---

<div class="post-metadata">

**Author:** ![Julo7139](https://avatars.discourse-cdn.com/v4/letter/j/a183cd/32.png) [@Julo7139](https://forums.openmv.io/u/Julo7139)\
**Post date:** [July 27, 2018, 5:46pm UTC](https://forums.openmv.io/t/usb-hid-mode/786/10 "2018-07-27T17:46:36Z")

</div>

Hello,

- i’m use google translate

I add in my file (boot.txt) this program:

**Boot.py**

```python
import pyb
pyb.main ('main.py') # main script to run after this one
# pyb.usb_mode ('VCP + MSC')
pyb.usb_mode ('VCP + HID')

```

then I renamed my file (boot.txt) =\> (boot.py)

then I add in my OpenMV IDE this program:

**OpenMV IDE**

```python
import pyb
hid = pyb.USB_HID ()

while (true):
     hid.send ((0, 10, 0, 0))

```

No other result … the mouse does not move …

Can you tell me what I’m doing wrong?

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [July 27, 2018, 7:07pm UTC](https://forums.openmv.io/t/usb-hid-mode/786/11 "2018-07-27T19:07:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [July 31, 2018, 2:59am UTC](https://forums.openmv.io/t/usb-hid-mode/786/12 "2018-07-31T02:59:27Z")

</div>

Hi, no I didn’t test it I just enabled it. I’ll test it and get back to you.

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [August 6, 2018, 1:05am UTC](https://forums.openmv.io/t/usb-hid-mode/786/13 "2018-08-06T01:05:32Z")

</div>

> [@](#):
>
> Hello,
> 
> - i’m use google translate
> 
> I add in my file (boot.txt) this program:
> 
> **Boot.py**
> 
> ```python
> import pyb
> pyb.main ('main.py') # main script to run after this one
> # pyb.usb_mode ('VCP + MSC')
> pyb.usb_mode ('VCP + HID')
> 
> ```
> 
> then I renamed my file (boot.txt) =\> (boot.py)
> 
> then I add in my OpenMV IDE this program:
> 
> **OpenMV IDE**
> 
> ```python
> import pyb
> hid = pyb.USB_HID ()
> 
> while (true):
> hid.send ((0, 10, 0, 0))
> 
> ```
> 
> No other result … the mouse does not move …
> 
> Can you tell me what I’m doing wrong?

Hi I just test HID and it’s working. The problem is with your script, you’re sending bytes in the wrong order. This script works:

```python
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)

```

Please read MicroPython’s tutorial first to understand how HID works:

> **[Home](https://github.com/micropython/micropython/wiki)**
>
> MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems - micropython/micropython

---

<div class="post-metadata">

**Author:** ![Julo7139](https://avatars.discourse-cdn.com/v4/letter/j/a183cd/32.png) [@Julo7139](https://forums.openmv.io/u/Julo7139)\
**Post date:** [August 20, 2018, 8:09am UTC](https://forums.openmv.io/t/usb-hid-mode/786/14 "2018-08-20T08:09:47Z")

</div>

Hello,

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:

```python
#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

```python
#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

```python
#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

```python
#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

```python
#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

```python
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)

```

but nothing works…

I am blocked

thank you verry much for help

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [August 20, 2018, 10:54pm UTC](https://forums.openmv.io/t/usb-hid-mode/786/15 "2018-08-20T22:54:38Z")

</div>

Hi,

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.

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [August 21, 2018, 3:02pm UTC](https://forums.openmv.io/t/usb-hid-mode/786/16 "2018-08-21T15:02:14Z")

</div>

Hi,

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.

Please follow this example:

[https://github.com/openmv/openmv/blob/master/scripts/examples/02-Board-Control/hid.py](https://github.com/openmv/openmv/blob/master/scripts/examples/02-Board-Control/hid.py)

Make sure that you see a new HID mouse in the device manager:  
 ![Screenshot from 2018-08-21 16-49-54.png](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/1X/7b29c8f1c83dd3f0a5b611b43230f94062c072df.png)

---

<div class="post-metadata">

**Author:** ![oelalfey](https://avatars.discourse-cdn.com/v4/letter/o/9fc348/32.png) [@oelalfey](https://forums.openmv.io/u/oelalfey)\
**Post date:** [August 23, 2018, 2:18am UTC](https://forums.openmv.io/t/usb-hid-mode/786/17 "2018-08-23T02:18:30Z")

</div>

Hi, I tested HID mode on Windows 7, and I can confirm it’s working. This is what I did:

1)First copy the following code to new file and name it boot.py

```python
import pyb #(UNCOMMENT THIS LINE!)
pyb.usb_mode('VCP+HID') # serial device + mouse (UNCOMMENT THIS LINE!)
#pyb.usb_mode('VCP+MSC') # serial device + storage device (default)
#pyb.usb_mode('VCP+HID', hid=pyb.hid_keyboard) # serial device + keyboard

```

2)copy boot.py to SD card

3)wait until the file is copied and then restart the camera.

4)run the following code on the OpenMV IDE

```python
import pyb, time

hid = pyb.USB_HID()

while(True):
    # x, y and scroll
    # move 10 pixels to the right
    hid.send((0, 10, 0, 0))
    time.sleep(500)

```

Check my video on youtube [test - YouTube](https://youtu.be/gUnpAMd1Dls)

---

<div class="post-metadata">

**Author:** ![umang](https://avatars.discourse-cdn.com/v4/letter/u/db5fbb/32.png) [@umang](https://forums.openmv.io/u/umang)\
**Post date:** [November 22, 2018, 9:32am UTC](https://forums.openmv.io/t/usb-hid-mode/786/18 "2018-11-22T09:32:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [November 22, 2018, 10:19pm UTC](https://forums.openmv.io/t/usb-hid-mode/786/19 "2018-11-22T22:19:35Z")

</div>

> [@](#):
>
> 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

I don’t think that’s possible, mouse and keyboard have different USB descriptors you have to choose one before the camera runs.

---

<div class="post-metadata">

**Author:** ![umang](https://avatars.discourse-cdn.com/v4/letter/u/db5fbb/32.png) [@umang](https://forums.openmv.io/u/umang)\
**Post date:** [February 27, 2019, 10:22am UTC](https://forums.openmv.io/t/usb-hid-mode/786/20 "2019-02-27T10:22:49Z")

</div>

> [@](#):
>
> > [@](#):
> >
> > 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
> 
> I don’t think that’s possible, mouse and keyboard have different USB descriptors you have to choose one before the camera runs.

Hello  
Is It possible to write Custom USB descriptors for Device(openMV) to combine HID mouse and HID keyboard ???

[Next page](https://forums.openmv.io/t/usb-hid-mode/786.md?page=2)
