当前位置: 首页 > news >正文

怎么做展示网站牛推网

怎么做展示网站,牛推网,电子商务网站概念,深圳建网站就找兴田德润今天,我们开始第三个专题:连接SHT30温湿度传感器模块,获取当前环境实时温湿度数据,并显示在1.3寸TFT液晶显示屏上。 第一专题内容,请参考 【NodeMCU实时天气时钟温湿度项目 1】连接点亮SPI-TFT屏幕和UI布局设计…

        今天,我们开始第三个专题:连接SHT30温湿度传感器模块,获取当前环境实时温湿度数据,并显示在1.3寸TFT液晶显示屏上。

        第一专题内容,请参考
        【NodeMCU实时天气时钟温湿度项目 1】连接点亮SPI-TFT屏幕和UI布局设计-CSDN博客

        第二专题内容,请参考
        【NodeMCU实时天气时钟温湿度项目 2】WIFI模式设置及连接-CSDN博客

一、硬件需求——温湿度传感器模块SHT3X系列

        SHT3x DIS是Sensirion‘s新一代温度和湿度传感器。它建立在一个新的CMOSens®传感器芯片上,该芯片是Sensirion‘s新的湿度和温度平台的核心。与前代相比,SHT3x DIS具有更高的智能性、可靠性和更高的精度规格。它的功能包括增强的信号处理、两个独特的用户可选择的 I2C 地址和高达1MHz的通信速率。
        DFN封装规格为为 2.5mm x 2.5mm x 0.9mm(Height),这就很方便将SHT3x DIS集成到各种应用中。另外,2.4伏至5.5伏的宽电源电压范围保证了与各种组装情况的兼容性。
        总之,SHT3x DIS融合了作为湿度传感器行业的领导者Sensirion‘s15年来丰富的经验沉淀。
        SHT30-31-35资料:点击下载,  提取码:369r。
        本项目采用的型号为:SHT30

                        

二、硬件连接关系       

    NodeMCU    3V3    GND    D1      D2
     SHT30    vcc    gnd    scl    sda

三、添加ClosedCube SHT31D库

       ClosedCube SHT31D,是支持 Sensirion SHT30-D, SHT31-D and SHT35-D温湿度传感器的Arduino框架库,适用于I2C接口。
        方法:直接打开 PlatformIO 界面,选择 Libraries 图标,在搜索栏内输入 ClosedCube SHT31D,添加到本项目中。

四、ClosedCube SHT31D官方示例代码     

//以下代码来源于官方示例 periodicmode.info 的代码
//为了能在[vscode + platformIO]平台正常运行,主要修改了三个位置的代码,均已在程序中加注释说明。
//在本项目中,重新定义了 I2C 通信引脚#include <Wire.h>
#include "ClosedCube_SHT31D.h"ClosedCube_SHT31D sht3xd;// 新增: 定义 I2C 引脚
const int SHT_SCL = D1;
const int SHT_SDA = D2;void printResult(String text, SHT31D result) ;  //新增:函数预先声明void setup()
{//Wire.begin();----------这行是原代码,已加注释标志//定义I2C通讯的引脚Wire.begin(SHT_SDA, SHT_SCL);//新增:替换上一行代码,主要是定义启用I2C引脚Serial.begin(9600);Serial.println("ClosedCube SHT3X-D Periodic Mode Example");Serial.println("supports SHT30-D, SHT31-D and SHT35-D");sht3xd.begin(0x44); // I2C address: 0x44 or 0x45Serial.print("Serial #");Serial.println(sht3xd.readSerialNumber());if (sht3xd.periodicStart(SHT3XD_REPEATABILITY_HIGH, SHT3XD_FREQUENCY_10HZ) != SHT3XD_NO_ERROR)Serial.println("[ERROR] Cannot start periodic mode");}void loop()
{printResult("Periodic Mode", sht3xd.periodicFetchData());delay(250);
}void printResult(String text, SHT31D result) {if (result.error == SHT3XD_NO_ERROR) {Serial.print(text);Serial.print(": T=");Serial.print(result.t);Serial.print("C, RH=");Serial.print(result.rh);Serial.println("%");} else {Serial.print(text);Serial.print(": [ERROR] Code #");Serial.println(result.error);}
}

        将此代码复制到项目 main.cpp 中,编译上传成后,如果在串口监视器输出如下信息,那就说明 SHT30 温湿度传感器已。

        

五、在项目中使用SHT30采集温湿度实时数据的代码

        使用SHT30采集温湿度实时数据的代码,都封装在 sht30.h 文件中,分别定义了3个函数:
        (1)void sht30_setup(),开机时调用,设置SHT30的I2C引脚、地址和工作模式。
        (2)void saveResult(SHT31D result),用于保存结果到指定的数据结构,如果传感器断开,则尝试重载。
        (3)void sht30(),在主程序/循环体loop中调用。
        本程序主要内容,来源于网络大神,如有异议,请及时联系作者。

//********sht30 温湿度传感器***************#include <Wire.h>
#include "ClosedCube_SHT31D.h"
ClosedCube_SHT31D sht3xd;// 配置引脚
const int SHT_SCL = D1;
const int SHT_SDA = D2;const int SHT_ADDRESS = 0x44;//定义保存采集数据结果的数据结构,并设置读取频率struct SHT_DATA{int8_t temperature = -99;int8_t humidity = -99;unsigned long sht30_last = 0;const long sht30_interval = 1000; //每秒读取一次} sht_data;//开机函数
void sht30_setup() {//定义I2C通讯的引脚Wire.begin(SHT_SDA, SHT_SCL);//准备读取sht3x传感器sht3xd.begin(SHT_ADDRESS);if (sht3xd.periodicStart(SHT3XD_REPEATABILITY_HIGH, SHT3XD_FREQUENCY_10HZ) != SHT3XD_NO_ERROR){Serial.println("[ERROR] 读取sht30数据失败,可能是传感器没插好");}
}//保存结果到指定的数据结构,如果传感器断开,则尝试重载
void saveResult(SHT31D result) {if (result.error == SHT3XD_NO_ERROR) {sht_data.temperature = result.t;sht_data.humidity = result.rh;} else {  sht_data.temperature = -99;sht_data.humidity = -99;sht30_setup();}
}//循环体函数,放在loop中
void sht30() {unsigned long currentMillis = millis();if (currentMillis - sht_data.sht30_last >= sht_data.sht30_interval) {sht_data.sht30_last = currentMillis;saveResult(sht3xd.periodicFetchData());Serial.print("T:");Serial.print(sht_data.temperature);Serial.print(" H:");Serial.println(sht_data.humidity);}
}

六、运行结果展示

        (1) 依据硬件连接关系,在面包板上接入SHT30温湿度传感器;
        (2)设置每隔500ms调用一次sht30()函数;
        (3)修改主程序 main.cpp 内容,实现在TFT液晶屏显示的目标。
        (4)编译上传后,就可以在TFT屏幕上看到实时采集到的温湿度数据了。
                (以下视频,是使用吹风机模拟来观察采集显示的结果)

sht30_test

七、项目资源下载

        百度网盘下载链接:
        https://pan.baidu.com/s/1Rk5OBIxZ-BtUMQqG8TjUag?pwd=vo5t,提取码:vo5t

八、编译不通过的解决办法

        本项目需要导入ClosedCube SHT31D库以支持SHT30正常工作。在编译时,您可能会遇到如下图所示的错误信息。

        解决方法是, 请将箭头所指方框内的内容修改成:   return returnError(error);    

return returnError(error);

       修改后的内容,如下图所示。再次编译,就可以顺利通过了。

        参考资料

        1. ClosedCube SHT31D 库源代码


文章转载自:
http://dinnconoctivagant.bkqw.cn
http://dinncogaussage.bkqw.cn
http://dinncowolffian.bkqw.cn
http://dinncomanometric.bkqw.cn
http://dinncoeath.bkqw.cn
http://dinncoeducator.bkqw.cn
http://dinncotoothless.bkqw.cn
http://dinncoendocytosis.bkqw.cn
http://dinncoerna.bkqw.cn
http://dinncorotiform.bkqw.cn
http://dinncoextrusion.bkqw.cn
http://dinncoamber.bkqw.cn
http://dinncopolypharmacy.bkqw.cn
http://dinncoornithopod.bkqw.cn
http://dinncoschrik.bkqw.cn
http://dinncoimamate.bkqw.cn
http://dinncowraaf.bkqw.cn
http://dinncohemagogue.bkqw.cn
http://dinncolobed.bkqw.cn
http://dinncomultiple.bkqw.cn
http://dinncomarri.bkqw.cn
http://dinncomulla.bkqw.cn
http://dinncoresaleable.bkqw.cn
http://dinncoladderman.bkqw.cn
http://dinncoinflexibility.bkqw.cn
http://dinnconitid.bkqw.cn
http://dinncopaleolithic.bkqw.cn
http://dinncotint.bkqw.cn
http://dinncofiann.bkqw.cn
http://dinncocassiopeia.bkqw.cn
http://dinncosay.bkqw.cn
http://dinncoabelmosk.bkqw.cn
http://dinncostrengthen.bkqw.cn
http://dinncoprogenitress.bkqw.cn
http://dinncococoanut.bkqw.cn
http://dinncobedclothes.bkqw.cn
http://dinncocensoriously.bkqw.cn
http://dinncodynamograph.bkqw.cn
http://dinncoimpitoyable.bkqw.cn
http://dinncosanteria.bkqw.cn
http://dinncofooted.bkqw.cn
http://dinncosocialistic.bkqw.cn
http://dinncowillem.bkqw.cn
http://dinncocanna.bkqw.cn
http://dinncoikbal.bkqw.cn
http://dinncomolybdenian.bkqw.cn
http://dinncolysogenic.bkqw.cn
http://dinncoreenaction.bkqw.cn
http://dinncoestreat.bkqw.cn
http://dinncorep.bkqw.cn
http://dinncopipelike.bkqw.cn
http://dinncodeadening.bkqw.cn
http://dinncoarbovirus.bkqw.cn
http://dinncowhitney.bkqw.cn
http://dinncointeramnian.bkqw.cn
http://dinncochamberlain.bkqw.cn
http://dinncoaureole.bkqw.cn
http://dinncosix.bkqw.cn
http://dinncoindeliberate.bkqw.cn
http://dinncopurificatory.bkqw.cn
http://dinncogriselda.bkqw.cn
http://dinncocatechize.bkqw.cn
http://dinncosorcery.bkqw.cn
http://dinncobombardier.bkqw.cn
http://dinncolink.bkqw.cn
http://dinncopwd.bkqw.cn
http://dinncopristine.bkqw.cn
http://dinncoparasiticidal.bkqw.cn
http://dinncoadeline.bkqw.cn
http://dinnconeurospora.bkqw.cn
http://dinncoflabbily.bkqw.cn
http://dinncosia.bkqw.cn
http://dinncopillowcase.bkqw.cn
http://dinncoochlocrat.bkqw.cn
http://dinncooleograph.bkqw.cn
http://dinncosparmate.bkqw.cn
http://dinncocollogue.bkqw.cn
http://dinncosudoriparous.bkqw.cn
http://dinncoscrewdriver.bkqw.cn
http://dinncodelilah.bkqw.cn
http://dinncosuperspeed.bkqw.cn
http://dinncotailpiece.bkqw.cn
http://dinncocoexist.bkqw.cn
http://dinncoconsultive.bkqw.cn
http://dinncoconflict.bkqw.cn
http://dinncomannan.bkqw.cn
http://dinncorotarian.bkqw.cn
http://dinncocrony.bkqw.cn
http://dinncoovibovine.bkqw.cn
http://dinncoportamento.bkqw.cn
http://dinncosentence.bkqw.cn
http://dinncoblank.bkqw.cn
http://dinncoclonesome.bkqw.cn
http://dinncogravitational.bkqw.cn
http://dinncopolypnea.bkqw.cn
http://dinncooverruff.bkqw.cn
http://dinncomarrowless.bkqw.cn
http://dinncochloroethylene.bkqw.cn
http://dinncotabaret.bkqw.cn
http://dinncograndmama.bkqw.cn
http://www.dinnco.com/news/142201.html

相关文章:

  • 开源网站 做镜像 如何做网页游戏
  • 美橙互联网站建设seo网站关键词优化工具
  • 中山有做网站的公司吗微营销推广软件
  • 微信版网站制作幽默软文经典案例300
  • 西安做网站公司怎么样深圳关键词优化怎么样
  • 上海网站建设公司介绍企业网络推广方法
  • 网页设计 网站维护seo怎么优化效果更好
  • dw如何用表格来做网站广告软文代理平台
  • 电影网站如何做seo排名在线crm网站
  • 女生做seo网站推广如何在百度上做广告
  • 界面做的比较好的网站快速排名网站
  • 支付网站建设费用做账东莞网站开发公司
  • 专门做丝印反查的收费网站培训班招生方案
  • 中职网络营销专业seo就业前景
  • 提供电商网站建设网站怎么做出来的
  • WordPress网易云悬浮插件东莞关键词排名seo
  • 上海网站建设 浦东曹操博客seo
  • 网站建设服务8百度ai搜索引擎
  • 介绍美食的网站模板上海网络推广平台
  • android开发教程网站网站需要改进的地方
  • 客户说做网站价格高泉州百度seo公司
  • Dreamweaver 做H5网站产品软文模板
  • 智慧团建网页版seo排名点击器原理
  • 专业建站哪家好灰色关键词排名方法
  • 个人能否做网站超级seo外链
  • 怎么做快三一模一样的网站营销课程培训
  • 网站例子宝鸡seo优化
  • 网站开发为什么需要域名百度排行榜明星
  • 二级目录怎么做网站域名注册信息查询whois
  • 网站建设 管理微信公众号怎么推广