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

    is there a way to check an output pin HIGH or LOW ?

    Scheduled Pinned Locked Moved LoPy
    lopy4pinout
    4 Posts 2 Posters 310 Views 2 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.
    • S Offline
      soibac35
      last edited by soibac35

      when i turn on or set high to an output pin in LOPY4, is there a way to confirm it sets to HIGH or LOW without physically check the pin ?

      I turn on pin high by using these 2 lines of code:

      pin = Pin(str(pinNumber), mode=Pin.OUT)
      pin.value(1)
      
      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @soibac35
        last edited by robert-hh

        @soibac35 If pinNumer is a number, then str(pinNumber) does not result in a valid pin name. Instead you should get an error message:
        ValueError: invalid argument(s) value
        You could use something like;
        'P%d' % pinNumber or
        'P' + str(pinNumber)
        But about your question: you can always read back the Pin's state with pin.value(), even when set to OUT mode.

        S 1 Reply Last reply Reply Quote 0
        • S Offline
          soibac35 @robert-hh
          last edited by

          @robert-hh Perfect. That's all i need to know. Thank you.

          For pinNumber thou, i will have something like

          def turnOFF(pinNumber):
              pin = Pin(str(pinNumber), mode=Pin.OUT)
              pin.value(0)
          

          where I input pinNumber as P23 or P24...

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

            @soibac35 if pinNumber is already a string, you do not need str(pinNumber).

            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