Multipoint temperature readings on 18m2

Captain Haddock

Senior Member
I have just been playing with trying to read multiple temp sensors on one wire using 18B20's , I have the serial numbers off the sensors but can only track down a command that works with 20X2, is there a work around been done for an 18M2? or am I just urinating in an isobarically disadvantaged direction?
I can see a major advantage using this trick for a couple of the projects I am working on, I didn't realise these things could do this till I read the full datasheet.
 

Captain Haddock

Senior Member
I though I might get my legs wet, I'll have a good read through that, thanks.
Looks like I better order a 20X2 then...

Added... 20X2 ordered!
Excellent pdf, thanks for compiling such a useful guide!
 
Last edited:

Captain Haddock

Senior Member
Should this unit work with parasite power when using readtemp on M2's or is that only useable with true 1 wire setup?
I've tried it and just get the standard 85 degrees showing, it must be powering up or 0 degrees would show but not giving the M2 the temp reading.
 

MartinM57

Moderator
Parasitic power does not work - you need to supply +5v to the sensor

Manual 2 - readtemp command...
This command is not designed to be used with parasitically powered DS18B20 sensors, the 5V pin of the sensor must always be connected.
 

westaust55

Moderator
Parasitic powered DB18B20's will function with the OWIN and OWOUT commands while the DS18B20 chips (even multiples on 1 line) are close to the PICAXE
but as I recall from my work when the temp sesors are some distance away (in terms of cable length) then actively powered from the +5Vdc was essential.
The pull-up resistor can be reduced ( even down to around 2.2 kOhms ) when multiple devices are present and if you look to having all temp sensors do the
conversion pretty much simultaneously then a reduced value will be essential.
 

Captain Haddock

Senior Member
20x2 arrived, have it reading a ds1307 rtc and displaying fine on lcd, have it addressing and displaying temp from 2x ds18b20's ok but it's done in ascii(modified borrowed code), is there a nice short way of converting the owin result into a whole degree only figure that can be used in calculations, I've seen some bits of code but maths was never my thing and I can't get it doing anything useful as I don't understand most of what it's doing.
The bit of code I am reading with at the moment is:
Code:
init:	pause 500
	serout B.0,N2400,(254,1)
	symbol line1 = 128
	symbol line2 = 192
Gettemps:

	pause 50
	let b0 = line1
	owout b.7,%1001,($55,40,51,163,51,3,0,0,243,$44)    ' reset(send match rom ,send convert t)
  	owout b.7,%0001,($55,40,51,163,51,3,0,0,243,$BE)    ' reset(send match rom ,send read lsb msb)
                          
     	gosub Convert
	let b0 = line2
	owout b.7,%1001,($55,40,65,188,51,3,0,0,22,$44)     ' reset(send match rom ,send convert t)
  	owout b.7,%0001,($55,40,65,188,51,3,0,0,22,$BE)     ' reset(send match rom ,send read lsb msb)

	gosub Convert

     	goto Gettemps

Convert:  
	owin b.7,%0000,(b2,b3)        '  info     + 125 degrees / 0.0625 =  2000
      let b9 =43                	' Display + (43) space (32)
     	IF W1 > 64655 THEN            '  info     -  55 degrees = 64656
      let b9 =45                	' Display - (45)
     	W1 = - W1                 	'  info  if - ie w1=5500  Display -  55.00 C
     	ENDIF                      	          
      W1 = W1 * 25 / 4              '  info     + ie w1=12500 Display + 125.00 C
                                          
	BINTOASCII w1,b8,b7,b6,b5,b4 
	IF b8 = "0" THEN  : b8 = " "  :ENDIF                   ' zero blanking b8
	IF b8 =  " "  AND  b7 =  "0"  THEN : b7 = " "  :ENDIF  ' zero blanking b7
	serout B.0,N2400,(254,b0)
	serout B.0,N2400,("Temp",b9,b8,b7,b6,".",b5,b4," C") ' resolution to 0.06
	pause 50

	return
 

marks

Senior Member
Hi Captain Haddock,
Dont let Pete see this he'll send you back too Skhool lol !
Its always interesting to rewrite some code.
maybe i'll get it write one day . lol
Hopefully this works and its a bit closer to what you want !


Code:
# Picaxe20x2

SYMBOL Ds18b20       = B.7
SYMBOL Temperature   = W1 : SYMBOL TempLsb       = b2 : SYMBOL TempMsb      = b3
SYMBOL Sign          = b9

Celsius:
owout Ds18b20,%1001,($CC,$44)                     ' reset(send skip rom ,send convert t) 
owout Ds18b20,%0001,($CC,$BE)                     ' reset(send skip rom ,send read )
owin  Ds18b20,%0000,(TempLsb,TempMsb)             ' read in result  

     Convert:
     TempMsb = Temperature >> 4 : let Sign = " "                               ' Display  space for +
     IF TempMsb > 127 THEN      : let Sign = "-" : TempMsb = - TempMsb : ENDIF ' Display -
                                   
SERTXD (CR, LF, "Temperature  ",Sign,#TempMsb,"  Degrees C", CR, LF)      
pause 1000
goto Celsius
 

Captain Haddock

Senior Member
You recognise the original code then :eek: told you it was 'borrowed', thanks for that by the way.
I'll have a go with the new bit later, thank you very much.
 

westaust55

Moderator
For example 1-Wire network code which also adjusts the sensor resolution and reads multiple devices on one network see post 14 here: http://www.picaxeforum.co.uk/showthread.php?15306-One-Wire-Devices-Networks/page2

For integer only, the lower 4 bits are the fractional degree part, so after you check the most significant bit for negative values you can divide by 16 to have just the integer portion.

From my code example:
Code:
; now fractional part done we can alter w0 to work out the whole/Integer portion to suit the required resolution 
w0 = w0 AND $07FF >> 4 ; mask off all the 5 sign bits and shift right 4 bits to leave only integer portion.
for the 18M2, change the >> 4 part to / 16
 
Last edited:

Captain Haddock

Senior Member
I just can't get the one-wire to work when reading from i2c in the same program, is there a known glitch or is it just me doing something stupid?
As soon as I comment out the i2c lines it works fine, have tried hi2c as well and it's the same, i2c clock works fine just the temps stop updating.
code is:
Code:
init:	pause 500
	
	serout B.0,N2400,(254,1)
	SYMBOL line1 = 128
	SYMBOL line2 = 192
	SYMBOL Ds18b20       = B.7
      SYMBOL Temperature   = W12 
      SYMBOL TempLsb       = b24 
      SYMBOL TempMsb       = b25 
      SYMBOL Sign          = b26
      symbol RTC=%11010000
      hi2csetup i2cmaster, RTC,i2cslow,i2cbyte	'set up i2c DS1307 RTC

Gettemps:

	pause 50
	let b18 = line2
	owout Ds18b20,%1001,($55,40,51,163,51,3,0,0,243,$44)
	pause 500    
  	owout Ds18b20,%0001,($55,40,51,163,51,3,0,0,243,$BE) 
  	  
     	gosub Convert
     	serout B.0,N2400,(254,192)
	serout B.0,N2400,("1:",Sign,#TempMsb,%11011111,"C")
	let b18 = line2
	owout Ds18b20,%1001,($55,40,65,188,51,3,0,0,22,$44) 
	pause 500    
  	owout Ds18b20,%0001,($55,40,65,188,51,3,0,0,22,$BE) 
  	   
	gosub Convert
	serout B.0,N2400,(254,201)
	serout B.0,N2400,("2:",Sign,#TempMsb,%11011111,"C")

gettime:	
	hi2cin 0,(b0,b1,b2,b3,b4,b5,b6,b7)	'read Time and Date
	bcdtoascii b0,b19,b20		'Secs Convert to ASCII
	bcdtoascii b1,b8,b9		'Mins 
	bcdtoascii b2,b10,b11		'Hours
	bcdtoascii b3,b21,b22         'DayOfWeek;	bcdtoascii b4,b12,b13		'Date
	bcdtoascii b5,b14,b15		'Month
	bcdtoascii b6,b16,b17		'Year
	If b22="1" then serout B.0,N2400,(254,line1,"Sun ") 'convert Ascii 1-7 Day of Week number to Text
	elseif b22="2" then serout B.0,N2400,(254,line1,"Mon ")
	elseif b22="3" then serout B.0,N2400,(254,line1,"Tue ")
	elseif b22="4" then serout B.0,N2400,(254,line1,"Wed ")
	elseif b22="5" then serout B.0,N2400,(254,line1,"Thur")
	elseif b22="6" then serout B.0,N2400,(254,line1,"Fri ")
	elseif b22="7" then serout B.0,N2400,(254,line1,"Sat ")
	endIf
	serout B.0,N2400,(254,133,b10,b11,":",b8,b9,":",b19,b20)
	
     	goto Gettemps
	 
Convert:
     	owin  Ds18b20,%0000,(TempLsb,TempMsb)             ' read in result 
      TempMsb = Temperature >> 4 : let Sign = " "                               ' Display  space for +
      IF TempMsb > 127 THEN      : let Sign = "-" : TempMsb = - TempMsb : ENDIF ' Display -
    	return
it's untidy as it's bits grafted together.

Edit: Doh!!! Major stupidity on my part, I've got the ds18b20 signal pin on the same pin as the i2c scl, must tidy breadboard spagetti into civilised wiring.:eek::eek::eek::eek:
 
Last edited:

Captain Haddock

Senior Member
Many thanks to all those wonderful people that have put up with my daft questions and code 'borrowing', I now have 3 ds18b20's in a 1-wire setup & ds1307 rtc on i2c all displaying on the lcd with temp alarm functions as well as an auto start system for 2 diesel engines with temp dependant pre-heat controllers on the one chip, just need to tidy up the code now and make the display a bit prettier.
Couldn't have done it without you guys!!
Don't think you've got rid of me as I'll soon plague you with the next project:D
 
Top