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
b4898380
Commit
b4898380
authored
Mar 08, 2015
by
zeroday
Browse files
Merge pull request #271 from ftruzzi/master
DRDYn pin support added.
parents
acf0df3a
c96c8d57
Changes
3
Hide whitespace changes
Inline
Side-by-side
lua_modules/hdc1000/HDC1000-example.lua
View file @
b4898380
...
...
@@ -2,8 +2,9 @@ HDC1000 = require("HDC1000")
sda
=
1
scl
=
2
drdyn
=
false
HDC1000
.
init
(
sda
,
scl
)
HDC1000
.
init
(
sda
,
scl
,
drdyn
)
HDC1000
.
config
()
-- default values are used if called with no arguments. prototype is config(address, resolution, heater)
print
(
string.format
(
"Temperature: %.2f °C\nHumidity: %.2f %%"
,
HDC1000
.
getTemp
(),
HDC1000
.
getHumi
()))
...
...
lua_modules/hdc1000/HDC1000.lua
View file @
b4898380
...
...
@@ -25,6 +25,7 @@ _G[modname] = M
local
id
=
0
local
i2c
=
i2c
local
delay
=
20000
local
_drdyn_pin
local
HDC1000_ADDR
=
0x40
...
...
@@ -69,7 +70,8 @@ function M.batteryDead()
end
-- initalize i2c
function
M
.
init
(
sda
,
scl
)
function
M
.
init
(
sda
,
scl
,
drdyn_pin
)
_drdyn_pin
=
drdyn_pin
i2c
.
setup
(
id
,
sda
,
scl
,
i2c
.
SLOW
)
end
...
...
@@ -84,14 +86,22 @@ end
-- outputs temperature in Celsius degrees
function
M
.
getHumi
()
setReadRegister
(
HDC1000_HUMI
)
tmr
.
delay
(
delay
)
if
(
_drdyn_pin
~=
false
)
then
gpio
.
mode
(
_drdyn_pin
,
gpio
.
INPUT
)
while
(
gpio
.
read
(
_drdyn_pin
)
==
1
)
do
end
else
tmr
.
delay
(
delay
)
end
return
(
read16
()
/
65535
.
0
*
100
)
end
-- outputs humidity in %RH
function
M
.
getTemp
()
setReadRegister
(
HDC1000_TEMP
)
tmr
.
delay
(
delay
)
if
(
_drdyn_pin
~=
false
)
then
gpio
.
mode
(
_drdyn_pin
,
gpio
.
INPUT
)
while
(
gpio
.
read
(
_drdyn_pin
)
==
1
)
do
end
else
tmr
.
delay
(
delay
)
end
return
(
read16
()
/
65535
.
0
*
165
-
40
)
end
...
...
lua_modules/hdc1000/README.md
View file @
b4898380
...
...
@@ -10,7 +10,11 @@ First, require it:
Then, initialize it:
`HDC1000.init(sda, scl)`
`HDC1000.init(sda, scl, drdyn)`
If you don't want to use the DRDYn pin, set it to false: a 20ms delay will be automatically set after each read request.
`HDC1000.init(sda, scl, false)`
Configure it:
...
...
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