• Home
Name Date Size #Lines LOC

..--

include/12-May-2024-3918

src/12-May-2024-8943

BUILD.gnD12-May-2024911 2623

README.mdD12-May-20242.6 KiB8961

e53_is1_example.cD12-May-20241.9 KiB7551

README.md

1# BearPi-HM_Nano开发板传感器驱动开发——E53_IS1人体红外感应
2本示例将演示如何在BearPi-HM_Nano开发板上使用E53_IS1实现人体红外感应,当检测到有人走动时,蜂鸣器发出报警,设备安装如下图所示。
3
4![](../../docs/figures/C5_e53_is1_infrared/E53_IS1安装.png "E53_IS1安装")
5## E53_IS1 API分析
6本案例主要使用了以下API完成人体红外感应。
7### E53IS1Init()
8```C
9void E53IS1Init(void);
10```
11 **描述:**
12
13初始化E53_IS1。
14
15### E53IS1ReadData()
16```C
17void E53IS1ReadData(E53IS1CallbackFunc func);
18```
19 **描述:**
20
21设置人体感应触发的回调函数。
22
23
24
25
26## 硬件设计
27本案例将用到 E53_IS1 红外感应扩展板与 BearPi-HM_Nano 开发板,其中E53_IS1扩展板原理图如下,当检测到人时,传感器会输出高电平,通过对GPIO_7的监测就能判断是否有人走动。
28
29![](../../docs/figures/C5_e53_is1_infrared/E53_IS1接口.png "E53_IS1接口")
30
31![](../../docs/figures/C5_e53_is1_infrared/E53接口电路.png "E53接口电路")
32
33E53_IS1 红外感应扩展板与 BearPi-HM_Nano 开发板安装如下图所示
34
35![](../../docs/figures/C5_e53_is1_infrared/E53_IS1安装.png "E53_IS1安装")
36## 软件设计
37
38**主要代码分析**
39
40
41首先调用 `E53IS1Init()` 函数初始化E53_SC1所接的引脚的功能,然后调用 `E53IS1ReadData()` BeepAlarm(),系统启动后会通过osEventFlagsWait()函数让ExampleTask任务一直等待事件标志位FLAGS_MSK1,当检测到人后,BeepAlarm()函数会发送事件标志位,ExampleTask任务继续运行开启蜂鸣器报警3秒钟 然后关闭蜂鸣器继续等待下一次触发事件。
42```C
43static void BeepAlarm(char *arg)
44{
45    (void)arg;
46    osEventFlagsSet(g_eventFlagsId, FLAGS_MSK1);
47}
48
49static void ExampleTask(void)
50{
51    int ret;
52    E53IS1Init();
53    ret = E53IS1ReadData(BeepAlarm);
54    if (ret != 0) {
55        printf("E53_IS1 Read Data failed!\r\n");
56        return;
57    }
58    while (1) {
59        osEventFlagsWait(g_eventFlagsId, FLAGS_MSK1, osFlagsWaitAny, osWaitForever);
60        BeepStatusSet(ON);
61        osDelay(TASK_DELAY_3S);
62        BeepStatusSet(OFF);
63    }
64}
65```
66
67
68
69## 编译调试
70
71### 修改 BUILD.gn 文件
72修改`device\bearpi\bearpi_hm_nano\app`路径下 BUILD.gn 文件,指定 `e53_is1_example` 参与编译。
73```r
74#"C1_e53_sf1_mq2:e53_sf1_example",
75#"C2_e53_ia1_temp_humi_pls:e53_ia1_example",
76#"C3_e53_sc1_pls:e53_sc1_example",
77#"C4_e53_sc2_axis:e53_sc2_example",
78"C5_e53_is1_infrared:e53_is1_example",
79```
80
81
82
83
84### 运行结果
85
86示例代码编译烧录代码后,按下开发板的RESET按键,人员靠近开发板,蜂鸣器开始报警。
87
88
89