After a lot of research, trial and error I managed to solve the issue; I’m going to share what I’ve learned, hoping that it might be useful for others.
NOTE: * If you want the solution “ready to consume” just skip the explaining paragraph and go to the last one.*
First of all, let me say that I have mixed feelings about this sensor: on paper it should be one of most basic and easy to use but in reality a quick search on the web shows a terrific amount of problems with this sensor.
From what I could gather It is clear that this sensor (DHT22 – AM2023) IS NOT the best choice in terms of:
I compared its readings against a BOSH BME280 and there is always a discrepancy of ~ 2°C and 5% RH.
One could be tempted to move directly to BME280, and I would agree if not for a relatively big problem: this sensor works with I2C and so it is not usable if you plan on developing a Radio Node / Gateway with MySensors and NodeMCU.
( yes, I’m aware of the method to read multiple sensors on I2C by using a pair of Resistance approx. between 3K and 10K – depending on the sensor – but I wasn’t capable of getting the BME280 working with 2.4Ghz Radio on NodeMCU. Each time GW or NODE was trying to access Radio I had a soft reset.)
Back to the DHT22: another huge problem, from my standpoint, is the incredible mess it has with libraries. Honestly, I could not describe it in another way: there are thousands of libraries “adapted” for the DHT22 and even more users complaining about their usability.
Now MySensors should have its own Library for DHT22 (and I tried it!) except this library appears to have a problematic approach to NodeMCU ESP8266 and DHT22 Sensors made by “ASAIR”.
( And I believe this is something worth being clearly stated in the “Build” page of MySensors; a warning would have been nice for a novice like me, whom bought the “best” DHT22 sensors he could find in order to have a good measurement)
Another very popular library is the Adafruit one, but it also got problems with ASAIR sensors; moreover it has been “stripped out” of error codes so the only error you might get is a quite meaningless “Can’t connect to DHT22”.
NodeMCU, MySensors and ASAIR AM2032 DHT22
So, here we are: how to make this “bloody thing” work with MySensors and ESP8266.
First of all, you need this specific library: DHT v. 0.1.13 by Rob Tillaart.
Not the previous, not the updated one: you need EXACTLY the VERSION 0.1.13.
Secondly, you need to understand that NodeMCU board has a serious issue with PIN Numbering: they probably thought it was funny to rename all ESP8266 Pins differently on the board respect the GPIO ordering.
(please bear with me for the joke, it took me almost 2 days to figure the issue with pins. Most certainly is because I'm a "n00b" but a little disclaimer would have been a blessing for my headache. )
Keep in mind the following picture as reference:
If you have your DHT22 sensor connected to pin “D4” you have to initialize it in the Arduino IDE as “2” because D2 actually corresponds to GPIO2.
If all this wasn’t enough, wait there is more!
You have your sketch ready, your sensor wired (eventually with pull-up resistor and stability capacitor, depending on the version you bought. I was lazy and bought the sensor already attached on the micro-board with resistance and capacitor) and still getting “DHT22 Timeout” error in Serial Monitor.
You don’t have a faulty sensor, do as follows:
- Connect the sensor to the board
- Load your sketch
- Open serial monitor, “DHT22 Timeout” will appear
- Disconnect just the sensor, keep the board powered and connected
- Reconnect the sensor in this precise order: Ground, VCC, Data
- Magically you will start having readings in the Serial Monitor.
If you cut power to the Node/Gateway you have to repeat steps 4-5-6.
I am happy to have a working sensor, but I’m frustrated about all the time I spent having a such simple sensor working correctly.
I wish I had this information before, so I could plan a different development.
I really hope that my experience could help other users.