I am having a problem with my dht22 sensor and nodemcu.
I am getting timeout errors all the time.
Here is my Lua:
function get_data_from_dht()
dht=require("dht")
status,temp,humi,temp_decimial,humi_decimial = dht.read(2)
if( status == dht.OK ) then
-- Prevent "0.-2 deg C" or "-2.-6"
temperature = temp.."."..(math.abs(temp_decimial)/100)
humidity = humi.."."..(math.abs(humi_decimial)/100)
-- If temp is zero and temp_decimal is negative, then add
-- "-" to the temperature string
if(temp == 0 and temp_decimial<0) then
temperature = "-"..temperature
end
print("Temperature: "..temperature.." deg C")
print("Humidity: "..humidity.."%")
elseif( status == dht.ERROR_CHECKSUM ) then
print( "DHT Checksum error" )
temperature=-1 --TEST
elseif( status == dht.ERROR_TIMEOUT ) then
print( "DHT Time out" )
temperature=-2 --TEST
end
-- Release module
dht=nil
package.loaded["dht"]=nil
end
get_data_from_dht()
Pins are:
+ to 3v3
- to GND
out to D2
Any help would be apppreciated.