Ds18b20 1 wire help !!

optic

New Member
Hi all this is doing my head in, read many threads and tried many programs but find half the programs don't work with syntax error, or they seem totally over complicated for me to be able to robs parts of it,

i've got a 28x2 and i've had readtemp12 working with 1 sensor all fine and fine reading the 1 wire bus with 1 sensor,

i've used Hippy's program and have the serial numbers for the sensors on the bus

Searching for one-wire devices ...

Found : 40 112 14 2 4 0 0 189 Checksum Okay
Found : 40 8 34 13 4 0 0 199 Checksum Okay
Found : 40 148 66 2 4 0 0 128 Checksum Okay
Found : 40 54 11 2 4 0 0 168 Checksum Okay
Found : 40 157 26 2 4 0 0 189 Checksum Okay
Found : 40 189 42 2 4 0 0 143 Checksum Okay
Found : 40 189 62 13 4 0 0 118 Checksum Okay
Found : 40 59 61 2 4 0 0 250 Checksum Okay
Found : 40 183 47 2 4 0 0 146 Checksum Okay
Found : 40 119 21 13 4 0 0 174 Checksum Okay

Finished


Is there not a simple match rom read script that will read the temps on the each sensor on the bus and put each value into c1 c2 c3 etc,

Time is not an issue here for the program so long as the convert t is done on all sensors at the same time the the recovery time of the values is not an issue,

my goal it to match the sensors in pairs and then use a flow meter to have an acurate khw meter or energy produced to water.

Just about to give up on using more than one sensor on each input of a 28x2 but it should work and would mean that i could have this one chip do alot more things than read some temps,.

I think i'm trying to run before i can walk putting together and setting up the picaxe to say hello world was very easy never played with ic before,.

thanks inadvance.
 

Captain Haddock

Senior Member
Heres a code I was using on a 20x2 to read 3 ds18b20's on one wire and time from a ds1307 a while back.
They don't read simultaneous but it may be of help to you.
Code:
init:	pause 500
	
	serout B.0,N2400,(254,1)
	SYMBOL line1 = 128
	SYMBOL line2 = 192
	SYMBOL Ds18b20       = C.0
      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:

	owout Ds18b20,%1001,($55,40,65,188,51,3,0,0,22,$44)    
  	owout Ds18b20,%0001,($55,40,65,188,51,3,0,0,22,$BE) 
  	gosub Convert
  	let b27 = TempMsb
	serout B.0,N2400,(254,192)
	serout B.0,N2400,("1:",#TempMsb)
	
	owout Ds18b20,%1001,($55,40,51,163,51,3,0,0,243,$44) 
  	owout Ds18b20,%0001,($55,40,51,163,51,3,0,0,243,$BE) 
     	gosub Convert
     	let b28 = TempMsb
     	serout B.0,N2400,(254,198)
	serout B.0,N2400,("2:",#TempMsb)

	owout Ds18b20,%1001,($55,40,79,232,51,3,0,0,143,$44)    
  	owout Ds18b20,%0001,($55,40,79,232,51,3,0,0,143,$BE) 
  	gosub Convert
  	let b29 = TempMsb
	serout B.0,N2400,(254,204)
	serout B.0,N2400,("3:",#TempMsb)
	

gettime:	
	hi2cin 0,(b0,b1,b2,b3,b4,b5,b6)	'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
 

westaust55

Moderator
with the 1-Wire commands (OWIN and OWOUT), it is possible to simultaneously initiate the temp conversion in multiple DS18B20 chips.

However, the temp must be read back individually from each DS18B20 which requires one to know the 8-byte Serial No of each DS18B20.

From recollection, the code example in my "tutorial" was reading 5 x DS18B20 connected on 1 pin (plus 1 on a second pin)
 

optic

New Member
Hi thanks guys,

it was this bit of code that i needed owout Ds18b20,%1001,($55,40,51,163,51,3,0,0,243,$44) as i had the serial numbers, i've done the temp convert on all sensors on the bus and going to read them back, once read back i've checked for negative numbers and put them in b11 to b20 for each sensor reading. i need to do the *10/16 to have degrees to two decimal places,
I then need to calculate the difference in temp between two sensors which are to be places on the input and output of a water heater, i know the flow value 0.33 l/s ( but could measure it one day)so then i can caculate the kw added to the water. I then need to measure the voltage 230v supplied http://openenergymonitor.org/emon/buildingblocks/measuring-voltage-with-an-acac-power-adapterand the current with one of these http://www.ebay.co.uk/itm/110894073072?var=410115820127&ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649

to find out the kw supplied and to a simple output kw / supplied kw to work out the Cofficent Of Performance in real time put this up on the LCD and send all data to openlog usd card with time stamp.

Simples, now where is that picaxe manual for programming !!
 

optic

New Member
*10 is for 1 decimal place.
*100 is needed for 2 decimal places
ok so i'll have to stick to 1 decimal place to read temps over 45 degrees as i will run out of word variables ??

which is fine, the ground water has a much higher flow rate and a delta of only three degrees temp range is -5 to 15 degrees so one day will measure that to 2 decimal places,
 

westaust55

Moderator
ok so i'll have to stick to 1 decimal place to read temps over 45 degrees as i will run out of word variables ??
A byte variable can hold a value from 0 to 255. So allowing for 1 decimal place, the highest value you can store/hold in a byte variable is 25.5.

Tentatively you should be able to reuse variables or store them in RAM with PEEK and POKE commands.
I have done such variable re-use and allocated 3 or 4 purposes for each variable on earlier PICAXE chips with only 14 byte variables.
 
Top