At power-on, I would like to detect whether the OpenMV H7 Plus has been plugged in to a computer. Clearly it can figure this out because the green flashes for the boot loader appear only when connected to USB; they are skipped when powering from battery.
The pyb.USB_VCP().isconnected() method is not what I’m looking for; it reports whether the serial port has been connected… and it never has at the instant of power-on.
Is there a method in some class I missed or a hardware register somewhere I could look at? (I couldn’t see anything useful in pyb.info()… looks like mostly just memory management details.)
Thank you for your thoughts and suggestions!
Context, if helpful:
My application involves saving an image to the H7 Plus’s micro-SD card, then entering standby for 5 minutes (or perhaps longer).
At some point, users will need to collect these images by connecting the H7 Plus to USB and copying them from the micro-SD and then deleting the originals. I’d rather not make them remove the micro-SD card; few computers have readers built-in.
When connected to a computer, it is important not to run my usual code; entering standby would interrupt copying the images. I suspect it could also be problematic to write new images to the filesystem while the micro-SD is being read and written to by the host OS.
While plugged in to USB, I would also like to be able to look for a possible VCP connection to allow optional configuration of device parameters using a simple serial UI.
…having imported Pin from pyb, of course. With only a couple of tests, putting this at the beginning of the script seems to reliably indicate whether there was USB power at boot. (To test it’s 0 on battery, I connect USB later and check the value of usb_vbus printed in a loop.)
By the way, at first I got an error saying that “PA9” is not defined. But naming it USB_VBUS is more readable for this use anyway.
Such function is very useful to avoid the H7+ to initiate a deep sleep before user had time to connect to the IDE. However, it seems like the current firmware does not include the USB_VBUS name anymore.