Prevent re-initialization of DHT11...
Posted: Tue Nov 24, 2015 3:54 am
Hello all,
I have this DHT11 sensor connected to ESP-12 on GPIO2 with a program to read sensor temperature and humidity using Arduino IDE (using the Adafruit DHT11 library). In the loop(), I read the sensor readings, send it to a collector node (using UDP) and then deep sleep for 10 seconds. The process continues.
Now my observation is that the readTemperature() and readHumidity() return NAN (invalid values for 50% of the function call, while correct values for the remaining tries). This was really of concern for me. Some thinking led me hit the point that dht.begin() to initialize the sensor may be causing the issue of invalid readings frequently. Since the wakeup from deep sleep starts from the setup() in which the dht.begin() is called, thus initializing the DHT sensor again and again. To prove this, I gave a try by commenting out the deep sleep (i.e. ESP.deepSleep()), and the invalid values were no more returned by the call and in every read, I got the correct values. But then, it comes with a price of ESP being always on, which I don't want.
How can I prevent the re-initialization of dht (through dht.begin()) along with deepSleep wakeup calling setup() ? In fact, frequent re-initialization can be an issue with any sensor connected on ESP.
Thanks and Regards,
Prabhat
I have this DHT11 sensor connected to ESP-12 on GPIO2 with a program to read sensor temperature and humidity using Arduino IDE (using the Adafruit DHT11 library). In the loop(), I read the sensor readings, send it to a collector node (using UDP) and then deep sleep for 10 seconds. The process continues.
Now my observation is that the readTemperature() and readHumidity() return NAN (invalid values for 50% of the function call, while correct values for the remaining tries). This was really of concern for me. Some thinking led me hit the point that dht.begin() to initialize the sensor may be causing the issue of invalid readings frequently. Since the wakeup from deep sleep starts from the setup() in which the dht.begin() is called, thus initializing the DHT sensor again and again. To prove this, I gave a try by commenting out the deep sleep (i.e. ESP.deepSleep()), and the invalid values were no more returned by the call and in every read, I got the correct values. But then, it comes with a price of ESP being always on, which I don't want.
How can I prevent the re-initialization of dht (through dht.begin()) along with deepSleep wakeup calling setup() ? In fact, frequent re-initialization can be an issue with any sensor connected on ESP.
Thanks and Regards,
Prabhat