2015-04-03 17:44:26 +02:00
|
|
|
# DHTxx module
|
2015-01-21 08:23:06 +01:00
|
|
|
|
2015-04-03 17:44:26 +02:00
|
|
|
This module is compatible with DHT11, DHT21 and DHT22.
|
2015-01-25 20:20:48 +01:00
|
|
|
No need to use a resistor to connect the pin data of DHT22 to ESP8266.
|
|
|
|
|
2015-04-03 17:44:26 +02:00
|
|
|
##Integer Verison[When using DHT11, Float version is useless...]
|
|
|
|
### Example
|
2015-01-21 08:23:06 +01:00
|
|
|
```lua
|
|
|
|
PIN = 4 -- data pin, GPIO2
|
|
|
|
|
2015-04-03 17:44:26 +02:00
|
|
|
DHT= require("dht_lib")
|
|
|
|
|
|
|
|
--dht.read11(PIN)
|
|
|
|
DHT.read22(PIN)
|
|
|
|
|
|
|
|
t = DHT.getTemperature()
|
|
|
|
h = DHT.getHumidity()
|
2015-01-21 08:23:06 +01:00
|
|
|
|
2015-02-02 10:01:24 +01:00
|
|
|
if h == nil then
|
2015-04-03 17:44:26 +02:00
|
|
|
print("Error reading from DHT11/22")
|
2015-01-25 20:20:48 +01:00
|
|
|
else
|
|
|
|
-- temperature in degrees Celsius and Farenheit
|
2015-04-03 17:44:26 +02:00
|
|
|
|
2015-02-02 10:01:24 +01:00
|
|
|
print("Temperature: "..((t-(t % 10)) / 10).."."..(t % 10).." deg C")
|
2015-04-03 17:44:26 +02:00
|
|
|
|
2015-01-25 20:20:48 +01:00
|
|
|
print("Temperature: "..(9 * t / 50 + 32).."."..(9 * t / 5 % 10).." deg F")
|
2015-02-02 10:01:24 +01:00
|
|
|
|
2015-01-25 20:20:48 +01:00
|
|
|
-- humidity
|
2015-04-03 17:44:26 +02:00
|
|
|
|
2015-02-02 10:01:24 +01:00
|
|
|
print("Humidity: "..((h - (h % 10)) / 10).."."..(h % 10).."%")
|
2015-01-25 20:20:48 +01:00
|
|
|
end
|
2015-01-21 08:23:06 +01:00
|
|
|
|
|
|
|
-- release module
|
2015-04-03 17:44:26 +02:00
|
|
|
DHT = nil
|
|
|
|
package.loaded["dht_lib"]=nil
|
2015-01-21 08:23:06 +01:00
|
|
|
```
|
2015-04-03 17:44:26 +02:00
|
|
|
##Float Verison
|
|
|
|
###Example
|
|
|
|
```lua
|
|
|
|
PIN = 4 -- data pin, GPIO2
|
|
|
|
|
|
|
|
DHT= require("dht_lib")
|
|
|
|
|
|
|
|
--dht.read11(PIN)
|
|
|
|
DHT.read22(PIN)
|
|
|
|
|
|
|
|
t = DHT.getTemperature()
|
|
|
|
h = DHT.getHumidity()
|
2015-01-25 20:20:48 +01:00
|
|
|
|
2015-04-03 17:44:26 +02:00
|
|
|
if h == nil then
|
|
|
|
print("Error reading from DHT11/22")
|
|
|
|
else
|
|
|
|
-- temperature in degrees Celsius and Farenheit
|
|
|
|
-- floating point and integer version:
|
|
|
|
print("Temperature: "..t.." deg C")
|
|
|
|
print("Temperature: "..(9 * t / 50 + 32).." deg F")
|
|
|
|
|
|
|
|
-- humidity
|
|
|
|
print("Humidity: "..h.."%")
|
|
|
|
end
|
|
|
|
|
|
|
|
-- release module
|
|
|
|
DHT = nil
|
|
|
|
package.loaded["dht_lib"]=nil
|
|
|
|
```
|
|
|
|
## Functions
|
|
|
|
### read11
|
|
|
|
read11(pin)
|
|
|
|
Read humidity and temperature from DHT11.
|
|
|
|
###read22
|
|
|
|
read22(pin)
|
|
|
|
Read humidity and temperature from DHT22/21.
|
2015-01-25 20:20:48 +01:00
|
|
|
**Parameters:**
|
|
|
|
|
2015-04-03 17:44:26 +02:00
|
|
|
* pin - ESP8266 pin connect to data pin
|
2015-01-25 20:20:48 +01:00
|
|
|
|
|
|
|
### getHumidity
|
|
|
|
getHumidity()
|
|
|
|
Returns the humidity of the last reading.
|
|
|
|
|
|
|
|
**Returns:**
|
|
|
|
* last humidity reading in per thousand
|
|
|
|
|
|
|
|
### getTemperature
|
|
|
|
getTemperature()
|
|
|
|
Returns the temperature of the last reading.
|
|
|
|
|
|
|
|
**Returns:**
|
2015-04-03 17:44:26 +02:00
|
|
|
* last temperature reading in(dht22) 0.1ºC (dht11)1ºC
|
|
|
|
*
|
2015-01-25 20:20:48 +01:00
|
|
|
|