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. -
@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. -
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). -
@rcolistete You can always connect Vin via a voltage divider to a GPIO Pin.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login