markruys / arduino-DHT

Efficient DHT library for Arduino
Other
163 stars 119 forks source link

It desn't work with ESP8266 #6

Open gosewski opened 8 years ago

gosewski commented 8 years ago

When compiled for ESP8266, this library functions return some strange readings like: Temperature: 3080214.00 *C Humidity: 404527.00 %

CuriousTech commented 8 years ago

Uninitialized variable. In DHT.cpp, line 147. Change... word data; to word data = 0;

Lucky7Chess commented 8 years ago

Did that actually work? Didn't work for me.......

peterodro commented 7 years ago

dears, i make a trial with DHT11 and DHT22. it is working only with DHT11, with DHT22 it shows any strange value. I check connected DHT model with "dht.getModel()". In both cases it shows model 1 = DHT11. I try to manualy set for model 2 (dht.setup(2,2) or dht.setup(2, DHT22) ) but it always get any error. Then I adapt DHT.cpp file, i manualy add line model = DHT22; into "void DHT::readSensor()" Problem solved. How to corectly set dht.setup() to make fix model type DHT22?

CuriousTech commented 7 years ago

@peterodro try adding Serial.println(DHT22); and see if it prints a 2.

The latest esp8266 SDK has trouble with uninitialized variables even though it's supposed to set them to zero. The DHT_MODEL_t enum in DHT.h is uninitialized. It should begin with AUTO_DETECT = 0 to get around the bug.

If those 2 var inits don't work, make sure it's not something else like I/O pins or hardware.

peterodro commented 7 years ago

i'm sure about correct connection. In my project I put a 4pin "connector" in place of DHT, so i just plug in DHT11 and then DHT22 (both have same connection i suppose). DHT11 works ok, DHT22 shows 1.0C and 0.0%. To be sure that DHTs are OK, i test them before on Arduino UNO board, with examples from IDE. So HW is 100% ok. in my program is used dht.setup(2); So DHT connect into pin2. I need to somethink like dht.setup(2, DHT22); or dht.setup(2, 2); but it gives error. what is correct syntax of dht.setup() with exactly selected model?

CuriousTech commented 7 years ago

@peterodro It should be dht.setup(pin, DHT::DHT22); For hardware, if you're powering it at 3.3V you may need a pullup resistor if the signal line is low idle. You can also change the pinMode() in readSensor() to use INPUT_PULLUP instead of INPUT, which is a little easier.

peterodro commented 7 years ago

@CuriousTech thanks dht.setup(pin, DHT::DHT22); works

so auto detection not working in this lib, but problem solved without changing lib.

CuriousTech commented 7 years ago

@peterodro It looks like you're probably including 2 different DHT libraries and getting some conflicts. There's another one defining DHT22 as a different value.