esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 36 forks source link

DHT Sensor not operating with ESP8266 (ESP01) (Not usual case of pull-up resistor) #791

Closed WillT93 closed 4 years ago

WillT93 commented 4 years ago

Ongoing problem for about a week now and I've tried everything I can think of. Please help if you can, I'm really at the end of my rope. :/

Devices:

Problem:

Regardless of what I try, I continuously am only able to get the:

[22:35:01][W][dht:120]: Requesting data from DHT failed!
[22:35:01][W][dht:058]: Invalid readings! Please check your wiring (pull-up resistor, pin number) and consider manually specifying the DHT model using the model option.

error.

Attempted Resolutions:

Latest test code, as you can see, stripped to the basics:

esphome:
  name: totallyrandom
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: "[Redacted]"
  password: "[Redacted]"

logger:

api:

ota:

sensor:
  - platform: dht
    pin: 2
    temperature:
      name: "Living Room Temperature"
    humidity:
      name: "Living Room Humidity"
    update_interval: 10s

Output from most recent attempt to upload that code:

INFO Connecting to totallyrandom.local:6053 (xxx.xxx.xxx.229)
INFO Successfully connected to totallyrandom.local
[22:29:50][I][app:096]: esphome version 1.13.6 compiled on Nov  1 2019, 22:27:01
[22:29:50][C][wifi:372]: WiFi:
[22:29:50][C][wifi:254]:   SSID: '[Redacted]'
[22:29:50][C][wifi:255]:   IP Address: xx.xx.xx.229
[22:29:50][C][wifi:257]:   BSSID: xx:xx:xx:xx:xx:xx
[22:29:50][C][wifi:258]:   Hostname: 'totallyrandom'
[22:29:50][C][wifi:262]:   Signal strength: -71 dB ▂▄▆█
[22:29:50][C][wifi:263]:   Channel: 11
[22:29:50][C][wifi:264]:   Subnet: 255.255.255.0
[22:29:50][C][wifi:265]:   Gateway: xxx.xxx.xxx.231
[22:29:50][C][wifi:266]:   DNS1: xxx.xxx.xxx.231
[22:29:50][C][wifi:267]:   DNS2: 0.0.0.0
[22:29:50][C][logger:137]: Logger:
[22:29:50][C][logger:138]:   Level: DEBUG
[22:29:50][C][logger:139]:   Log Baud Rate: 115200
[22:29:50][C][logger:140]:   Hardware UART: UART0
[22:29:50][C][dht:017]: DHT:
[22:29:50][C][dht:018]:   Pin: GPIO2 (Mode: INPUT)
[22:29:50][C][dht:020]:   Auto-detected model: DHT22
[22:29:50][C][dht:027]:   Update Interval: 10.0s
[22:29:50][C][dht:029]:   Temperature 'Living Room Temperature'
[22:29:50][C][dht:029]:     Unit of Measurement: '°C'
[22:29:50][C][dht:029]:     Accuracy Decimals: 1
[22:29:50][C][dht:029]:     Icon: 'mdi:thermometer'
[22:29:50][C][dht:030]:   Humidity 'Living Room Humidity'
[22:29:50][C][dht:030]:     Unit of Measurement: '%'
[22:29:50][C][dht:030]:     Accuracy Decimals: 0
[22:29:50][C][dht:030]:     Icon: 'mdi:water-percent'
[22:29:50][C][ota:029]: Over-The-Air Updates:
[22:29:50][C][ota:030]:   Address: totallyrandom.local:8266
[22:29:50][C][api:103]: API Server:
[22:29:50][C][api:104]:   Address: totallyrandom.local:6053
[22:29:51][W][dht:120]: Requesting data from DHT failed!
[22:29:51][W][dht:058]: Invalid readings! Please check your wiring (pull-up resistor, pin number) and consider manually specifying the DHT model using the model option.
[22:30:01][W][dht:120]: Requesting data from DHT failed!
[22:30:01][W][dht:058]: Invalid readings! Please check your wiring (pull-up resistor, pin number) and consider manually specifying the DHT model using the model option.
[22:30:11][W][dht:120]: Requesting data from DHT failed!
[22:30:11][W][dht:058]: Invalid readings! Please check your wiring (pull-up resistor, pin number) and consider manually specifying the DHT model using the model option.
[22:30:14][D][api:573]: Client 'Home Assistant 0.99.3 (10.11.12.11)' connected successfully!
[22:30:21][W][dht:120]: Requesting data from DHT failed!
[22:30:21][W][dht:058]: Invalid readings! Please check your wiring (pull-up resistor, pin number) and consider manually specifying the DHT model using the model option.
[22:30:31][W][dht:120]: Requesting data from DHT failed!`

The most interesting part of it all though, is that after I upload the following bog-standard Arduino code to the EXACT same device, it spits out the temperature and humidity levels to the console window without a single problem in the world. The only issue seems to be when it's running the code compiled up for it by ESPHome.

Arduino code that seems to work fine, printing to the console.

// Example testing sketch for various DHT humidity/temperature sensors written by ladyada
// REQUIRES the following Arduino libraries:
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor

#include "DHT.h"

#define DHTPIN 2     // Digital pin connected to the DHT sensor
// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --
// Pin 15 can work but DHT must be disconnected during program upload.

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println(F("DHTxx test!"));

  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.print(F("°C "));
  Serial.print(f);
  Serial.print(F("°F  Heat index: "));
  Serial.print(hic);
  Serial.print(F("°C "));
  Serial.print(hif);
  Serial.println(F("°F"));
}

Apologies for the information overload, I figure if there's any chance of solving this, it's with all the info I can provide, I'm happy to test anything out that you guys suggest, post any code, anything. If I sound desperate, it's cause I am. I've been at this for what feels like forever.

Thank you in advance, William

close-issue-app[bot] commented 4 years ago

This issue was auto-closed because the issue template was not filled out. The ESPHome developers invest lots of time to maintain this project, so please at least fill out the issue template so that a bunch of standard questions don't need to be asked again each time. Thank you for taking the time to report a bug, hopefully it can be resolved soon.