This application shows an example of a way to connect DS18B20 temperature sensors to 1 wire converter.
Figure below shows how to connect DS18B20 to the converter.
In case you want to connect more than one sensor:
Here's script, which on startup scans for defined number of temperature sensors and on wakeup sends temperature of each sensor over LoRaWAN (in this case).
--Power pin
powerpin=1
--Data pin
datapin=2
function onWake ()
buf,err,ack,wake = api.getGUIContext()
-- Read number of found devices to #48
no_dev = api.getVar(48)
addr = {}
-- Loop over devices and store their addresses to EEPROM
for i = 1, no_dev, 1
do
-- Reconstruct address from EEPROM
for j = 1, 8, 1
do
-- Read address bytes from EEPROM
addr[j] = api.getVar(48+(i-1)*8+j)
end
temp=api.ds18b20GetTemp(1,2,addr)
print("Temp #" .. i .. " " .. temp/1000 .. "C")
buf=buf .. temp
end
api.dumpArray(buf)
print("Send to LORA")
api.loraSend(ack,20000,buf)
print("Done sending")
api.wakeUpIn(0,0,wake,0)
end
function onStartup()
print("Starting up LUA DS18B20 script...")
found = api.ds18b20Search(powerpin, datapin)
if (found)
then
print("Found " .. #found .. " devices")
-- Store number of found devices to #48
api.setVar(48, #found)
-- Loop over devices and store their addresses to EEPROM
for i = 1, #found, 1
do
-- Loop over address bytes
for j = 1, 8, 1
do
-- Store address bytes to EEPROM
-- Device 1 address is at 49,50,51,52,53,54,55,56 etc.
-- Device 2 address is at 57,58, ...
api.setVar(48+(i-1)*8+j, found[i][j])
end
end
else
api.setVar(48, 0)
end
end