目录
ArduinoIDE安装8266库(开发板和mini D1)
BMP180和BMP280程序里不同的地方(BMP280库文件下载)
介绍
8266开发板资料:
https://blog.csdn.net/SunnerChen/article/details/127282446
Wemos D1 Mini 资料:
https://zhuanlan.zhihu.com/p/295394580
BMP280资料:
https://blog.csdn.net/qq_51712037/article/details/118723269
BMP180资料:
https://blog.csdn.net/qq_51712037/article/details/119354384
效果展示
ArduinoIDE安装8266库(开发板和Wemos D1 Mini)
一、点灯科技的配置
2、添加设备(生成密钥key)
通过添加设备页面,您可以添加设备到您的账号。
在我的设备页面点击右上角的“+”图标,即可进入添加设备页面,具体步骤如下:
3.配置Blinker界面(UI)
显示实时数据 增加一个 数据控件,数据键名1.为temp 文本:温度 数据键名2.为pres文本:气压,数据键名3.为alti文本:相对高度即可
压缩包里有界面(UI)
4.点灯app温湿度曲线图配置
曲线图 增加一个 图表 控件,数据键名1为temp 文本:温度 数据键名2为pres文本:气压,数据键名3.为alti文本:相对高度即可
具体的说明可以看这个:https://blog.csdn.net/JIANGYINGH/article/details/105414517
二、代码步骤
1.引入库
代码如下(示例):
#include <Blinker.h>//点灯科技库
#include <Wire.h>//函数库
#include <Adafruit_BMP085.h>//BMP180库
---------------------------------------------------
#include <Blinker.h>//点灯库文件
#include <Wire.h>//辅助函数
#include <Adafruit_BMP280.h>//BMP280的库文件
库文件在我的压缩包里
2.接线(检查好是否连接正确在通电)
BMP180接线:
- 开发板GND—GND(BMP180)
- 开发板+3.3V—VVC(BMP180)
- 开发板D1—BMP180(SCL)
- 开发板D2—BMP180(SDA)
BMP280接线:
- 开发板GND—GND(BMP180)
- 开发板+3.3V—VVC(BMP180)
- 开发板D1—BMP280(SCL)
- 开发板D2—BMP280(SDA)
3.BMP180代码
代码如下(示例):
/* *****************************************************************
*
* Download latest Blinker library here:
* https://github.com/blinker-iot/blinker-library/archive/master.zip
*
*
* Blinker is a cross-hardware, cross-platform solution for the IoT.
* It provides APP, device and server support,
* and uses public cloud services for data transmission and storage.
* It can be used in smart home, data monitoring and other fields
* to help users build Internet of Things projects better and faster.
*
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
* if use ESP8266 with Blinker.
* https://github.com/esp8266/Arduino/releases
*
* Make sure installed 1.0.5 or later ESP32/Arduino package,
* if use ESP32 with Blinker.
* https://github.com/espressif/arduino-esp32/releases
*
* Docs: https://diandeng.tech/doc
*
*
* *****************************************************************
*
* Blinker 库下载地址:
* https://github.com/blinker-iot/blinker-library/archive/master.zip
*
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
*
* 如果使用 ESP8266 接入 Blinker,
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
* https://github.com/esp8266/Arduino/releases
*
* 如果使用 ESP32 接入 Blinker,
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
* https://github.com/espressif/arduino-esp32/releases
*
* 文档: https://diandeng.tech/doc
*
*
* *****************************************************************/
#define BLINKER_WIFI//定义wifi模块
#include <Blinker.h>//点灯库文件
#include <Wire.h>//辅助函数
#include <Adafruit_BMP085.h>//BMP180的库文件
char auth[] = "*********";//key 密钥
char ssid[] = "*********";//WiFi名称
char pswd[] = "*********";//WiFi密码
BlinkerNumber TEMP("temp"); // 定义BMT180温度数据键名
BlinkerNumber PRES("pres"); // 气压
BlinkerNumber ALTI("alti"); // 相对海拔
float ad = 0, cd = 0;
//volatile float ad;//定义浮点型全局变量 储存BMP180读取的数据
volatile float bd;
//volatile float cd;
Adafruit_BMP085 bmp;//定义
void heartbeat()
{
TEMP.print(ad);//给blinkerapp回传温度数据
PRES.print(bd);//给blinkerapp回传气压数据
ALTI.print(cd);//给blinkerapp回传相对海拔数据
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
//pinMode(LED_BUILTIN, OUTPUT);
//digitalWrite(LED_BUILTIN, LOW);
Blinker.begin(auth, ssid, pswd);
Blinker.attachHeartbeat(heartbeat);
Blinker.attachDataStorage(dataStorage);//调用云函数
bmp.begin();
}
void dataStorage()//云存储温湿度数据函数
{
Blinker.dataStorage("temp", ad);//存储温度
Blinker.dataStorage("pres", bd);//存储气压
Blinker.dataStorage("alti", cd);//存储相对高度
}
void loop()
{
Blinker.run();
{
if (!bmp.begin()) {
BLINKER_LOG("找不到有效的BMP280传感器,请检查接线!");
return;delay(100);}
float a = bmp.readTemperature();//读取温度
float b = bmp.readPressure();//读取气压
float c = bmp.readAltitude();//读取相对海拔(不准确模拟的)
//打印
BLINKER_LOG("温度: ",a,"C");//打印读出的数据
BLINKER_LOG("气压: ",b," *Pa");
BLINKER_LOG("相对高度: ",c," *米");
ad = a;//将读取到的湿度赋值给全局变量ad
bd = b;//将读取到的温度赋值给全局变量bd
cd = c;//将读取到的温度赋值给全局变量bd
}
Blinker.delay(1000);//延时函数
}
BMP280项目文件在压缩包里
4.BMP280代码
/* *****************************************************************
*
* Download latest Blinker library here:
* https://github.com/blinker-iot/blinker-library/archive/master.zip
*
*
* Blinker is a cross-hardware, cross-platform solution for the IoT.
* It provides APP, device and server support,
* and uses public cloud services for data transmission and storage.
* It can be used in smart home, data monitoring and other fields
* to help users build Internet of Things projects better and faster.
*
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
* if use ESP8266 with Blinker.
* https://github.com/esp8266/Arduino/releases
*
* Make sure installed 1.0.5 or later ESP32/Arduino package,
* if use ESP32 with Blinker.
* https://github.com/espressif/arduino-esp32/releases
*
* Docs: https://diandeng.tech/doc
*
*
* *****************************************************************
*
* Blinker 库下载地址:
* https://github.com/blinker-iot/blinker-library/archive/master.zip
*
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
*
* 如果使用 ESP8266 接入 Blinker,
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
* https://github.com/esp8266/Arduino/releases
*
* 如果使用 ESP32 接入 Blinker,
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
* https://github.com/espressif/arduino-esp32/releases
*
* 文档: https://diandeng.tech/doc
*
*
* *****************************************************************/
#define BLINKER_WIFI//定义wifi模块
#include <Blinker.h>//点灯库文件
#include <Wire.h>//辅助函数
#include <Adafruit_BMP280.h>//BMP280的库文件
char auth[] = "***********";//key 密钥
char ssid[] = "***********";//WiFi名称
char pswd[] = "***********";//WiFi密码
BlinkerNumber TEMP("temp"); // 定义BMP280温度数据键名
BlinkerNumber PRES("pres"); // 气压
BlinkerNumber ALTI("alti"); // 相对海拔
float ad = 0, cd = 0;
//volatile float ad;//定义浮点型全局变量 储存BMP280读取的数据
volatile float bd;
//volatile float cd;
Adafruit_BMP280 bmp;//定义
void heartbeat()
{
TEMP.print(ad);//给blinkerapp回传温度数据
PRES.print(bd);//给blinkerapp回传气压数据
ALTI.print(cd);//给blinkerapp回传相对海拔数据
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
//pinMode(LED_BUILTIN, OUTPUT);
//digitalWrite(LED_BUILTIN, LOW);
Blinker.begin(auth, ssid, pswd);
Blinker.attachHeartbeat(heartbeat);
Blinker.attachDataStorage(dataStorage);//调用云函数
bmp.begin(0X76);
}
void dataStorage()//云存储温湿度数据函数
{
Blinker.dataStorage("temp", ad);//存储温度
Blinker.dataStorage("pres", bd);//存储气压
Blinker.dataStorage("alti", cd);//存储相对高度
}
void loop()
{
Blinker.run();
{
if (!bmp.begin(0X76)) {
BLINKER_LOG("找不到有效的BMP280传感器,请检查接线!");
return;delay(100);}
float a = bmp.readTemperature();//读取温度
float b = bmp.readPressure();//读取气压
float c = bmp.readAltitude();//读取相对海拔(不准确模拟的)
//打印
BLINKER_LOG("温度: ",a,"C");//打印读出的数据
BLINKER_LOG("气压: ",b," *Pa");
BLINKER_LOG("相对高度: ",c," *米");
ad = a;//将读取到的湿度赋值给全局变量ad
bd = b;//将读取到的温度赋值给全局变量bd
cd = c;//将读取到的温度赋值给全局变量bd
}
Blinker.delay(1000);//延时函数
}
BMP280项目文件在压缩包里
BMP180和BMP280程序里不同的地方(BMP280库文件下载)
用的库文件也不一样BMP280我直接用的Arduino下载的库文件