2017-02-25 22:56:45 +01:00
-- encoder module is needed only for debug output; lines can be removed if no
-- debug output is needed and/or encoder module is missing
2015-01-10 10:58:08 +01:00
t = require ( " ds18b20 " )
2017-02-25 22:56:45 +01:00
pin = 3 -- gpio0 = 3, gpio2 = 4
2015-01-10 10:58:08 +01:00
2017-02-25 22:56:45 +01:00
function readout ( temp )
for addr , temp in pairs ( temp ) do
-- print(string.format("Sensor %s: %s 'C", addr, temp))
2017-03-07 07:06:50 +01:00
print ( string.format ( " Sensor %s: %s °C " , encoder.toHex ( addr ) , temp ) ) -- readable address with base64 encoding is preferred when encoder module is available
2017-02-25 22:56:45 +01:00
end
2015-01-10 10:58:08 +01:00
2017-02-25 22:56:45 +01:00
-- Module can be released when it is no longer needed
t = nil
package.loaded [ " ds18b20 " ] = nil
2015-01-10 10:58:08 +01:00
end
2017-02-25 22:56:45 +01:00
-- t:readTemp(readout) -- default pin value is 3
t : readTemp ( readout , pin )
if t.sens then
print ( " Total number of DS18B20 sensors: " .. table.getn ( t.sens ) )
for i , s in ipairs ( t.sens ) do
-- print(string.format(" sensor #%d address: %s%s", i, s.addr, s.parasite == 1 and " (parasite)" or ""))
2017-03-07 07:06:50 +01:00
print ( string.format ( " sensor #%d address: %s%s " , i , encoder.toHex ( s.addr ) , s.parasite == 1 and " (parasite) " or " " ) ) -- readable address with base64 encoding is preferred when encoder module is available
2017-02-25 22:56:45 +01:00
end
2016-01-17 14:39:39 +01:00
end