Threading example
-
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 -
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?
-
@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 -
@robmarkcole
no, your link is for pyboardhere 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 -
This post is deleted!
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