ESP32:dsb1820温度传感器提供恒定的负127读数 [英] ESP32: dsb1820 temperature sensor giving constant negative 127 reading

查看:13
本文介绍了ESP32:dsb1820温度传感器提供恒定的负127读数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用连接到esp32微控制器的单个dsb1820温度传感器来获取温度读数。传感器连接到esp32的GPIO-4上。我打算将温度读数发送到云中。

我面临的问题是温度读数始终为-127。

我在网上看到,当dsb1820返回-127表示传感器未连接。

我是否使用错误的引脚连接传感器?

#include "OneWire.h"
#include "DallasTemperature.h"
#include <WiFi.h>
#define WIFI_SSID "SSID"
#define WIFI_PASSWORD "PASSWORD"

OneWire oneWire(4);
DallasTemperature tempSensor(&oneWire);

void setup(void)
{
    Serial.begin(115200);
    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    Serial.print("Connecting to Wi-Fi");
    while (WiFi.status() != WL_CONNECTED)
    {
        Serial.print(".");
        delay(300);
    }
    Serial.println();
    Serial.print("Connected with IP: ");
    Serial.println(WiFi.localIP());
    Serial.println();

    tempSensor.begin();
}

void loop(void)
{
    tempSensor.requestTemperaturesByIndex(0);

    Serial.print("Temperature: ");
    Serial.print(tempSensor.getTempCByIndex(0));
    Serial.println(" C");

    delay(2000);
}

推荐答案

检查电缆并:

const int oneWireBus = 32;  // on pin 32 /GPIO7/D0 on pcb (a 4.7K resistor is necessary)
OneWire oneWire(oneWireBus);

它应该是传感器的中间针脚(见我的图)

编辑 Devkit没有引脚4,您也可以使用Arduino 24中的GPIO4(印刷电路板上的4针),但

以下系带销:0、2、4、5(开机时高)、12(低 引导期间)和15(引导期间高)用于将ESP32放入 引导加载程序或闪烁模式。不要将外围设备连接到那些针脚上! 如果你这样做了,你可能在尝试上传代码、闪存或重置时遇到麻烦 董事会。

连接到32(PCB板上的GPIO7或D0),因为这是安全的测试

如果您使用错误或没有/错误的电阻,它将显示-127(或者您关闭了传感器/它是DOA)。

这篇关于ESP32:dsb1820温度传感器提供恒定的负127读数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆