【问题标题】:ESP32: dsb1820 temperature sensor giving constant negative 127 readingESP32:dsb1820 温度传感器给出恒定的负 127 读数
【发布时间】:2020-07-25 02:04:08
【问题描述】:

我正在尝试使用连接到 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);
}

【问题讨论】:

  • 这样有趣的读物通常是因为短路 - 当我发生这种情况时,是因为数据线在电源上短路。
  • @HaydenEastwood,对于 DS18B20 不需要,这通常意味着 OP 缺少 Vcc 和 DS18B20 输出之间所需的电阻或电阻值错误。

标签: arduino microcontroller sensors esp32


【解决方案1】:

检查您的电缆并:

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(pcb 上的 4)但是

以下捆扎销:0、2、4、5(启动时为高)、12(低 启动期间)和 15(启动期间高)用于将 ESP32 放入 引导加载程序或闪烁模式。不要将外围设备连接到这些引脚! 如果这样做,您可能无法尝试上传代码、刷机或重置 董事会。

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

如果你有错误或没有/错误电阻,它会给你 -127(或者你杀死了传感器/它是 DOA)。

【讨论】:

  • 我用一个 4.75 欧姆的电阻器制作了与您图片中所示相同的电路。事实上,我使用的图片与您发布的图片完全相同。唯一不同的是我的 esp32 引脚排列如我发布的图片所示。
  • 感谢您的回复,请确保电阻为 4.7kOhms。您说我应该使用 GPIO7 作为传感器,我会在代码中将其命名为什么?我的意思是我应该写 7 、 D0 还是 0 而不是 4 写在我的代码中??
猜你喜欢
  • 2021-02-25
  • 1970-01-01
  • 1970-01-01
  • 2022-06-14
  • 1970-01-01
  • 2014-03-31
  • 1970-01-01
  • 2018-04-08
  • 1970-01-01
相关资源
最近更新 更多