【项目背景】
本项目用来解大气运动的状态和变化,使用云雀气象仪,通过它检测风速、风向来了解大气运动的状态,检测气压、温度、湿度来了解大气的物理状态。并结合Mind+“可视化面板”实现大屏显示。
【硬件连接】
云雀气象仪接行空板I2C引脚,摄像头接行空板USB口,使用太阳能板加锂电池组为行空板供电。
【相关知识】
“气压的国际制单位是帕斯卡,简称帕,符号是Pa。气象学中,人们一般用千帕(kPa)、或使用百帕(hpa)作为单位。其它的常用单位分别是:巴(bar,1bar=100,000帕)和厘米水银柱(或称厘米汞柱)。”
湿度,表示空气干湿程度,即空气中所含水汽多少的物理量。 在一定的温度下在一定体积的空气里含有的水汽越少,则空气越干燥;水汽越多,则空气越潮湿。空气的干湿程度叫做“湿度”。在此意义下,常用绝对湿度、相对湿度、比较湿度、混合比、饱和差以及露点等物理量来表示;若表示在湿蒸汽中水蒸气的重量占蒸汽总重量(体积)的百分比,则称之为蒸汽的湿度。人体感觉舒适的湿度是:相对湿度低于70%。
风向
风力等级
【准备工作】
按说明教程,完成行空板SIOT V2升级,Mind+ 增加扩展 “云雀气象仪”。
需要说明的是:因程序最终要在行空板上运行,所以需要将“气象仪”扩展包下载下来,解压后将“libraries”中的“DFRobot_Atmospherlum.py”文件拷贝到行空板,程序所在目录下。
【程序编写】
程序中,需在初始化“云雀”前,加上调动“引脚”设置语句,不然运行会出错(需要工程师处理完善BUG)
发送到SIOT的图像需要先进行BASE64编程,并处理成字符串,再加上“data:image/jpeg;base64,”。可视化面板上的“网络图片”才能正确显示。
【可视化面板】
Mind+要使用V1.8.0版本
【附Python代码】
# -*- coding: UTF-8 -*-
# MindPlus
# Python
from pinpong.extension.unihiker import *
from pinpong.board import Board,Pin
from DFRobot_Atmospherlum import *
from io import BytesIO
from PIL import Image
import base64
import siot
import cv2
# 自定义函数
def TuXiangBase64BianMa(frame):
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
img = Image.fromarray(frame) #将每一帧转为Image
output_buffer = BytesIO() #创建一个BytesIO
img.save(output_buffer, format='JPEG') #写入output_buffer
byte_data = output_buffer.getvalue() #在内存中读取
base64_data = base64.b64encode(byte_data) #转为BASE64
base64_str =str(base64.b64encode(byte_data),'utf-8') #转为字符串
return base64_str
siot.init(client_id="",server="192.168.31.192",port=1883,user="siot",password="dfrobot")
Board().begin()
siot.connect()
siot.loop()
p_p25_out=Pin(Pin.P25, Pin.OUT)
p_p25_out.write_digital(0)
yunque_i2c = DFRobot_Atmospherlum_I2C(0x42)
while (yunque_i2c.begin() != 0):
print("yunque_i2c initialize failed!!")
time.sleep(1)
print("Sensor initialize success!!")
yunque_i2c.set_local_time()
time.sleep(1)
FengLiDengJi = ""
vd = cv2.VideoCapture()
vd.open(0)
while not (vd.isOpened()):
pass
YunXingShiJian = time.time()
while True:
if vd.grab():
ret, frame = vd.read()
if ((time.time() - YunXingShiJian) > 5):
YunXingShiJian = time.time()
if vd.grab():
ret, frame = vd.read()
frame=cv2.resize(frame,(320,240))
base64TuPian = TuXiangBase64BianMa(frame)
siot.publish_save(topic="siot/video", data=(str((str("data:image/jpeg;base64,"))) + str(base64TuPian)))
siot.publish_save(topic="siot/pressure", data=(yunque_i2c.get_value("Pressure")))
siot.publish_save(topic="siot/humidity", data=(yunque_i2c.get_value("Humi")))
siot.publish_save(topic="siot/temperature", data=(yunque_i2c.get_value("Temp")))
FengSu = (int(float((yunque_i2c.get_value("speed")))))
if ((FengSu >= 0) and (FengSu <= 0.2)):
FengLiDengJi = "0级 无风"
elif ((FengSu > 0.3) and (FengSu <= 1.5)):
FengLiDengJi = "1级 软风"
elif ((FengSu > 1.6) and (FengSu <= 3.3)):
FengLiDengJi = "2级 轻风"
elif ((FengSu > 3.4) and (FengSu <= 5.4)):
FengLiDengJi = "3级 微风"
elif ((FengSu > 5.5) and (FengSu <= 7.9)):
FengLiDengJi = "4级 和风"
elif ((FengSu > 8.0) and (FengSu <= 10.7)):
FengLiDengJi = "5级 清劲风"
elif ((FengSu > 10.8) and (FengSu <= 13.8)):
FengLiDengJi = "6级 强风"
elif ((FengSu > 13.9) and (FengSu <= 17.1)):
FengLiDengJi = "7级 疾风"
elif ((FengSu > 17.2) and (FengSu <= 20.7)):
FengLiDengJi = "8级 大风"
elif ((FengSu > 20.8) and (FengSu <= 24.4)):
FengLiDengJi = "9级 烈风"
elif ((FengSu > 24.5) and (FengSu <= 28.4)):
FengLiDengJi = "10级 狂风"
elif ((FengSu > 28.5) and (FengSu <= 32.6)):
FengLiDengJi = "11级 暴风"
elif ((FengSu > 32.7) and (FengSu <= 36.9)):
FengLiDengJi = "12级 飓风"
siot.publish_save(topic="siot/wind_speed", data=FengLiDengJi)
FengXiang = (yunque_i2c.get_value("dir"))
if (FengXiang == "N"):
FengXiang = "北"
elif (FengXiang == "NE"):
FengXiang = "东北"
elif (FengXiang == "E"):
FengXiang = "东"
elif (FengXiang == "SE"):
FengXiang = "东南"
elif (FengXiang == "S"):
FengXiang = "南"
elif (FengXiang == "SW"):
FengXiang = "西南"
elif (FengXiang == "W"):
FengXiang = "西"
elif (FengXiang == "NW"):
FengXiang = "西北"
siot.publish_save(topic="siot/wind_direction", data=FengXiang)
【演示视频】
花生编程2023.07.09
赞
花生编程2023.07.09
厉害厉害
三春牛-创客2023.06.28
赞!
三春牛-创客2023.06.28
不错不错