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
adfffb89
Commit
adfffb89
authored
Dec 08, 2014
by
HuangRui
Browse files
* Changed ds18b20.lua to ds18b20-example.lua
parent
019fe9f5
Changes
1
Hide whitespace changes
Inline
Side-by-side
examples/ds18b20.lua
deleted
100644 → 0
View file @
019fe9f5
--'
-- 18b20 one wire example for NODEMCU
-- NODEMCU TEAM
-- LICENCE: http://opensource.org/licenses/MIT
-- Vowstar <vowstar@nodemcu.com>
--'
pin
=
9
ow
.
setup
(
pin
)
count
=
0
repeat
count
=
count
+
1
addr
=
ow
.
reset_search
(
pin
)
addr
=
ow
.
search
(
pin
)
tmr
.
wdclr
()
until
((
addr
~=
nil
)
or
(
count
>
100
))
if
(
addr
==
nil
)
then
print
(
"No more addresses."
)
else
print
(
addr
:
byte
(
1
,
8
))
crc
=
ow
.
crc8
(
string.sub
(
addr
,
1
,
7
))
if
(
crc
==
addr
:
byte
(
8
))
then
if
((
addr
:
byte
(
1
)
==
0x10
)
or
(
addr
:
byte
(
1
)
==
0x28
))
then
print
(
"Device is a DS18S20 family device."
)
repeat
ow
.
reset
(
pin
)
ow
.
select
(
pin
,
addr
)
ow
.
write
(
pin
,
0x44
,
1
)
tmr
.
delay
(
1000000
)
present
=
ow
.
reset
(
pin
)
ow
.
select
(
pin
,
addr
)
ow
.
write
(
pin
,
0xBE
,
1
)
print
(
"P="
..
present
)
data
=
nil
data
=
string.char
(
ow
.
read
(
pin
))
for
i
=
1
,
8
do
data
=
data
..
string.char
(
ow
.
read
(
pin
))
end
print
(
data
:
byte
(
1
,
9
))
crc
=
ow
.
crc8
(
string.sub
(
data
,
1
,
8
))
print
(
"CRC="
..
crc
)
if
(
crc
==
data
:
byte
(
9
))
then
t
=
(
data
:
byte
(
1
)
+
data
:
byte
(
2
)
*
256
)
*
625
t1
=
t
/
10000
t2
=
t
%
10000
print
(
"Temperature= "
..
t1
..
"."
..
t2
..
" Centigrade"
)
end
tmr
.
wdclr
()
until
false
else
print
(
"Device family is not recognized."
)
end
else
print
(
"CRC is not valid!"
)
end
end
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