Multiple DS18B20

Information and discussion regarding Firewing shields

Re: Multiple DS18B20

Postby David John Barker » Tue Jan 07, 2014 2:35 pm

Sorry, it should be getTemp() - Firewing modules are open source, so you can use the explorer window to see what public variables, subs and functions are available and also open the module in the editor window to see how it all works...

explorer.jpg
explorer.jpg (93.58 KiB) Viewed 17002 times
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: Multiple DS18B20

Postby AndrewB » Tue Jan 21, 2014 7:38 pm

Have tried to read devices rather than fixed values and the routine works as is but when trying to incorporate it into the progLCDPlus program it does not!
Any ideas what the problem is?


Imports OW ' one wire, used for search
Imports DS18B20 ' temperature sensor module
' secure digital (SD) module

' program variables...
private DS18B20_Available As Boolean = False ' DS18B20 is available flag
' date variable
dim romID1(8) as byte
dim romID2(8) as byte
dim romID3(8) as byte
Dim devices as byte = 0
' Declarations...



' one wire, used for search
Imports OW

' the event is triggered each time the OW module is asked to
' perform a search - here we will list all devices connected to
' the one wire bus...
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
if devices >=1 then DS18B20_Available = True ' mark as available
End Sub

' display a list of all devices connected to the bus...

Sub Main()
OW.Search()
Console.Write(13,10)
Console.Write("Devices found : ",Str(devices))
End Sub
AndrewB
 
Posts: 94
Joined: Thu Jan 02, 2014 3:38 pm

Re: Multiple DS18B20

Postby David John Barker » Tue Jan 21, 2014 7:50 pm

No idea - I assume the above is working code? You need to post the (smallest) code that does not work and what the problem is - also, could you please use code start and end tags when posting - it makes it much easier to read...
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: Multiple DS18B20

Postby David John Barker » Tue Jan 21, 2014 8:02 pm

OK, I added this to the above code:
Code: Select all
Sub Main()
   Dogm.Clear 
   Dogm.SetBacklight(512) 
   
   OW.Search()
   Console.Write(13,10)
   Console.Write("Devices found : ",Str(devices))
   dogm.WriteAt(1,1,"Found : ",Str(devices))
End Sub

and the LCD correctly displayed "Found : 2". In addition, the serial communicator window displayed:
Code: Select all
romID1 : &H28 &HDE &H7E &H59 &H04 &H00 &H00 &HD3
romID2 : &H05 &H5D &HF7 &H19 &H00 &H00 &H00 &HF1
Devices found : 2

It appears your code does work correctly with the LCD.
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: Multiple DS18B20

Postby AndrewB » Wed Jan 22, 2014 12:39 pm

Ah :oops: a typo error.

Works OK.
AndrewB
 
Posts: 94
Joined: Thu Jan 02, 2014 3:38 pm

Re: Multiple DS18B20

Postby David John Barker » Wed Jan 22, 2014 2:49 pm

If using multiple OW devices on the bus, you might want to take a look at the following code which shows you how to create an array of ow device structures
Code: Select all
' import modules...
Imports DS18B20           ' temperature sensor module
Imports OW                ' one wire, used for search

' OW rom structure...
structure OwRomId
   romID(8) as byte
   family as byte
end structure

' program constants and variables...
const MAX_ROM = 8                  ' max number of likely Ow devices
dim owDevices(MAX_ROM) as OwRomId  ' array of rom ids
dim deviceCount as byte = 0        ' number of devices

' device found event...
Sub OnDeviceFound(command As Byte, family As Byte, ByRef romID() As Byte, ByRef abort As Boolean) Handles OW.OnSearch
   owDevices(deviceCount).romID = romID    ' save rom ID
   owDevices(deviceCount).family = family  ' save family
   deviceCount += 1                        ' next
End Sub

' main program entry point...
Sub Main()   
   OW.Search()
   Console.Write("Devices found : ",CStr(deviceCount),13,10)
   for deviceIndex as byte = 0 to deviceCount - 1
      for index as byte = 0 to ubound(Ow.RomID)
         Console.Write("&H", Hex(owDevices(deviceIndex).RomId(index),2)," ")
      next
      console.write(13,10)
   next
End Sub

which will output something like
Code: Select all
Devices found : 2
&H28 &HDE &H7E &H59 &H04 &H00 &H00 &HD3
&H05 &H5D &HF7 &H19 &H00 &H00 &H00 &HF1
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: Multiple DS18B20

Postby AndrewB » Wed Jan 22, 2014 3:14 pm

Thanks.

I have used pic basic before so the new language structure is new to me.
I will take a look and work out how it this all works

Thanks again
AndrewB
 
Posts: 94
Joined: Thu Jan 02, 2014 3:38 pm

Previous

Return to Shields

Who is online

Users browsing this forum: No registered users and 1 guest

cron

x