I have multiple DS18B20 on the 1wire and sometime these may be removed or changed so having fixed ID's will not work.
The routines I use are below and work until I use an interrupt with an analogue sensor check.
As soon as the analogue signal changes too fast it effects the routines and devices can change to more or less than on the bus.
Any suggestions.
It starts main with Getsensors and then Getsensorvalues.
it check \getsensorvalues in a while loop with a check of Getsensors every 58 seconds.
If the alanlogue level is changing fast in the 58 sec mark then var devices is incorrect.
Sub OnDeviceFound(command As Byte, family As Byte, ByRef romID() As Byte, ByRef abort As Boolean) Handles OW.OnSearch
Console.Write(13,10)
if devices = 0 then
romID1 = romID
Console.Write("romID1 : ")
for index as byte = 0 to ubound(romID1)
Console.Write("&H", Hex(romID1(index),2)," ")
next
end if
if devices = 1 Then
romID2 = romID
Console.Write("romID2 : ")
for index as byte = 0 to ubound(romID2)
Console.Write("&H", Hex(romID2(index),2)," ")
next
end if
if devices = 2 Then
romID3 = romID
Console.Write("romID3 : ")
for index as byte = 0 to ubound(romID3)
Console.Write("&H", Hex(romID3(index),2)," ")
next
end if
devices = devices + 1
End Sub
Sub Getsensors()
OW.Search()
if devices > 0 then
DS18B20_Available = True
end if
Console.Write(Str(devices))
If DS18B20_Available Then
DS18B20.SetResolution(Resolution.Is9Bit)
end if
End sub
Sub Getsensorvalues()
if DS18B20_Available and devices >=1 then
'Get Led Temp1
DS18B20.ROMID = romID1
DS18B20.SetResolution(Resolution.Is9Bit)
DS18B20.Convert()
DS18B20.GetTemp(Temp1,TempFrac)
end if
'Get Abient Temp2
if DS18B20_Available and devices >=2 then
DS18B20.ROMID = romID2
DS18B20.SetResolution(Resolution.Is9Bit)
DS18B20.Convert()
DS18B20.GetTemp(Temp2,TempFrac)
end if
'Get Abient Temp3
if DS18B20_Available and devices >=3 then
DS18B20.ROMID = romID3
DS18B20.SetResolution(Resolution.Is9Bit)
DS18B20.Convert()
DS18B20.GetTemp(Temp3,TempFrac)
end if
End Sub