-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetTempIDs.lua
45 lines (36 loc) · 1021 Bytes
/
getTempIDs.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
dsModule = require("ds18b20")
-- Pin that the probes are connected to
-- In this case this is pin D1
dsModule.setup(1)
-- Initializes addresses and the number of probes
-- Reads the probes three times to stop it from returning 85C
function initDS()
addrs = dsModule.addrs()
num_probes = table.getn(addrs)
for j = 1, 3 do
for i = 1, num_probes do
temp = dsModule.read(addrs[i],dsModule.C)
end
end
tmr.alarm(0,500, 0, getDSids)
end
-- Prints information about the probes
function getDSids()
print("Number of Sensors: "..num_probes)
id_int_format = "%u,%u,%u,%u,%u,%u,%u,%u"
if (num_probes > 0) then
for i = 1, num_probes do
string_id=string.format(id_int_format,addrs[i]:byte(1,9))
print("Probe "..i.." Unique ID: "..string_id.." ")
end
end
for i = 1, num_probes do
temp = dsModule.read(addrs[i],dsModule.C)
print("Temp Probe "..i..": "..temp.." deg C")
end
-- Cleanup
dsModule = nil
ds18b20 = nil
package.loaded["ds18b20"]=nil
end
initDS()