PIR Unit

Support the following products:

PIR

Micropython Example:

 1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8from unit import PIRUnit
 9
10
11label0 = None
12pir_0 = None
13
14
15def pir_0_active_event(pir):
16    global label0, pir_0
17    label0.setText(str("Detected"))
18
19
20def pir_0_negative_event(pir):
21    global label0, pir_0
22    label0.setText(str("Not detected"))
23
24
25def setup():
26    global label0, pir_0
27
28    M5.begin()
29    Widgets.fillScreen(0x222222)
30    label0 = Widgets.Label("label0", 132, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
31
32    pir_0 = PIRUnit((36, 26))
33    pir_0.set_callback(pir_0_active_event, pir_0.IRQ_ACTIVE)
34    pir_0.set_callback(pir_0_negative_event, pir_0.IRQ_NEGATIVE)
35    pir_0.enable_irq()
36
37
38def loop():
39    global label0, pir_0
40    M5.update()
41
42
43if __name__ == "__main__":
44    try:
45        setup()
46        while True:
47            loop()
48    except (Exception, KeyboardInterrupt) as e:
49        try:
50            from utility import print_error_msg
51
52            print_error_msg(e)
53        except ImportError:
54            print("please update to latest firmware")

UIFLOW2 Example:

example.png

pir_core_example.m5f2

class PIR

Constructors

class PIR(IO1, IO2)

Create a PIR object.

The parameters are:
  • IO1,IO2 I2C pin.

UIFLOW2:

init.png

Methods

PIR.get_status()

Get detection status.

UIFLOW2:

get_status.png

PIR.enable_irq()

Enable Human detection function.

UIFLOW2:

enable_irq.png

PIR.disable_irq()

Disable Human detection function.

UIFLOW2:

disable_irq.png

PIR.set_callback()

Polling method, placed in the loop function, constantly check.

UIFLOW2:

set_callback.png