neptune2 / esp8266-weather-station-oled-DST

Customized version of Squix78 ESP8266 OLED Weather Station w/ Auto Daylight Saving Time Adjust and other mods using SSD1306 OLED. See https://github.com/squix78/esp8266-weather-station for original code and library
61 stars 17 forks source link

DHT22 no Reading #3

Closed anthonyjclarke closed 7 years ago

anthonyjclarke commented 7 years ago

Hi, wonder if you can advise...

Two things, how do I change the updateDHT() to less frequently than a minute?

And, its giving me a nan reading for Temp and Humidity, bit randomly... changed the sensor a couple of times, same thing.... was thinking of changing the frequency of read to see if that makes a different...

Any suggestions?

neptune2 commented 7 years ago

Hi Anthony,

You can change how often the update occurs on line 309 in esp8266-weather-station-oled-DST.ino ticker.attach(60, setReadyForDHTUpdate);

Simply change 60 to the number of seconds you want between updates. Better yet, make it a variable and define it at the top of the code.

I have not seen problems with the DHT22, however others have reported similar "nan" issues with the DHT22 and arduino (both AVR and esp8266) I would recommend try adding a pull-up resistor from the DHT22 data pin ( any value 4.7KOhms to 10K Ohms) to 3.3V

Other known issues:

Please post back if you find which of these is affecting you

IoTMike commented 7 years ago

First, haven't had a chance yet to say thanks, I definitely like the additions you did on top of Dani's code! As for the DHT, I've pretty much relegated them to use for teaching, not for "real" use. Even on the newer DHT22, the temp is still fairly imprecise compared a DS18B20, and the humidity accuracy/reproducibility is crap compared to a SHT71 or BMP280. And, others have noted a rather high failure/inconsistency rate with DHT22s. Note that I have not tried the DHT33/RHT04.... With that gripe set aside, the DHTs have a "wakeup" time, and some DHT libraries account for that (e.g. Rob Tillaart's). I found that if the library does not account for it, taking a read, delay(30), read, tends to provide more consistent results. (Wakeup time is usually ~12ms, the second read must be taken in less than 2s else the chip go back to sleep mode). Cheers, Mike

anthonyjclarke commented 7 years ago

Thanks all...

@neptune2 my comments to your great suggestions,

  1. The DHT sensors are on small boards with resistors on them....
  2. Running esp8266 faster than 80MHz here - using ESP-12E un-modified
  3. Putting the DHT22 sensor at the end of a long cable (try without the cable) - on breadboard (see pic)
  4. Voltage dropping significantly below 3.3V (try a better power supply) - not using a battery, plugged into USB port / power adapter
  5. Possibly a bad DHT22 (try another DHT22) - seemed to make no difference before code below.

So I "googled".... and tried a couple of other things,

  1. do a DHT dummy read, short delay and then re-read - to no avail
  2. and was going to get clever and insert some logic "if bad read, read again", and got this far :-

// Called every 1 minute void updateDHT() { humidity = dht.readHumidity(); temperature = dht.readTemperature(!IS_METRIC); if (isnan(temperature) || isnan(humidity)) {
Serial.println("Failed to read from DHT"); } Serial.println("Temp = "+ String(temperature) +" - Humid = "+String(humidity)); readyForDHTUpdate = false; }

and its worked every since.... :)

img_1086

neptune2 commented 7 years ago

@IoTMike - You are very welcome, glad you like it. Thanks also for your insight and comments regarding the DHT sensors. As with most things, you get what you pay for. I wish the SHT71 was lower cost. However, on the bright side - the esp8266 is one of the rare exceptions of getting much more than you pay for 😀

@anthonyjclarke - Thanks for reporting back on each the potential problems. Wow, your end result is baffling! I would not have expected the additional code to solve the problem, especially after the dht library calls.

As always - adding debug code is often the antidote to insanity. I'd be really interested to know what the root cause is ... I hope this remains solved for you and that things that go away by themselves, don't come back by themselves