Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    equivalent to pyb.USB_VCP() or lobo's machine.stdin_get()

    Scheduled Pinned Locked Moved MicroPython
    micropythonusb uartmachine
    4 Posts 3 Posters 724 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • philwilkinsonP Offline
      philwilkinson
      last edited by

      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.

      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @philwilkinson
        last edited by

        @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.

        1 Reply Last reply Reply Quote 0
        • rcolisteteR Offline
          rcolistete
          last edited by

          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).

          My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).

          robert-hhR 1 Reply Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @rcolistete
            last edited by

            @rcolistete You can always connect Vin via a voltage divider to a GPIO Pin.

            1 Reply Last reply Reply Quote 0

            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
            • 1 / 1
            • First post
              Last post

            Pycom on Twitter

            Pycom