【DFRobot 云雀气象仪评测】Arduino无线智能空气监测系统搭建-02连接Arduino获取数据
本帖最后由 eew_TKwwQ7 于 2023-11-12 23:39 编辑<p>如何连接Arduino设备实时获取云雀DFRobot 云雀气象仪数据,官网已经介绍比较详细,</p>
<p>可参考:<a href="https://wiki.dfrobot.com.cn/_SKU_EDU0157_%E4%BA%91%E9%9B%80%E6%B0%94%E8%B1%A1%E4%BB%AA" target="_blank">https://wiki.dfrobot.com.cn/_SKU_EDU0157_%E4%BA%91%E9%9B%80%E6%B0%94%E8%B1%A1%E4%BB%AA</a></p>
<p>刚好手上有几块DFRobot Romeo V2开发板,其它开发板操作也类似,具体开发板可参考,基本上主流开发板都已经支持</p>
<p> </p>
<p>DFRobot Romeo V2详细资料可参考:<a href="https://wiki.dfrobot.com.cn/_SKU_DFR0225_RoMeo_V2" target="_blank">https://wiki.dfrobot.com.cn/_SKU_DFR0225_RoMeo_V2</a></p>
<p></p>
<p>下面就开始操作进行准备工作:</p>
<p><span style="font-size:18px;"><strong>一、Arduino平台下DFRobot 云雀气象仪库的安装与下载</strong></span></p>
<p>1.1 DFRobot_LarkWeatherStation库的下载</p>
<div>安装链接为:<a href="https://github.com/cdjq/DFRobot_Atmospherlum" target="_blank">https://github.com/cdjq/DFRobot_Atmospherlum</a>,下载zip文件 </div>
<p> </p>
<p>1.2库的安装,添加zip库方法如下:</p>
<p> </p>
<p>将zip库添加到Arduino IDE</p>
<p> </p>
<p>1.3进行编译,缺少<strong>DFRobot_RTU</strong>库报错</p>
<p> </p>
<p>1.4添加DFRobot_RTU库</p>
<p> </p>
<p>1.5打开案例程序,进行编译</p>
<p> </p>
<p>1.6编译通过,下载程序,接口采用IIC接口</p>
<p> </p>
<p>1.7实物连接照片</p>
<p> </p>
<p><strong>二、Arduino平台获取DFRobot 云雀气象仪数据</strong></p>
<p>2.1获取数据通过USB串口打印到电脑上,通过Arduino IDE 可以实时查看数据</p>
<p> </p>
<p>2.2程序代码如下</p>
<pre>
<code>/*!
* <a href="home.php?mod=space&uid=1307177" target="_blank">@File </a> getData.ino
* <a href="home.php?mod=space&uid=159083" target="_blank">@brief </a> This is a routine to get skylark data
* ---------------------------------------------------------------------------------------------------------------
* board | MCU | Leonardo/Mega2560/M0 | UNO | ESP8266 | ESP32 |microbit|
* VCC | 3.3V/5V | VCC | VCC | VCC |VCC| X |
* GND | GND | GND | GND | GND |GND| X |
* RX | TX | Serial1 TX1 | 5 | 5/D6|D2 | X |
* TX | RX | Serial1 RX1 | 4 | 4/D7|D3 | X |
* ---------------------------------------------------------------------------------------------------------------
*
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* <a href="home.php?mod=space&uid=33377" target="_blank">@license </a> The MIT License (MIT)
* <a href="home.php?mod=space&uid=1315547" target="_blank">@author </a> (jie.tang@dfrobot.com)
* <a href="home.php?mod=space&uid=252314" target="_blank">@version </a> V1.0.0
* <a href="home.php?mod=space&uid=311857" target="_blank">@date </a> 2023-06-8
* <a href="home.php?mod=space&uid=637249" target="_blank">@URL </a> https://github.com/DFRobot/DFRobot_LarkWeatherStation
*/
#include "DFRobot_LarkWeatherStation.h"
#if defined(ARDUINO_AVR_UNO)||defined(ESP8266)
#include <SoftwareSerial.h>
#endif
#define DEVICE_ADDR 0x42
#define MODESWITCH /*UART:*/0 /*I2C: 0*/
#if MODESWITCH
#if defined(ARDUINO_AVR_UNO)||defined(ESP8266)
SoftwareSerial mySerial(/*rx =*/4, /*tx =*/5);
DFRobot_LarkWeatherStation_UART atm(&mySerial);
#else
DFRobot_LarkWeatherStation_UART atm(&Serial1);
#endif
#else
DFRobot_LarkWeatherStation_I2C atm(DEVICE_ADDR,&Wire);
#endif
void setup(void){
#if MODESWITCH
//Init MCU communication serial port
#if defined(ARDUINO_AVR_UNO)||defined(ESP8266)
mySerial.begin(115200);
#elif defined(ESP32)
Serial1.begin(115200, SERIAL_8N1, /*rx =*/D3, /*tx =*/D2);
#else
Serial1.begin(115200);
#endif
#endif
Serial.begin(115200);
while(atm.begin()!= 0){
Serial.println("init error");
delay(1000);
}
Serial.println("init success");
atm.setTime(2023,1,11,23,59,0);
}
void loop(void){
Serial.println("----------------------------");
Serial.print(atm.getValue("Temp"));
Serial.println(atm.getUnit("Temp"));
Serial.print(atm.getValue("Humi"));
Serial.println(atm.getUnit("Humi"));
Serial.print(atm.getValue("Speed"));
Serial.println(atm.getUnit("Speed"));
Serial.println(atm.getValue("Dir"));
Serial.print(atm.getValue("Altitude"));
Serial.println(atm.getUnit("Altitude"));
Serial.print(atm.getValue("Pressure"));
Serial.println(atm.getUnit("Pressure"));
Serial.println("----------------------------");
Serial.println(atm.getInformation(true));
delay(500);
}</code></pre>
<p> </p>
<p>自此已经完成Arduino设备实时获取云雀DFRobot 云雀气象仪数据,其它开发板获取数据也类似,后面有时间再用其它开发板获取云雀DFRobot 云雀气象仪数据</p>
<p> </p>
<p>感谢楼主提供的技术分享,先收藏学习再发表个人意见,顶起来</p>
页:
[1]