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

    Threading example

    Scheduled Pinned Locked Moved Getting Started
    wipy 2.0
    5 Posts 3 Posters 2.0k 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.
    • R Offline
      robmarkcole
      last edited by

      Hi all, am developing a Wipy multisensor, I want to have a PIR sensor running on a background thread pinging an MQTT message when it registers motion, whilst performing other periodic sensor readings on the main thread (or vice-versa I suppose). Does anyone have a good example of this?
      Cheers
      Robin

      1 Reply Last reply Reply Quote 0
      • B Offline
        bucknall
        last edited by

        Hi @robmarkcole,

        Would using an interrupt on the PIR sensor pin be a potential solution? You could then run your main code loop and have your MQTT message sent any time that the interrupt is triggered?

        Developer Evangelist - Pycom

        R 1 Reply Last reply Reply Quote 0
        • R Offline
          robmarkcole @bucknall
          last edited by

          @bucknall Hi Alex, thanks for the advice, you are referring to https://docs.micropython.org/en/latest/pyboard/reference/isr_rules.html#isr-rules
          ? If you know of any examples that could get me started that would be a great help, as this appears quite advanced.
          Cheers

          L 1 Reply Last reply Reply Quote 0
          • L Offline
            livius @robmarkcole
            last edited by livius

            @robmarkcole
            no, your link is for pyboard

            here you have example from docs

            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)
            

            for pycom doc is here
            https://docs.pycom.io/pycom_esp32/library/machine.Pin.html#machine.Pin

            think about people first, then computers

            R 1 Reply Last reply Reply Quote 1
            • R Offline
              robmarkcole @livius
              last edited by

              This post is deleted!
              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