Using two DS18B20 sensors but only oe reads

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
toyman
Posts: 39
Joined: Tue Feb 18, 2014 8:25 pm

Using two DS18B20 sensors but only oe reads

Post by toyman » Fri May 02, 2014 3:48 am

I tested the two sensors and both work using same multiple DS18B20displayall.bas code sample. Ran code with only one sensor connected and both sensors output a temp reading and different ROMID #'s (sensors bought on Ebay)
When connecting both sensors only one reads. Using the software UART. Changed the pull up resistor to recommended 4.7K
Have sensor 1 in ice bath while sensor 2 in ambient air laying on bench. Any ideas why only one sensor reads and it is always the same sensor (ice bath clarified this)

Code: Select all


DEVICE = 18F2420
CLOCK = 8

// import modules...
INCLUDE "DS18B20.bas"
INCLUDE "convert.bas"
INCLUDE "suart.bas"
INCLUDE "internalOscillator.bas"
INCLUDE  "Utils.bas"
// on display temperature event...
EVENT OnDisplayTemp()
   DIM TempA AS SHORTINT
   DIM TempB AS WORD
   DIM Index AS BYTE
   DIM tempf AS WORD
   RomID = SearchRomID
   GetTemp(TempA, TempB)
   UART.Write(DecToStr(TempA),".",DecToStr(TempB,4), $BA, "C")
     tempf = ((TempA*10+TempB/1000)*9/5+320)/10
                uart.write ("tempeature=",dectostr(tempf),13,10)
                DELAYMS(1000)
   // display ROM ID...
   UART.Write(" ($")
   Index = 6
   REPEAT
      UART.Write(HexToStr(SearchRomID(index),2))
     ' delayms(1000)
     
      DEC(Index) 
       
   UNTIL Index = 0
   UART.Write(")",13,10)
END EVENT
   
// program start...
uart.SetBaudrate(sbr9600)
uart.setmode(umtrue)
uart.settx(portb.7)
SetPin(PORTC.2)
setalldigital
// if we have some DS1820 devices connected to the bus,
// then display temperature for each one...
 IF Count > 0 THEN
   WHILE true
  
      ConvertAll               
      FindAll(OnDisplayTemp)
      DELAYMS(1000)
      
       'delayms(1000)
     
   WEND
ENDIF 

   
   

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Re: Using two DS18B20 sensors but only oe reads

Post by David Barker » Fri May 02, 2014 7:51 am

Study this article

http://www.sfcompiler.co.uk/wiki/pmwiki ... B20Article

which shows you how to read multiple devices. You can then modify the code to perform a search and load an array of romIDs to handle dynamic initialisation. There is some Firewing code which does this:

http://www.firewing.info/pmwiki.php?n=F ... MultipleOw

toyman
Posts: 39
Joined: Tue Feb 18, 2014 8:25 pm

Re: Using two DS18B20 sensors but only oe reads

Post by toyman » Fri May 02, 2014 3:31 pm

Thanks
I was considering doing something similar but by testing and noting ID of each sensor seperatly. Using the OW search helps a bunch.
Will give it a whirl

toyman
Posts: 39
Joined: Tue Feb 18, 2014 8:25 pm

Re: Using two DS18B20 sensors but only oe reads

Post by toyman » Fri May 02, 2014 8:21 pm

The problem that I had reading multiple sensors but the program would not output more than one sensor was apparently due to the software uart. I tried using the hardware uart and all is a go.
WHY?? at this point I am moving on with this project. I now need to concoct a math formula to determine refrigeration efficiency using outside temp vers inside box temp. Basically how fast the refrigeration cools down the area inside a walk in beer cooler. Desired temp is 34degrees.
Thanks for the input David. I plan to utilize the code example for the two sensors.

Post Reply