equivalent to pyb.USB_VCP() or lobo's machine.stdin_get()
-
If you have a Pycom board running a looping script on a LiPo battery out in the field, it would be really useful for it to detect when a USB cable has been connected, and exit out of the script.
Does anyone know if there is an equivalent to Pyboard's pyb.USB_VCP() function; specifically the vcp.any function? This returns True when a USB connection is detected.
Lobo's micropython port has the machine.stdin_get() function which passes in a timeout parameter, making it non-blocking. This does not detect the USB but does allow a check if a char is entered within a time period, before continuing on with the script.
-
@rcolistete You can always connect Vin via a voltage divider to a GPIO Pin.
-
What about detecting a microUSB cable only charging LoPy + Expansion Board ?
It would be useful because only measuring the voltage of battery doesn't mean the battery is being discharging or charging (at least in the beginning of the discharging process).
-
@philwilkinson Pycom device uses an UART and not a USB peripheral for the REPL, like the Pyboard. However, what you can do is to use uart.any() to tell, whether there is a character from the UART REPL interface waiting:
from machine import UART uart=UART(0, 115200) if uart.any(): ....
That will not detect the cable, but the first character sent.
That will however not detect characters from a telnet session.
You can also connect one of the modem control signals of the USB/UART bridge to a GPIO pin.