[文章]【HarmonyOS HiSpark Wi-Fi IoT 套件试用连连载】四、环境监测板的使用

阅读量0
推荐
0
0
`

今天来写一篇关于使用环境监测板的帖子。主要完成温湿度传感器数据采集和烟雾传感器的数据采集,然后把采集到的数据打印输出。
一、硬件介绍

通过查看环境监测板的原理图,发现该板子主要有三个板子资源:AHT20温湿度传感器、MQ-2烟雾传感器、蜂鸣器。
aht20.PNG
beep.PNG

烟雾.PNG

它们使用主控的GPIO口分别为:AHT20温湿度传感器
SDA        --》        GPIO13           可复用为I2C0_SDA
SCL        --》        GPIO14          可复用为I2C0_SCL
MQ-2烟雾传感器
ADC       --》    GPIO11           
可复用为ADC5
蜂鸣器BEEP     --》
GPIO9           可复用为PWM0_OUT

二、软件设计
1、新建文件
在wifi-iot/app目录下,新建EM文件夹,存放与环境监测板相关的代码。
新建目录.PNG
在EM文件夹分别新建aht20.c、aht20.h、envrionment_demo.c和BUILD.gn文件。
上面c文件和h文件我是从许思维老师demo工程中移植过来的,然后进行了一些修改。
2、aht20.c
该c文件主要存放与aht20传感器操作相关的代码

  1. /*
  2. * Copyright (c) 2020, HiHope Community.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * 1. Redistributions of source code must retain the above copyright notice, this
  8. *    list of conditions and the following disclaimer.
  9. *
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. *    this list of conditions and the following disclaimer in the documentation
  12. *    and/or other materials provided with the distribution.
  13. *
  14. * 3. Neither the name of the copyright holder nor the names of its
  15. *    contributors may be used to endorse or promote products derived from
  16. *    this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  24. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */

  29. #include "aht20.h"

  30. #include <stdio.h>
  31. #include <string.h>
  32. #include <unistd.h>

  33. #include "wifiiot_i2c.h"
  34. #include "wifiiot_errno.h"

  35. #define AHT20_I2C_IDX WIFI_IOT_I2C_IDX_0

  36. #define AHT20_STARTUP_TIME     20*1000 // 上电启动时间
  37. #define AHT20_CALIBRATION_TIME 40*1000 // 初始化(校准)时间
  38. #define AHT20_MEASURE_TIME     75*1000 // 测量时间

  39. #define AHT20_DEVICE_ADDR   0x38
  40. #define AHT20_READ_ADDR     ((0x38<<1)|0x1)
  41. #define AHT20_WRITE_ADDR    ((0x38<<1)|0x0)

  42. #define AHT20_CMD_CALIBRATION       0xBE // 初始化(校准)命令
  43. #define AHT20_CMD_CALIBRATION_ARG0  0x08
  44. #define AHT20_CMD_CALIBRATION_ARG1  0x00

  45. /**
  46. * 传感器在采集时需要时间,主机发出测量指令(0xAC)后,延时75毫秒以上再读取转换后的数据并判断返回的状态位是否正常。
  47. * 若状态比特位[Bit7]为0代表数据可正常读取,为1时传感器为忙状态,主机需要等待数据处理完成。
  48. **/
  49. #define AHT20_CMD_TRIGGER       0xAC // 触发测量命令
  50. #define AHT20_CMD_TRIGGER_ARG0  0x33
  51. #define AHT20_CMD_TRIGGER_ARG1  0x00

  52. // 用于在无需关闭和再次打开电源的情况下,重新启动传感器系统,软复位所需时间不超过20 毫秒
  53. #define AHT20_CMD_RESET      0xBA // 软复位命令

  54. #define AHT20_CMD_STATUS     0x71 // 获取状态命令

  55. /**
  56. * STATUS 命令回复:
  57. * 1. 初始化后触发测量之前,STATUS 只回复 1B 状态值;
  58. * 2. 触发测量之后,STATUS 回复6B: 1B 状态值 + 2B 湿度 + 4b湿度 + 4b温度 + 2B 温度
  59. *      RH = Srh / 2^20 * 100%
  60. *      T  = St  / 2^20 * 200 - 50
  61. **/
  62. #define AHT20_STATUS_BUSY_SHIFT 7       // bit[7] Busy indication
  63. #define AHT20_STATUS_BUSY_MASK  (0x1<<AHT20_STATUS_BUSY_SHIFT)
  64. #define AHT20_STATUS_BUSY(status) ((status & AHT20_STATUS_BUSY_MASK) >> AHT20_STATUS_BUSY_SHIFT)

  65. #define AHT20_STATUS_MODE_SHIFT 5       // bit[6:5] Mode Status
  66. #define AHT20_STATUS_MODE_MASK  (0x3<<AHT20_STATUS_MODE_SHIFT)
  67. #define AHT20_STATUS_MODE(status) ((status & AHT20_STATUS_MODE_MASK) >> AHT20_STATUS_MODE_SHIFT)

  68.                                         // bit[4] Reserved
  69. #define AHT20_STATUS_CALI_SHIFT 3       // bit[3] CAL Enable
  70. #define AHT20_STATUS_CALI_MASK  (0x1<<AHT20_STATUS_CALI_SHIFT)
  71. #define AHT20_STATUS_CALI(status) ((status & AHT20_STATUS_CALI_MASK) >> AHT20_STATUS_CALI_SHIFT)
  72.                                         // bit[2:0] Reserved

  73. #define AHT20_STATUS_RESPONSE_MAX 6

  74. #define AHT20_RESLUTION            (1<<20)  // 2^20

  75. #define AHT20_MAX_RETRY 10

  76. static uint32_t AHT20_Read(uint8_t* buffer, uint32_t buffLen)
  77. {
  78.     WifiIotI2cData data = { 0 };
  79.     data.receiveBuf = buffer;
  80.     data.receiveLen = buffLen;
  81.     uint32_t retval = I2cRead(AHT20_I2C_IDX, AHT20_READ_ADDR, &data);
  82.     if (retval != WIFI_IOT_SUCCESS) {
  83.         printf("I2cRead() failed, %0X!
  84. ", retval);
  85.         return retval;
  86.     }
  87.     return WIFI_IOT_SUCCESS;
  88. }

  89. static uint32_t AHT20_Write(uint8_t* buffer, uint32_t buffLen)
  90. {
  91.     WifiIotI2cData data = { 0 };
  92.     data.sendBuf = buffer;
  93.     data.sendLen = buffLen;
  94.     uint32_t retval = I2cWrite(AHT20_I2C_IDX, AHT20_WRITE_ADDR, &data);
  95.     if (retval != WIFI_IOT_SUCCESS) {
  96.         printf("I2cWrite(%02X) failed, %0X!
  97. ", buffer[0], retval);
  98.         return retval;
  99.     }
  100.     return WIFI_IOT_SUCCESS;
  101. }

  102. // 发送获取状态命令
  103. static uint32_t AHT20_StatusCommand(void)
  104. {
  105.     uint8_t statusCmd[] = { AHT20_CMD_STATUS };
  106.     return AHT20_Write(statusCmd, sizeof(statusCmd));
  107. }

  108. // 发送软复位命令
  109. static uint32_t AHT20_ResetCommand(void)
  110. {
  111.     uint8_t resetCmd[] = {AHT20_CMD_RESET};
  112.     return AHT20_Write(resetCmd, sizeof(resetCmd));
  113. }

  114. // 发送初始化校准命令
  115. static uint32_t AHT20_CalibrateCommand(void)
  116. {
  117.     uint8_t clibrateCmd[] = {AHT20_CMD_CALIBRATION, AHT20_CMD_CALIBRATION_ARG0, AHT20_CMD_CALIBRATION_ARG1};
  118.     return AHT20_Write(clibrateCmd, sizeof(clibrateCmd));
  119. }

  120. // 读取温湿度值之前, 首先要看状态字的校准使能位Bit[3]是否为 1(通过发送0x71可以获取一个字节的状态字),
  121. // 如果不为1,要发送0xBE命令(初始化),此命令参数有两个字节, 第一个字节为0x08,第二个字节为0x00。
  122. uint32_t AHT20_Calibrate(void)
  123. {
  124.     uint32_t retval = 0;
  125.     uint8_t buffer[AHT20_STATUS_RESPONSE_MAX] = { AHT20_CMD_STATUS };
  126.     memset(&buffer, 0x0, sizeof(buffer));

  127.     retval = AHT20_StatusCommand();
  128.     if (retval != WIFI_IOT_SUCCESS) {
  129.         return retval;
  130.     }

  131.     retval = AHT20_Read(buffer, sizeof(buffer));
  132.     if (retval != WIFI_IOT_SUCCESS) {
  133.         return retval;
  134.     }

  135.     if (AHT20_STATUS_BUSY(buffer[0]) || !AHT20_STATUS_CALI(buffer[0])) {
  136.         retval = AHT20_ResetCommand();
  137.         if (retval != WIFI_IOT_SUCCESS) {
  138.             return retval;
  139.         }
  140.         usleep(AHT20_STARTUP_TIME);
  141.         retval = AHT20_CalibrateCommand();
  142.         usleep(AHT20_CALIBRATION_TIME);
  143.         return retval;
  144.     }

  145.     return WIFI_IOT_SUCCESS;
  146. }

  147. // 发送 触发测量 命令,开始测量
  148. uint32_t AHT20_StartMeasure(void)
  149. {
  150.     uint8_t triggerCmd[] = {AHT20_CMD_TRIGGER, AHT20_CMD_TRIGGER_ARG0, AHT20_CMD_TRIGGER_ARG1};
  151.     return AHT20_Write(triggerCmd, sizeof(triggerCmd));
  152. }

  153. // 接收测量结果,拼接转换为标准值
  154. uint32_t AHT20_GetMeasureResult(float* temp, float* humi)
  155. {
  156.     uint32_t retval = 0, i = 0;
  157.     if (temp == NULL || humi == NULL) {
  158.         return WIFI_IOT_FAILURE;
  159.     }

  160.     uint8_t buffer[AHT20_STATUS_RESPONSE_MAX] = { 0 };
  161.     memset(&buffer, 0x0, sizeof(buffer));
  162.     retval = AHT20_Read(buffer, sizeof(buffer));  // recv status command result
  163.     if (retval != WIFI_IOT_SUCCESS) {
  164.         return retval;
  165.     }

  166.     for (i = 0; AHT20_STATUS_BUSY(buffer[0]) && i < AHT20_MAX_RETRY; i++) {
  167.         // printf("AHT20 device busy, retry %d/%d!
  168. ", i, AHT20_MAX_RETRY);
  169.         usleep(AHT20_MEASURE_TIME);
  170.         retval = AHT20_Read(buffer, sizeof(buffer));  // recv status command result
  171.         if (retval != WIFI_IOT_SUCCESS) {
  172.             return retval;
  173.         }
  174.     }
  175.     if (i >= AHT20_MAX_RETRY) {
  176.         printf("AHT20 device always busy!
  177. ");
  178.         return WIFI_IOT_FAILURE;
  179.     }

  180.     uint32_t humiRaw = buffer[1];
  181.     humiRaw = (humiRaw << 8) | buffer[2];
  182.     humiRaw = (humiRaw << 4) | ((buffer[3] & 0xF0) >> 4);
  183.     *humi = humiRaw / (float)AHT20_RESLUTION * 100;

  184.     uint32_t tempRaw = buffer[3] & 0x0F;
  185.     tempRaw = (tempRaw << 8) | buffer[4];
  186.     tempRaw = (tempRaw << 8) | buffer[5];
  187.     *temp = tempRaw / (float)AHT20_RESLUTION * 200 - 50;
  188.     // printf("humi = %05X, %f, temp= %05X, %f
  189. ", humiRaw, *humi, tempRaw, *temp);
  190.     return WIFI_IOT_SUCCESS;
  191. }


  192. 3.aht20.h

  193. /*
  194. * Copyright (c) 2020, HiHope Community.
  195. *
  196. * Redistribution and use in source and binary forms, with or without
  197. * modification, are permitted provided that the following conditions are met:
  198. *
  199. * 1. Redistributions of source code must retain the above copyright notice, this
  200. *    list of conditions and the following disclaimer.
  201. *
  202. * 2. Redistributions in binary form must reproduce the above copyright notice,
  203. *    this list of conditions and the following disclaimer in the documentation
  204. *    and/or other materials provided with the distribution.
  205. *
  206. * 3. Neither the name of the copyright holder nor the names of its
  207. *    contributors may be used to endorse or promote products derived from
  208. *    this software without specific prior written permission.
  209. *
  210. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  211. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  212. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  213. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  214. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  215. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  216. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  217. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  218. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  219. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  220. */

  221. #ifndef AHT20_H
  222. #define AHT20_H

  223. #include <stdint.h>

  224. uint32_t AHT20_Calibrate(void);

  225. uint32_t AHT20_StartMeasure(void);

  226. uint32_t AHT20_GetMeasureResult(float* temp, float* humi);

  227. #endif  // AHT20_H
复制代码


4、envrionment_demo.c
该c文件是在许思维老师例程代码基础上进行修改,需要I2C功能,需要把IO配置为I2C功能,且前面要加上 GpioInit()函数,才能成功配置IO。
  1. /*
  2. * Copyright (c) 2020, HiHope Community.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * 1. Redistributions of source code must retain the above copyright notice, this
  8. *    list of conditions and the following disclaimer.
  9. *
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. *    this list of conditions and the following disclaimer in the documentation
  12. *    and/or other materials provided with the distribution.
  13. *
  14. * 3. Neither the name of the copyright holder nor the names of its
  15. *    contributors may be used to endorse or promote products derived from
  16. *    this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  24. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */

  29. #include <stdio.h>
  30. #include <stdint.h>
  31. #include <string.h>
  32. #include <unistd.h>

  33. #include "ohos_init.h"
  34. #include "cmsis_os2.h"
  35. #include "wifiiot_i2c.h"
  36. #include "wifiiot_gpio.h"
  37. #include "wifiiot_gpio_ex.h"
  38. #include "wifiiot_pwm.h"
  39. #include "wifiiot_adc.h"
  40. #include "wifiiot_errno.h"

  41. #include "aht20.h"
  42. //#include "oled_ssd1306.h"

  43. #ifndef ARRAY_SIZE
  44. #define ARRAY_SIZE(a) sizeof(a)/sizeof(a[0])
  45. #endif

  46. #define MS_PER_S 1000

  47. #define BEEP_TIMES 3
  48. #define BEEP_DURATION 100
  49. #define BEEP_PWM_DUTY 30000
  50. #define BEEP_PWM_FREQ 60000
  51. #define BEEP_PIN_NAME WIFI_IOT_IO_NAME_GPIO_9
  52. #define BEEP_PIN_FUNCTION WIFI_IOT_IO_FUNC_GPIO_9_PWM0_OUT

  53. #define GAS_SENSOR_CHAN_NAME WIFI_IOT_ADC_CHANNEL_5
  54. // #define GAS_SENSOR_PIN_NAME WIFI_IOT_IO_NAME_GPIO_11

  55. #define AHT20_BAUDRATE 400*1000
  56. #define AHT20_I2C_IDX WIFI_IOT_I2C_IDX_0

  57. #define ADC_RESOLUTION 2048

  58. static float ConvertToVoltage(unsigned short data)
  59. {
  60.     return (float)data * 1.8 * 4 / 4096;
  61. }

  62. static void EnvironmentTask(void *arg)
  63. {
  64.     (void)arg;
  65.     uint32_t retval = 0;
  66.     float humidity = 0.0f;
  67.     float temperature = 0.0f;
  68.     float gasSensorResistance = 0.0f;
  69.    
  70.     /*I2C IO口初始化化*/
  71.     GpioInit();
  72.     IoSetFunc(WIFI_IOT_IO_NAME_GPIO_13,         WIFI_IOT_IO_FUNC_GPIO_13_I2C0_SDA);
  73.     IoSetFunc(WIFI_IOT_IO_NAME_GPIO_14, WIFI_IOT_IO_FUNC_GPIO_14_I2C0_SCL);
  74.     I2cInit(AHT20_I2C_IDX, AHT20_BAUDRATE);

  75.     while (WIFI_IOT_SUCCESS != AHT20_Calibrate()) {
  76.         printf("AHT20 sensor init failed!
  77. ");
  78.         usleep(1000);
  79.     }

  80.     while(1) {
  81.         retval = AHT20_StartMeasure();
  82.         if (retval != WIFI_IOT_SUCCESS) {
  83.             printf("trigger measure failed!
  84. ");
  85.         }

  86.         retval = AHT20_GetMeasureResult(&temperature, &humidity);
  87.         if (retval != WIFI_IOT_SUCCESS) {
  88.             printf("get humidity data failed!
  89. ");
  90.         }

  91.         unsigned short data = 0;
  92.         if (AdcRead(GAS_SENSOR_CHAN_NAME, &data, WIFI_IOT_ADC_EQU_MODEL_4, WIFI_IOT_ADC_CUR_BAIS_DEFAULT, 0)
  93.                 == WIFI_IOT_SUCCESS) {
  94.             float Vx = ConvertToVoltage(data);
  95.             gasSensorResistance = 5 / Vx - 1;
  96.         }
  97.         printf("temp: %.2f
  98. ", temperature);
  99.         printf("humi: %.2f
  100. ", humidity);
  101.         printf("gas: %.2f kom
  102. ", gasSensorResistance);
  103.         sleep(1);
  104.     }
  105. }

  106. static void EnvironmentDemo(void)
  107. {
  108.     osThreadAttr_t attr;
  109.     attr.name = "EnvironmentTask";
  110.     attr.attr_bits = 0U;
  111.     attr.cb_mem = NULL;
  112.     attr.cb_size = 0U;
  113.     attr.stack_mem = NULL;
  114.     attr.stack_size = 4096;
  115.     attr.priority = osPriorityNormal;

  116.     if (osThreadNew(EnvironmentTask, NULL, &attr) == NULL) {
  117.         printf("[EnvironmentDemo] Falied to create EnvironmentTask!
  118. ");
  119.     }
  120. }
  121. APP_FEATURE_INIT(EnvironmentDemo);
复制代码



5、BUILD.gn
BUILD.gn内容为
  1. # Copyright (c) 2020, HiHope Community.
  2. #
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions are met:
  5. #
  6. # 1. Redistributions of source code must retain the above copyright notice, this
  7. #    list of conditions and the following disclaimer.
  8. #
  9. # 2. Redistributions in binary form must reproduce the above copyright notice,
  10. #    this list of conditions and the following disclaimer in the documentation
  11. #    and/or other materials provided with the distribution.
  12. #
  13. # 3. Neither the name of the copyright holder nor the names of its
  14. #    contributors may be used to endorse or promote products derived from
  15. #    this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  21. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  23. # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  25. # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

  27. static_library("em_example") {
  28.     sources = [
  29.         "envrionment_demo.c",
  30.         "aht20.c"
  31.     ]
  32.     include_dirs = [
  33.         "//utils/native/lite/include",
  34.         "//kernel/liteos_m/components/cmsis/2.0",
  35.         "//base/iot_hardware/interfaces/kits/wifiiot_lite",
  36.     ]
  37. }
复制代码



这样还不行,还要修改app文件夹下的BUILD.gn。在features下增加"EM:em_example",
  1. lite_component("app") {
  2.     features = [
  3.         "startup",
  4.         "SSL:ssl_example",
  5.         "EM:em_example",
  6.         "OLED:oled_example"
  7.     ]
  8. }
复制代码
6、增加I2C功能
在默认情况下,hi3861_sdk中,I2C在CONFIG选项里没有打开,所以I2C无法进行使用我们需要修改vendorhisihi3861hi3861uildconfigusr_config.mk文件中的CONFIG_I2C_SUPPORT行:# CONFIG_I2C_SUPPORT is not set修改为CONFIG_I2C_SUPPORT=y
三、 编译烧录
烧录成功后,使用串口组手,查看到已经可以打印输出数据 。
四、总结
前一段时间太忙,确实落下很多进度,之后要加快学习速度了。再一次感谢许思维老师,查看许思维老师的例程代码,确实帮助了自己很多。明天我将写一篇关于OLED12864的帖子,主要功能为显示时钟、温湿度,总之要加快进度啦。

`
打印输出.PNG

回帖

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容图片侵权或者其他问题,请联系本站作侵删。 侵权投诉
链接复制成功,分享给好友