Detecting Pyboard D and USB connection SOLVED
Posted: Wed Apr 03, 2019 3:07 pm
Two questions. What is the best way programmatically to detect a Pyboard D as distinct from a V1.x board.
Secondly I want to detect the presence of a USB connection to either the HS or FS port on the 'D' or to the USB port on a Pyboard 1.x. At present I have
Is this right? Is there a better way?
Secondly I want to detect the presence of a USB connection to either the HS or FS port on the 'D' or to the USB port on a Pyboard 1.x. At present I have
Code: Select all
mode = pyb.usb_mode()
if mode is None:
# ignore this bit of code
elif 'VCP' in mode: # User has enabled VCP in boot.py: establish if there is a physical connection
usb_conn = pyb.Pin.board.USB_VBUS.value() # USB is connected to pyb V1.x
if not usb_conn:
usb_conn = hasattr(pyb.Pin.board, 'USB_HS_DP') and pyb.Pin.board.USB_HS_DP.value()
if not usb_conn:
usb_conn = hasattr(pyb.Pin.board, 'USB_DP') and pyb.Pin.board.USB_DP.value()