Adjust the detail, fix program bug
This commit is contained in:
parent
10ccfc6ad2
commit
d625198209
|
@ -1,6 +1,8 @@
|
||||||
# DHTxx module
|
# DHTxx module
|
||||||
|
|
||||||
This module is compatible with DHT11, DHT21 and DHT22.
|
This module is compatible with DHT11, DHT21 and DHT22.
|
||||||
|
And is able to auto-select wheather you are using DHT11 or DHT2x
|
||||||
|
|
||||||
No need to use a resistor to connect the pin data of DHT22 to ESP8266.
|
No need to use a resistor to connect the pin data of DHT22 to ESP8266.
|
||||||
|
|
||||||
##Integer Verison[When using DHT11, Float version is useless...]
|
##Integer Verison[When using DHT11, Float version is useless...]
|
||||||
|
@ -10,14 +12,13 @@ PIN = 4 -- data pin, GPIO2
|
||||||
|
|
||||||
DHT= require("dht_lib")
|
DHT= require("dht_lib")
|
||||||
|
|
||||||
--dht.read11(PIN)
|
DHT.read(PIN)
|
||||||
DHT.read22(PIN)
|
|
||||||
|
|
||||||
t = DHT.getTemperature()
|
t = DHT.getTemperature()
|
||||||
h = DHT.getHumidity()
|
h = DHT.getHumidity()
|
||||||
|
|
||||||
if h == nil then
|
if h == nil then
|
||||||
print("Error reading from DHT11/22")
|
print("Error reading from DHTxx")
|
||||||
else
|
else
|
||||||
-- temperature in degrees Celsius and Farenheit
|
-- temperature in degrees Celsius and Farenheit
|
||||||
|
|
||||||
|
@ -41,8 +42,7 @@ PIN = 4 -- data pin, GPIO2
|
||||||
|
|
||||||
DHT= require("dht_lib")
|
DHT= require("dht_lib")
|
||||||
|
|
||||||
--dht.read11(PIN)
|
DHT.read(PIN)
|
||||||
DHT.read22(PIN)
|
|
||||||
|
|
||||||
t = DHT.getTemperature()
|
t = DHT.getTemperature()
|
||||||
h = DHT.getHumidity()
|
h = DHT.getHumidity()
|
||||||
|
@ -52,11 +52,12 @@ if h == nil then
|
||||||
else
|
else
|
||||||
-- temperature in degrees Celsius and Farenheit
|
-- temperature in degrees Celsius and Farenheit
|
||||||
-- floating point and integer version:
|
-- floating point and integer version:
|
||||||
print("Temperature: "..t.." deg C")
|
|
||||||
|
print("Temperature: "..(t/10).." deg C")
|
||||||
print("Temperature: "..(9 * t / 50 + 32).." deg F")
|
print("Temperature: "..(9 * t / 50 + 32).." deg F")
|
||||||
|
|
||||||
-- humidity
|
-- humidity
|
||||||
print("Humidity: "..h.."%")
|
print("Humidity: "..(h/10).."%")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- release module
|
-- release module
|
||||||
|
@ -64,12 +65,10 @@ DHT = nil
|
||||||
package.loaded["dht_lib"]=nil
|
package.loaded["dht_lib"]=nil
|
||||||
```
|
```
|
||||||
## Functions
|
## Functions
|
||||||
### read11
|
|
||||||
read11(pin)
|
###read
|
||||||
Read humidity and temperature from DHT11.
|
read(pin)
|
||||||
###read22
|
Read humidity and temperature from DHTxx(11,21,22...).
|
||||||
read22(pin)
|
|
||||||
Read humidity and temperature from DHT22/21.
|
|
||||||
**Parameters:**
|
**Parameters:**
|
||||||
|
|
||||||
* pin - ESP8266 pin connect to data pin
|
* pin - ESP8266 pin connect to data pin
|
||||||
|
|
Loading…
Reference in New Issue