Multiple DS18B20

Information and discussion regarding Firewing shields

Multiple DS18B20

Postby AndrewB » Mon Jan 06, 2014 11:23 am

Just started today to look at the firewing and shield.
I'm afraid my coding is at a novice level.
What do I need to add to the proglcdplus program to add a couple of extra DS18B20?
AndrewB
 
Posts: 94
Joined: Thu Jan 02, 2014 3:38 pm

Re: Multiple DS18B20

Postby David John Barker » Mon Jan 06, 2014 12:14 pm

First of all, you need to understand how the "progLCDPlus" program finds a single DS18B20. You should notice a call to
Code: Select all
OW.Search()

This will instruct the module to try and locate a DS18B20 device connected to the bus. A search command invokes this routine:
Code: Select all
Sub OnDeviceFound(command As Byte, family As Byte, ByRef romID() As Byte, ByRef abort As Boolean) Handles OW.OnSearch
   If command = owSearchROM And   family = DS18B20.Family Then
      DS18B20_Available = True   ' mark as available
      DS18B20.ROMID = romID     ' set the unique ROM id...
      abort = True              ' no more searching required   
   End If
End Sub

notice the line "DS18B20.ROMID = romID" - this sets the rom id address to the first DS18B20 found. The search is then aborted (abort = True). So, you can address a particular DS18B20 by setting:
Code: Select all
DS18B20.ROMID = romID

You can set a ROM ID manually before using the DS18B20, without performing a search. For example:
Code: Select all
   dim romID() as byte = {&H28, &HDE, &H7E, &H59, &H04, &H00, &H00, &HD3}
   DS18B20.RomID = RomID

To find the address of a device or set of devices, just execute this code:
Code: Select all
 ' 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
   
   ' display family...
   Console.Write("&H", Hex(family,2)," : ")
   
   ' display unique identifier...
   for index as byte = 0 to ubound(romID)
      Console.Write("&H", Hex(romID(index),2)," ")
   next
   Console.Write(13,10)
End Sub

' display a list of all devices connected to the bus...
sub Main() 
   OW.Search()
end sub

which will output something like:
Code: Select all
&H28 : &H28 &HDE &H7E &H59 &H04 &H00 &H00 &HD3

Now all you need to do is set the correct romID to the correct DS18B20 device before performing a read.
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: Multiple DS18B20

Postby AndrewB » Mon Jan 06, 2014 12:48 pm

Thanks David I will try this out.

FYI
I have added #option OW_PIN = PORTB.6 as you had earlier advised to place the DS18B20 on port D2 for 5v drive.
I have added a 1K5 pullup to the sensor which is 20 meters away and all work well.
AndrewB
 
Posts: 94
Joined: Thu Jan 02, 2014 3:38 pm

Re: Multiple DS18B20

Postby David John Barker » Mon Jan 06, 2014 1:42 pm

Thanks for posting your results, really useful - what type of cabling did you use?
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: Multiple DS18B20

Postby AndrewB » Tue Jan 07, 2014 10:13 am

I had some Van Damme audio cable 268-001-000 used for patch work. What I had in stock.
I will probably use a twisted pair screened cable.

Looks like D2 popped as this no longer works.
Maybe the 1k5 was too high? It's below the 4ma @ 5v.
Or maybe the 5v tolerance is not so tolerant.
It works on 3.3v @ distance.

I will get another and place a resistor in series.

Maxim make a tx/rx to 1 wire maybe this would be an option and safer.

Ok I have the devices ID numbers and I have placed.
Using the LCDPLUS prog

dim AMBromID() as byte = {&H28,&HD8,&H99,&H21,&H05,&H00,&H00,&HF5}
dim LEDromID() as byte = {&H28,&H69,&HA8,&H21,&H05,&H00,&H00,&H8C}

later on

DS18B20.ROMID = AMBromID
DS18B20.Convert()
Dogm.WriteAt(3,1, DS18B20.AsString, &HDF, "C")
DS18B20.ROMID = LEDromID
DS18B20.Convert()
Dogm.WriteAt(3,11, DS18B20.AsString, &HDF, "C")

It's reading the temps of both but the second device is reading several decimal points and not displaying the oC.
AndrewB
 
Posts: 94
Joined: Thu Jan 02, 2014 3:38 pm

Re: Multiple DS18B20

Postby AndrewB » Tue Jan 07, 2014 10:31 am

Ok I have done this.

DS18B20.ROMID = LEDromID
DS18B20.SetResolution(Resolution.Is9Bit)
DS18B20.Convert()
Dogm.WriteAt(3,1,"L ", DS18B20.AsString, &HDF, "C")
DS18B20.ROMID = AMBromID
DS18B20.SetResolution(Resolution.Is9Bit)
DS18B20.Convert()
Dogm.WriteAt(3,9,"A ", DS18B20.AsString, &HDF, "C")

and its now to one decimal place.
AndrewB
 
Posts: 94
Joined: Thu Jan 02, 2014 3:38 pm

Re: Multiple DS18B20

Postby AndrewB » Tue Jan 07, 2014 12:45 pm

How do I read the temp value to be compared in an IF Then?
AndrewB
 
Posts: 94
Joined: Thu Jan 02, 2014 3:38 pm

Re: Multiple DS18B20

Postby David John Barker » Tue Jan 07, 2014 1:38 pm

Code: Select all
            dim tempWhole as sbyte
            dim tempFrac as ushort
            DS18B20.GetTemp(tempWhole, tempFrac)

will read the whole and fractional part of the temperature which you could use for comparison. Alternatively,
Code: Select all
            dim theTemp as ushort = DS18B20.ReadTemp()

will read the DS18B20 scratch pad registers 0 and 1 (tmp LSB and MSB respectively) which you may find useful.
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: Multiple DS18B20

Postby AndrewB » Tue Jan 07, 2014 2:10 pm

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

Re: Multiple DS18B20

Postby AndrewB » Tue Jan 07, 2014 2:28 pm

dim theTemp as ushort = DS18B20.ReadTemp()

comes up error identifier not declared :ReadTemp
& Incompatible types
AndrewB
 
Posts: 94
Joined: Thu Jan 02, 2014 3:38 pm

Next

Return to Shields

Who is online

Users browsing this forum: No registered users and 1 guest

cron

x