Can't use VCP+HID mode

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
nedkonz
Posts: 24
Joined: Thu Aug 05, 2021 9:58 pm

Can't use VCP+HID mode

Post by nedkonz » Thu Dec 16, 2021 6:45 pm

I have a Pyboard v1.1 and have loaded firmware v1.17.
When I do this:

Code: Select all

>>> import pyb
>>> pyb.usb_mode()
'VCP+MSC'
>>> pyb.usb_mode('VCP+HID')
>>> pyb.usb_mode()
'VCP+MSC'
I see that the usb mode has not changed.
Am I missing something obvious?
Should this work?
I have also tried this code in boot.py.
Thanks!

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Can't use VCP+HID mode

Post by dhylands » Thu Dec 16, 2021 9:00 pm

You need to change usb_mode in boot.py. Changing it in main.py or later (like in the REPL) has no effect.

nedkonz
Posts: 24
Joined: Thu Aug 05, 2021 9:58 pm

Re: Can't use VCP+HID mode

Post by nedkonz » Thu Dec 16, 2021 9:22 pm

dhylands wrote:
Thu Dec 16, 2021 9:00 pm
You need to change usb_mode in boot.py. Changing it in main.py or later (like in the REPL) has no effect.
I've done this and it doesn't work. Here's my boot.py:

Code: Select all

# boot.py -- run on boot-up
import pyb
pyb.country('US') # ISO 3166-1 Alpha-2 code, eg US, GB, DE, AU
#pyb.main('main.py') # main script to run after this oneice
pyb.usb_mode('VCP+HID') # act as a serial device and a mouse

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Can't use VCP+HID mode

Post by dhylands » Thu Dec 16, 2021 10:39 pm

That worked for me. I had to unplug and replug the Pyboard. I happen to be running 1.15:

Code: Select all

MicroPython v1.15-126-g29718221d-dirty on 2021-05-18; PYBv1.1 with STM32F405RG
Type "help()" for more information.
>>> pyb.usb_mode()
'VCP+HID'
>>> 
I get the same results on 1.17:

Code: Select all

MicroPython v1.17-123-g7f1434442 on 2021-12-16; PYBv1.1 with STM32F405RG
Type "help()" for more information.
>>> 
>>> pyb.usb_mode()
'VCP+HID'
>>> 

nedkonz
Posts: 24
Joined: Thu Aug 05, 2021 9:58 pm

Re: Can't use VCP+HID mode

Post by nedkonz » Thu Dec 16, 2021 11:22 pm

Thanks!

I figured out what happened: I had a blank micro SD card installed, and therefore my /flash/boot.py wasn't being loaded.

Now to figure out how to set up the descriptor for a joystick...

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Can't use VCP+HID mode

Post by dhylands » Fri Dec 17, 2021 12:07 am

This may have some clues for you: viewtopic.php?f=2&t=7170&p=40980#p40755

nedkonz
Posts: 24
Joined: Thu Aug 05, 2021 9:58 pm

Re: Can't use VCP+HID mode

Post by nedkonz » Fri Dec 17, 2021 1:59 am

Thanks.

I just made a simple 3-axis (X,Y,Z) joystick emulator. Here's my code in boot.py:

Code: Select all

# simple joystick with 8-bit x,y,z
pyb.usb_mode('VCP+HID', hid=(1, 2, 3, 8, bytes([0x05, 0x01, 0x09, 0x04, 0xa1, 0x01, 0x09, 0x01, 0xa1, 0x00, 0x09, 0x30, 0x09, 0x31, 0x09, 0x32, 0x25, 0x7f, 0x15, 0x81, 0x75, 0x08, 0x95, 0x03, 0x81, 0x02, 0xc0, 0xc0])))

# Send joystick report. Values are -127 to +127.
# hid = pyb.USB_HID()
# hid.send((x, y, z))
I see the three axis values in Linux; haven't bothered to test it in Windows.

Post Reply