【DFRobot 云雀气象仪评测】Arduino无线智能空气监测系统搭建-02连接Arduino获取数据
[复制链接]
本帖最后由 eew_TKwwQ7 于 2023-11-12 23:39 编辑
如何连接Arduino设备实时获取云雀DFRobot 云雀气象仪数据,官网已经介绍比较详细,
可参考:https://wiki.dfrobot.com.cn/_SKU_EDU0157_%E4%BA%91%E9%9B%80%E6%B0%94%E8%B1%A1%E4%BB%AA
刚好手上有几块DFRobot Romeo V2开发板,其它开发板操作也类似,具体开发板可参考,基本上主流开发板都已经支持
DFRobot Romeo V2详细资料可参考:https://wiki.dfrobot.com.cn/_SKU_DFR0225_RoMeo_V2
下面就开始操作进行准备工作:
一、Arduino平台下DFRobot 云雀气象仪库的安装与下载
1.1 DFRobot_LarkWeatherStation库的下载
1.2库的安装,添加zip库方法如下:
将zip库添加到Arduino IDE
1.3进行编译,缺少DFRobot_RTU库报错
1.4添加DFRobot_RTU库
1.5打开案例程序,进行编译
1.6编译通过,下载程序,接口采用IIC接口
1.7实物连接照片
二、Arduino平台获取DFRobot 云雀气象仪数据
2.1获取数据通过USB串口打印到电脑上,通过Arduino IDE 可以实时查看数据
2.2程序代码如下
/*!
* @File getData.ino
* @brief 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)
* @license The MIT License (MIT)
* @author [TangJie](jie.tang@dfrobot.com)
* @version V1.0.0
* @date 2023-06-8
* @URL 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);
}
自此已经完成Arduino设备实时获取云雀DFRobot 云雀气象仪数据,其它开发板获取数据也类似,后面有时间再用其它开发板获取云雀DFRobot 云雀气象仪数据
|