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

    What is the extension board button right id?

    Scheduled Pinned Locked Moved WiPy 2&3
    wipy2.0expansion board
    8 Posts 2 Posters 2.7k 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.
    • C Offline
      ColombianAus
      last edited by

      Hello There,

      I am trying to use the button from the Extension board, so I have written the following code:

      #Pin.IN/Pin.OUT using RGB LED

      Autor: XXXXX

      from machine import Pin
      import pycom
      pycom.heartbeat(False)

      #Inputs Pins
      pin_i1 = Pin('G17', mode=Pin.IN, value=None)
      #Output Pins

      while (True):
      #Review pin_i1
      if pin_i1.value() != 1:
      pycom.rgbled(0x007f00) # green
      else:
      pycom.rgbled((0x7f0000) # red

      it is not working, does not do anything. Can anyone confirm if I have addressed the right pin in the extension boar (G17)?

      if I measure voltage between GND and G10, its 3.3V, and it does not matter if I press button on/off, 3.3V value still there.

      Cheers
      Colombian1976

      1 Reply Last reply Reply Quote 0
      • RobTuDelftR Offline
        RobTuDelft
        last edited by RobTuDelft

        The user button on the expansion board is indeed P10 - G17.

        Are you trying to set a value for an input pin (value=None)?

        With ````you can make a code block:

        from machine import Pin
        import pycom
        pycom.heartbeat(False)
        
        #Inputs Pins
        pin_i1 = Pin('G17', mode=Pin.IN, value=None)
        #Output Pins
        
        while (True):
            #Review pin_i1
            if pin_i1.value() != 1:
               pycom.rgbled(0x007f00) # green
            else:
               pycom.rgbled((0x7f0000) # red
        

        Without data you're just another person with an opinion.
        Hackster | About me

        C 2 Replies Last reply Reply Quote 0
        • C Offline
          ColombianAus @RobTuDelft
          last edited by

          @RobTuDelft

          hey Rob,

          Thank you for your reply mate.

          yes, I am trying to set use expansion board button to activate RGB LED. ..I did try to set up value to PIN.PULL_UP, but no change...and as I mentioned on my initial post, how weird that I measure voltage from P10 to GND and it is 3.3V all the time, no matter if the button is press or not.

          Great suggestion about the code block, trying to find a suitable coding standard....:-)

          Cheers
          Colombian

          1 Reply Last reply Reply Quote 0
          • C Offline
            ColombianAus @RobTuDelft
            last edited by livius

            @RobTuDelft

            Hello Rob,

            I think that I have made some progress :-). now I have following program

            from machine import Pin
            import pycom
            pycom.heartbeat(False)
            
            #Inputs Pins
            pin_i1 = Pin('GP1', mode=Pin.IN, value=PULL_UP)
            #Output Pins
            
            while (True):
            	#Revisar pin_i1 
            	if pin_i1.value() != 1:
             		pycom.rgbled(0x007f00) # green
            	else:
            		pycom.rgbled((0x7f0000) # red
            

            so...I have changed from my input pin to G1, (P0) in the board. AND connected a cable from G17 to G1. I still don't see my program working but...I'll get there :-)

            Cheers
            Colombian

            RobTuDelftR 1 Reply Last reply Reply Quote 0
            • RobTuDelftR Offline
              RobTuDelft @ColombianAus
              last edited by

              @ColombianAus

              Glad you are making progress!
              To help you a little bit, this example should probably work for you (didn't test it):

              import time
              from machine import Pin
              import os
              import machine
              import pycom
              
              
              uart = machine.UART(0, 115200)
              os.dupterm(uart)
              
              pycom.heartbeat(False)
              
              
              def toggle_rgbled(arg):
                  pycom.rgbled(0xff)
                  time.sleep(2)
                  pycom.rgbled(0)
                  
              
              button = Pin('P10', mode=Pin.IN, pull=Pin.PULL_UP)
              button.callback(Pin.IRQ_RISING, toggle_rgbled)
              

              Without data you're just another person with an opinion.
              Hackster | About me

              C 1 Reply Last reply Reply Quote 1
              • C Offline
                ColombianAus @RobTuDelft
                last edited by

                @RobTuDelft

                Hey

                Thank you very much for your assistance, your code works like a charm. I guess (and please correct me if I am wrong), the way you deal with Inputs in WiPy will be with interrupts? and not the way I was doing it..

                Cheers
                Colombian

                RobTuDelftR 1 Reply Last reply Reply Quote 0
                • RobTuDelftR Offline
                  RobTuDelft @ColombianAus
                  last edited by

                  @ColombianAus With callbacks you are assured that you always capture the event. I think that is the main advantage. Up to 16 events can be queued this way. Using a loop is also possible of course, but then it might interfere with other processes.

                  Without data you're just another person with an opinion.
                  Hackster | About me

                  C 1 Reply Last reply Reply Quote 0
                  • C Offline
                    ColombianAus @RobTuDelft
                    last edited by

                    @RobTuDelft ok fair enough. so Following code should work right?

                    import time
                    from machine import Pin
                    import machine
                    import pycom

                    pycom.heartbeat(False)

                    def toggle_rgbled_blue(arg):
                    pycom.rgbled(0xff)
                    time.sleep(2)
                    pycom.rgbled(0)

                    def toggle_rbgled_red(arg):
                    pycom.rgbled(0x7f0000)
                    time.sleep(2)
                    pycom.rgbled(0)

                    button_blue = Pin('P10', mode=Pin.IN, pull=Pin.PULL_UP)
                    button_blue.callback(Pin.IRQ_RISING, toggle_rgbled_blue)

                    buton_red = Pin('P0', mode=Pin.IN, pull=Pin.PULL_UP)
                    button_red.callback(Pin.IRQ_RISING, toggle_rgbled_red)

                    Cheers
                    Colombian

                    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