|
【HarmonyOS HiSpark Wi-Fi IoT 套件試用連連載】四、環(huán)境監(jiān)測(cè)板的使用, 今天來(lái)寫(xiě)一篇關(guān)于使用環(huán)境監(jiān)測(cè)板的帖子。主要完成溫濕度傳感器數(shù)據(jù)采集和煙霧傳感器的數(shù)據(jù)采集,然后把采集到的數(shù)據(jù)打印輸出。
一、硬件介紹
通過(guò)查看環(huán)境監(jiān)測(cè)板的原理圖,發(fā)現(xiàn)該板子主要有三個(gè)板子資源:AHT20溫濕度傳感器、MQ-2煙霧傳感器、蜂鳴器。
aht20.PNG (21.75 KB, 下載次數(shù): 0)
下載附件 保存到相冊(cè)
昨天 23:12 上傳
beep.PNG (18.57 KB, 下載次數(shù): 0)
下載附件 保存到相冊(cè)
昨天 23:12 上傳
煙霧.PNG (19.18 KB, 下載次數(shù): 0)
下載附件 保存到相冊(cè)
昨天 23:12 上傳
它們使用主控的GPIO口分別為:AHT20溫濕度傳感器
SDA --》 GPIO13 可復(fù)用為I2C0_SDA
SCL --》 GPIO14 可復(fù)用為I2C0_SCL
MQ-2煙霧傳感器
ADC --》 GPIO11
可復(fù)用為ADC5 蜂鳴器BEEP --》
GPIO9 可復(fù)用為PWM0_OUT
二、軟件設(shè)計(jì)
1、新建文件 在wifi-iot/app目錄下,新建EM文件夾,存放與環(huán)境監(jiān)測(cè)板相關(guān)的代碼。
打印輸出.PNG (20.89 KB, 下載次數(shù): 0)
下載附件 保存到相冊(cè)
昨天 23:09 上傳 在EM文件夾分別新建aht20.c、aht20.h、envrionment_demo.c和BUILD.gn文件。
上面c文件和h文件我是從許思維老師demo工程中移植過(guò)來(lái)的,然后進(jìn)行了一些修改。
2、aht20.c 該c文件主要存放與aht20傳感器操作相關(guān)的代碼
- /*
- * Copyright (c) 2020, HiHope Community.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the copyright holder nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS“
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
|
|