OpenHarmony輕量系統(tǒng)—潤和HiHope3861 UDP廣播人體傳感器數(shù)據(jù)
1、UDP廣播人體紅外傳感器數(shù)據(jù) 樣例運行效果
人體紅外感應器感應到人體后,通過UDP廣播 數(shù)據(jù)1(否則為0)。
注意:炫彩燈板上人體紅外感應傳感器響應速度比較慢。
樣例運行效果演示視頻 :https://gitee.com/from-north-to-north/open-armony-north/blob/master/潤和3861輕量系統(tǒng)UDP廣播人體紅外傳感器/潤和3861輕量系統(tǒng)UDP廣播人體紅外傳感器 效果演示視頻.mp4
2、運行步驟
(1)下載 https://gitee.com/from-north-to-north/open-armony-north/tree/master/潤和3861輕量系統(tǒng)UDP廣播人體紅外傳感器 ,將BUILD.gn、udp_broadcast_human_infrared_demo.c、wifi_connecter.c、wifi_connecter.c、wifi_connecter.h、文件放置在命名為 udp_broadcast_human_infrared 的文件夾下,將其放置在OpenHarmony輕量系統(tǒng)源碼 applications\sample\wifi-iot\app目錄下。
(2)在源碼 applications\sample\wifi-iot\app\BUILD.gn文件features 字段下添加"udp_broadcast_human_infrared:udp_broadcast_human_infrared_demo",使樣例demo加入編譯。
(3)在樣例demo的udp_broadcast_human_infrared_demo.c中設置要連接的wifi信息.
編譯燒錄后在pc端使用tcp/udp調試工具 SocketTool 創(chuàng)建udp group。組播地址為255.255.255.255,組播端口為8080。
3、炫彩燈板上人體紅外感應傳感器與主控芯片(Pegasus)引腳的對應關系
人體紅外傳感器——ADC采集值反應是否有人靠近 GPIO07: ADC3。
查看硬件原理圖可知 炫彩燈拓展板上的人體紅外感應傳感器型號為AS312,REL引腳查看底板硬件圖可知 通過GPIO 07連接到Hi3861v100芯片。(VDD表示工作正電壓,VSS表示工作負電壓)。
4、樣例源碼解析
// 人體紅外感應傳感器使用到的頭文件
#include "hi_gpio.h"
#include "hi_io.h"
#include "hi_adc.h"
#include "hi_errno.h"
// 用hi_adc_read讀取ADC通道的值
hi_u16 value = 0 ;
hi_adc_read(HI_ADC_CHANNEL_3, &value,HI_ADC_EQU_MODEL_4, HI_ADC_CUR_BAIS_AUTO, 0) ;
// (unsigned int)value 將value由hi_u16轉換為unsigned int類型
printf("ADC_VALUE = %u\n", (unsigned int)value);
// 人體紅外感應傳感器檢測到人體時,ADC通道的值大于950,udp廣播1
char *i;
if(value > 950){
i="1";
}else{
i="0";
}
// udp發(fā)送數(shù)據(jù)
ret = sendto(sock_fd, i, strlen(i), 0, (struct sockaddr *) &broadcast_addr, broadcast_addr_len);
5. 附贈: 潤和3861 UDP廣播可燃氣體傳感器樣例下載鏈接。
https://gitee.com/from-north-to-north/open-armony-north/tree/master/潤和3861輕量系統(tǒng)UDP廣播可燃氣體傳感器