Tell if USB is connected
Tell if USB is connected
Is there a way to tell if PyBoard is plugged into a computer's USB port. I'm not talking about vcp.is_connected(), since this function returns 'True' only after a session is established. I'm looking for a status indicator in the USB controller at the physical connection level. I tried various control & status registers, but with no luck so far.
Re: Tell if USB is connected
On the pyboard, VBUS from the USB connector is tired to PA9, which also has a board name of 'USB_VBUS'.
So can query the state of that pin:
So can query the state of that pin:
Code: Select all
vbus = pyb.Pin('USB_VBUS')
if vbus.value():
print('Powerd via USB'
else:
print('Not powered via USB')
Re: Tell if USB is connected
Hi Dave, thanks a lot for the hint. Now that you're telling it, I notice it in the schematics, but the name USB_VBUS for this PIN is not mentioned in the docs. So this hint is essential, and I have hoped that you would know.