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

    LoPy4 Interrupts for button

    Scheduled Pinned Locked Moved LoPy
    interruptslopy4debounce
    4 Posts 3 Posters 912 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.
    • P Offline
      PyBuggz
      last edited by

      Hi,
      tried the example at https://docs.pycom.io/firmwareapi/pycom/machine/pin#methods

      from machine import Pin
      ​
      def pin_handler(arg):
         print("got an interrupt in pin %s" % (arg.id()))
      ​
      p_in = Pin('P10', mode=Pin.IN, pull=Pin.PULL_UP)
      p_in.callback(Pin.IRQ_FALLING | Pin.IRQ_RISING, pin_handler)
      

      but I get multiple responses. Is there a 'button' function or what's the correct way to debounce an input?

      Also, can I have several buttons?

      TIA Dave

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jcaron @PyBuggz
        last edited by

        @pybuggz At the very least, with this code, you'll get two calls, one when the button is pressed, another when it is released (due to IRQ_FALLING and IRQ_RISING being set).

        Do you receive more than that?

        P 1 Reply Last reply Reply Quote 0
        • E Offline
          Eric Waai
          last edited by

          i guess @jcaron have given you the answer.
          but if not. there are some software solutions to debounce inputs. best practice is to do this in hardware so it doesn't cost precious processing power.
          how do you have things wired up?
          and yes you can have more button's you can make a separate handler for them

          you get something like this:

          def pin10_handler(arg):
             print("got an interrupt in pin10 %s" % (arg.id()))
          
          def pin11_handler(arg):
             print("got an interrupt in pin11 %s" % (arg.id()))
          
          def pin12_handler(arg):
             print("got an interrupt in pin12 %s" % (arg.id()))
          ​
          p_in10 = Pin('P10', mode=Pin.IN, pull=Pin.PULL_UP)
          p_in10.callback(Pin.IRQ_FALLING | Pin.IRQ_RISING, pin10_handler)
          
          
          ​
          p_in11 = Pin('P11', mode=Pin.IN, pull=Pin.PULL_UP)
          p_in11.callback(Pin.IRQ_FALLING | Pin.IRQ_RISING, pin11_handler)
          
          
          ​
          p_in12 = Pin('P12', mode=Pin.IN, pull=Pin.PULL_UP)
          p_in12.callback(Pin.IRQ_FALLING | Pin.IRQ_RISING, pin12_handler)
          

          I didn't test it but i gues it would work

          1 Reply Last reply Reply Quote 0
          • P Offline
            PyBuggz @jcaron
            last edited by

            @jcaron Yes, I got several each press, hence the query on de-bouncing.

            As for software de-bouncing, it's just that I try not to re-invent the wheel. e.g. I'm sure the micro:bit has a 'button' type for button A and B and since the Exp3 has a user button I guess I expected something from pycom.

            Hardware wise I tried a couple of different capacitors across the pushbutton (relying on the PULLUP) with little success. I may give it some more testing.

            Dave

            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