Pysense wake on pin enhancements



  • Hi all,

    The project we work on involves detecting presence in a room with PIR motion detectors coupled with a LoPy and Pysense.

    We currently use PIRs that can keep the signal high for a configurable duration, which will be extended as further motion is detected, so the signal will only go down after inactivity for that duration.

    This works pretty well, but there are several issues we're facing:

    • the delay is configured via potentiometers on the PIR, so we cannot adjust it remotely
    • the max delay is about 10 minutes, which in some scenarios is not necessarily long enough
    • the PIRs we are using have limited sensitivity and relatively high current consumption compared to other PIRs available on the market. But those "better" PIRs do not have that logic and will just keep the signal high as long as there's actual movement.

    For these reasons, I would like to implement the "stay high for duration X, and extend if further motion is detected" behaviour in software rather than in hardware.

    Given the pretty high power draw of the LoPy when it is active, we can't just have wake up the LoPy every time there's movement, so I would like to have the Pysense PIC do most of the work. However, we don't have access to the PIC firmware source code (hint, hint). I previously disassembled earlier versions of the firmware for fixes, but it's really time consuming, so I'd rather have you do it (unless you can share the sources).

    The idea would be to add the following features for wake on pin:

    • expose the following configuration variables:
      • add a setting for a hold duration (in seconds, 16-bit int). 0 means keep the current behaviour
      • add a setting for a retrigger flag
      • add settings for wake_on_rise and wake_on_fall
    • add an internal armed flag (initially false)
    • add an active flag which can be read (this is the "output" of the logic below), initially false
    • set INTEDG to true
    • set INTE to true
    • when INT goes up:
      • set INTEDG to false
      • if active is false:
        • set active to true
        • if wake_on_rise, trigger LoPy wake up, reason WAKE_REASON_INT_PIN_RISE
      • else:
        • don't change active
        • don't wake up the LoPy
        • if retrigger is true and hold is non-0
          • cancel the timer
          • clear armed
    • when INT goes down:
      • set INTEDG to true
      • if hold is 0:
        • set active to false
        • if wake_on_fall, wake-up the LoPy, reason WAKE_REASON_INT_PIN_FALL
      • else if active is true and armed is false:
        • set the timer to hold
        • set armed to true
    • when the timer expires:
      • set active to false
      • set armed to false
      • if wake_on_fall, wake up the LoPy, reason WAKE_REASON_INT_PIN_FALL

    The only issue I see is the timer... As far as I understand it, only the WDT and Timer1 are available during the PIC sleep, and I'm not sure which one is used for timer wake-up. If the same timer needs to be shared between timer wake up and the logic above, this will add quite a bit more work to keep both functionalities.

    Feedback welcome.

    Thanks!



Pycom on Twitter