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

    Pin Interrupt not working as expected

    Scheduled Pinned Locked Moved Getting Started
    3 Posts 2 Posters 61 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.
    • J Offline
      jackalope
      last edited by jackalope

      My Apologies if this is answered elsewhere. But I'm running into an odd issue that with my Lopy4 and expansion board. I'm setting up a pin with a callback and regardless of what trigger I use it immediately fires off and not again afterwards. Running the following code will immediately kick off the testing() function, if I press the back_button I can confirm its value goes from 1 to 0 but doesn't fire the callback. I've tried low_level, high_level, rising and falling values for the trigger. All behave the same.

      from machine import I2C, Pin
      import time
      
      
      def testing():
          print("test function")
      
      
      back_button = Pin('P8', Pin.IN, Pin.PULL_UP)
      
      back_button.callback(Pin.IRQ_FALLING, testing())
      
      

      For cabling I have a simple button going to P8 on one side and ground on the other.

      Calling the callback from the repl returns the following which I'm not sure is expected behavior or not.

      >>> back_button.callback(Pin.IRQ_FALLING, testing())
      test function
      

      Lopy version info:
      Pycom MicroPython 1.20.2.r1 [v1.11-a5aa0b8] on 2020-09-09; LoPy4 with ESP32
      Pybytes Version: 1.6.0

      Thank you in advance!

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

        @jackalope remove the (). You want to pass the function, not the result of calling that function.

        1 Reply Last reply Reply Quote 2
        • J Offline
          jackalope
          last edited by

          @jcaron, I'm such a fool. I had a feeling it had to be something stupid simple. Thank you!

          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