nodemcu连接两个温湿度传感器-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2392|回复: 1

[未解决] nodemcu连接两个温湿度传感器

[复制链接]
发表于 2021-6-14 16:04 | 显示全部楼层 |阅读模式
nodemcu连接一个温湿度传感器可以成功读取温湿度,测试了两个传感器硬件也都是正常的,但是把两个传感器同时接在nodeMCU上后就不能读取数据了,难道这个板子不支持接两个相同的传感器?
代码如下,还是说我的代码有问题?
#define BLINKER_WIFI

#include <Blinker.h>

char auth[] = "1234ffda3";  //blinker账户生产的密码,小爱同学必须选用阿里云
//代码配网用下面这两段
char ssid[] = "SS";   //WiFi账号
char pswd[] = "SS";   //WiFi密码

BlinkerNumber HUMIOUT("humiout");
BlinkerNumber TEMPOUT("tempout");
BlinkerNumber DEWOUT("dewout");

BlinkerNumber HUMIIN("humiin");
BlinkerNumber TEMPIN("tempin");
BlinkerNumber DEWIN("dewin");

// Download Adafruit DHT-sensor-library library here:
// https://github.com/adafruit/DHT-sensor-library
#include <DHT.h>
#include <math.h>

#define DHTPINOUT D4
#define DHTPININ D0

//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

DHT dhtout(DHTPINOUT, DHTTYPE);
DHT dhtin(DHTPININ, DHTTYPE);
uint32_t read_time = 0;

float humiout_read, tempout_read, dewout_read;
float humiin_read, tempin_read, dewin_read;


void dataRead(const String & data)
{
    BLINKER_LOG("Blinker readString: ", data);

    Blinker.vibrate();

    uint32_t BlinkerTime = millis();

    Blinker.print("millis", BlinkerTime);
}

void heartbeat()
{
    HUMIOUT.print(humiout_read);
    TEMPOUT.print(tempout_read);
    DEWOUT.print(dewout_read);

    HUMIIN.print(humiin_read);
    TEMPIN.print(tempin_read);
    DEWIN.print(dewin_read);

}




void setup()
{
    Serial.begin(115200);
    BLINKER_DEBUG.stream(Serial);

    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, LOW);

    Blinker.begin(auth, ssid, pswd);
    Blinker.attachData(dataRead);
    Blinker.attachHeartbeat(heartbeat);

    dhtout.begin();
    dhtin.begin();
}

void loop()
{
    Blinker.run();

    if (read_time == 0 || (millis() - read_time) >= 2000)
    {
        read_time = millis();

        float hout = dhtout.readHumidity();
        float tout = dhtout.readTemperature();
        delay(5000);      
        float hin = dhtin.readHumidity();
        float tin = dhtin.readTemperature();

        if (isnan(hout) || isnan(tout)) {
            BLINKER_LOG("Failed to read from DHT exernal sensor!");
            return;
        }

        if (isnan(hin) || isnan(tin)) {
            BLINKER_LOG("Failed to read from DHT internal sensor!");
            return;
        }



        humiout_read = hout;
        tempout_read = tout;


        humiin_read = hin;
        tempin_read = tin;

    }
}

发表于 2021-6-14 20:17 | 显示全部楼层
该问题和点灯无关,帮您移动到求助区
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-29 04:06 , Processed in 0.093597 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表