Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
b1287756
Commit
b1287756
authored
Apr 05, 2015
by
Martin Han
Browse files
Adjust the detail, fix program bug
parent
bcbde08b
Changes
1
Show whitespace changes
Inline
Side-by-side
lua_modules/dht_lib/README.md
0 → 100644
View file @
b1287756
# DHTxx module
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.
##Integer Verison[When using DHT11, Float version is useless...]
### Example
```
lua
PIN
=
4
-- data pin, GPIO2
DHT
=
require
(
"dht_lib"
)
DHT
.
read
(
PIN
)
t
=
DHT
.
getTemperature
()
h
=
DHT
.
getHumidity
()
if
h
==
nil
then
print
(
"Error reading from DHTxx"
)
else
-- temperature in degrees Celsius and Farenheit
print
(
"Temperature: "
..
((
t
-
(
t
%
10
))
/
10
)
..
"."
..
(
t
%
10
)
..
" deg C"
)
print
(
"Temperature: "
..
(
9
*
t
/
50
+
32
)
..
"."
..
(
9
*
t
/
5
%
10
)
..
" deg F"
)
-- humidity
print
(
"Humidity: "
..
((
h
-
(
h
%
10
))
/
10
)
..
"."
..
(
h
%
10
)
..
"%"
)
end
-- release module
DHT
=
nil
package.loaded
[
"dht_lib"
]
=
nil
```
##Float Verison
###Example
```
lua
PIN
=
4
-- data pin, GPIO2
DHT
=
require
(
"dht_lib"
)
DHT
.
read
(
PIN
)
t
=
DHT
.
getTemperature
()
h
=
DHT
.
getHumidity
()
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
/
10
)
..
" deg C"
)
print
(
"Temperature: "
..
(
9
*
t
/
50
+
32
)
..
" deg F"
)
-- humidity
print
(
"Humidity: "
..
(
h
/
10
)
..
"%"
)
end
-- release module
DHT
=
nil
package.loaded
[
"dht_lib"
]
=
nil
```
## Functions
###read
read(pin)
Read humidity and temperature from DHTxx(11,21,22...).
**Parameters:**
*
pin - ESP8266 pin connect to data pin
### 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:**
*
last temperature reading in(dht22) 0.1ºC (dht11)1ºC
*
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment