前言 环境监测板开发
一、AHT20温湿度传感器数据读取
二、MQ-2燃气传感器数据读取
ppm是指part per million,同理b,t分别表示billion和trillion。. 即1ppm=10^-6数量级,类似的还有ppb,ppt等,分别是-9次和-12次。.
1.结果
三、OLED显示数据
四、环境监测系统
1.,目录:
2.代码和配置:
BUILD.gn
static_library("demo") {
sources = [
# "aht20_demo.c","aht20.c", #温湿度传感器
#"mq2_demo.c" #MQ2监测环境可燃气体
#"colorful_light_demo.c",
#"colorful_light.c",
# "human_sensor.c",
# "photosensitive.c",
#"human_sensor_light.c"
#"oled_demo.c", "oled_ssd1306.c", #显示屏上输出
"main.c", "enrionment_task.c", "aht20.c", "oled_ssd1306.c", "oled_task.c",
#"enrionment_demo.c", "oled_ssd1306.c", "aht20.c" #环境监测系统
]
include_dirs = [
"//utils/native/lite/include",
"//kernel/liteos_m/components/cmsis/2.0",
"//base/iot_hardware/interfaces/kits/wifiiot_lite",
"//foundation/communication/interfaces/kits/wifi_lite/wifiservice",
"//third_party/pahomqtt/MQTTPacket/src",
"//third_party/pahomqtt/MQTTPacket/samples",
"//vendor\hisi\hi3861\hi3861\components\at\src",
]
}
main.c
//main.c
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "ohos_init.h"
#include "cmsis_os2.h"
#include "enrionment_task.h"
#include "oled_task.h"
// #include "wifi_device.h"
// #include "lwip/netifapi.h"
// #include "lwip/api_shell.h"
//主模块
static void ems_thread(void *arg)
{
(void)arg;
printf("Environmental monitoring system running\n");
enrionmentTask();
oledTask();
} //创建线程运行主模块
void ems_entry(void)
{
osThreadAttr_t attr;
attr.name = "emaews_thread";
attr.attr_bits = 0U;
attr.cb_mem = NULL;
attr.cb_size = 0U;
attr.stack_mem = NULL;
attr.stack_size = 4096; // 4096;
attr.priority = 36;
if (osThreadNew((osThreadFunc_t)ems_thread, NULL, &attr) == NULL)
{
printf("[emaews] Falied to create LedTask!\n");
}
}
SYS_RUN(ems_entry); //注册函数,可以执行
enironment_task.c