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
d155cfc5
Commit
d155cfc5
authored
Feb 02, 2015
by
Javier Yáñez
Browse files
Add support for NodeMCU with float point in the example
parent
055c55a7
Changes
1
Hide whitespace changes
Inline
Side-by-side
lua_modules/dht22/README.md
View file @
d155cfc5
# DHT22 module
# DHT22 module
This module is compatible with DHT22 and DHT21.
This module is compatible with DHT22 and DHT21.
Supports nodemcu with or without floating point.
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.
## Example
## Example
...
@@ -12,15 +13,20 @@ dht22.read(PIN)
...
@@ -12,15 +13,20 @@ dht22.read(PIN)
t
=
dht22
.
getTemperature
()
t
=
dht22
.
getTemperature
()
h
=
dht22
.
getHumidity
()
h
=
dht22
.
getHumidity
()
if
h
==
-
1
then
if
h
==
nil
then
print
(
"Error reading from DHT22"
)
print
(
"Error reading from DHT22"
)
else
else
-- temperature in degrees Celsius and Farenheit
-- temperature in degrees Celsius and Farenheit
print
(
"Temperature: "
..
(
t
/
10
)
..
"."
..
(
t
%
10
)
..
" deg C"
)
-- floating point and integer version:
print
(
"Temperature: "
..
((
t
-
(
t
%
10
))
/
10
)
..
"."
..
(
t
%
10
)
..
" deg C"
)
-- only integer version:
print
(
"Temperature: "
..
(
9
*
t
/
50
+
32
)
..
"."
..
(
9
*
t
/
5
%
10
)
..
" deg F"
)
print
(
"Temperature: "
..
(
9
*
t
/
50
+
32
)
..
"."
..
(
9
*
t
/
5
%
10
)
..
" deg F"
)
-- only float point version:
print
(
"Temperature: "
..
(
9
*
t
/
50
+
32
)
..
" deg F"
)
-- humidity
-- humidity
print
(
"Humidity: "
..
(
h
/
10
)
..
"."
..
(
h
%
10
)
..
"%"
)
-- floating point and integer version
print
(
"Humidity: "
..
((
h
-
(
h
%
10
))
/
10
)
..
"."
..
(
h
%
10
)
..
"%"
)
end
end
-- release module
-- release module
...
@@ -29,7 +35,7 @@ package.loaded["dht22"]=nil
...
@@ -29,7 +35,7 @@ package.loaded["dht22"]=nil
```
```
## Functions
## Functions
### read
### read
read(pin)
read(pin)
Read humidity and temperature from DHT22.
Read humidity and temperature from DHT22.
**Parameters:**
**Parameters:**
...
...
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