DS18B20 problem

Smitten123

New Member
Hello all, I have written and constructed a circuit using the DS18B20 temperature sensor and connected the sensor to the negative port of C.7. this is the code i have used.
Code:
init: pause 500
	serout B.6,N2400,(254,1)
	pause 100

main: readtemp C.7,b1						;read temperature into b1
  if b1 <=10 then						;if the temperature is less than 10 degrees then
	serout b.6,N2400,(254,128,"Low Temperature")		;Display Low Temperature on the first line
	serout b.6,N2400,(254,192,#b1,"C")			;Display the temperature on the second line
  endif
  if b1<=10 then 						;if the temperature is less than 10 degrees then
	high B.3						;light green LED
  else
	low B.3							;turn off green LED
  endif
  goto main

  if b1 >=30 then							;if the temperature is more than 30 degrees then
	serout B.6,N2400,(254,128,"High Temperature")	;Display High Temperature on the first line
	serout B.6,N2400,(254,192,#b1,"C")			;Display the temperature
  endif
  if b1 >=30 then							;if the temperature is more than 30 degrees
	high B.7							;turn on the red LED
  else
	low B.7 							;turn off the red LED
  endif
  goto main

  if b1 >10 and b1 <30 then					;if the temperature is between 11 and 29 degrees then
	serout B.6,N2400,(254,128,"Temperature") 		;Display the word Temperature on the first line
	serout B.6,N2400,(254,192,#b1,"C")			;Display the Temperature on the second line
  endif
  goto main
the screen was at first showing "Low temperature 0C", now it wont show anything at all, I am using a plug in power source so its not the batteries that have caused this, any help would be massively appreciated.

Thank you
 
Last edited by a moderator:

premelec

Senior Member
I suggest you simplify to JUST read the 18B20 and report and make sure that's working... THEN add conditional statements and actions one at a time... Do you have a resistor to V+ connected to the 18B20 or are you trying to use parasitic read?
 

inglewoodpete

Senior Member
....and connected the sensor to the negative port of C.7
Can you clarify what you mean by "negative port"?

.... I am using a plug in power source so its not the batteries that have caused this, any help would be massively appreciated.
Please tell us more about the "plug in power source"? Is it a regulated supply? What voltage do you measure on the output?

Also, which model of PICAXE are you using?

Finally, It might be working as you have coded it. There is a "Goto Main" in the middle of your code that prevents most of the LCD and LED display working. As I read it, the display will only show something is the temperature is below 10C. Try putting an ice cube in a small plastic bag and holding it against the DS18B20 to test this.

Edit: Being forum member is good for my geography knowledge :) I see it's 4C at the moment in Saltcoats. Perhaps you won't need much ice! It was 40C in my part of the world yesterday and it only got down to 23C overnight. Don't they know it's the middle of March??
 
Last edited:

westaust55

Moderator
Do you have the DS18B20 connected as per the diagram on page 93 in PICAXE manual 2
http://www.picaxe.com/docs/picaxe_manual2.pdf ?

now it wont show anything at all
The question becomes: is it the temp sensor or the display.

What happens on the display if you add in the initialisation part after the line:
serout B.6,N2400,(254,1)
and extra line:
serout b.6,N2400,(254,128,"My Temp. Sensor.")

Is that showing on the display ?
 
Last edited:

Smitten123

New Member
Please tell us more about the "plug in power source"? Is it a regulated supply? What voltage do you measure on the output?

Also, which model of PICAXE are you using?

Finally, It might be working as you have coded it. There is a "Goto Main" in the middle of your code that prevents most of the LCD and LED display working. As I read it, the display will only show something is the temperature is below 10C. Try putting an ice cube in a small plastic bag and holding it against the DS18B20 to test this.

Edit: Being forum member is good for my geography knowledge :) I see it's 4C at the moment in Saltcoats. Perhaps you won't need much ice! It was 40C in my part of the world yesterday and it only got down to 23C overnight. Don't they know it's the middle of March??
The plug in source is of just over 5V, I have taken the goto main commands out of the middle of the code and just left the if loops and put a goto main at the end, it is now still reading "Low Temperature 0C" and lighting the green LED as per the commands, I checked the voltage output from the DS18B20 and it is receiving enough voltage.

I am using the 18-M2 chip on the CHI030B board.
 

westaust55

Moderator
I am using the 18-M2 chip on the CHI030B board.
It helps folks here to help you if you respond to the questions put to you.

Please confirm that you are connecting the DS18B20 to the B.6 point between the PICAXE chip and the ULN2803 Darlington driver chip and NOT the B.6 output terminal at the edge of the CHI030B board.
http://www.picaxe.com/docs/chi030b.pdf

As per the original enquiry by premelec at post 2:
Do you have a resistor to V+ connected to the 18B20 or are you trying to use parasitic read?
finally my question from post 4:
Do you have the DS18B20 connected as per the diagram on page 93 in PICAXE manual 2 ?
 

Smitten123

New Member
Sorry, I missed that question, I have moved the sensor to the B.0 pin between the Darlington and the PICAXE chip. I also have the resistor connected between V+ and the signal. Page 93 in PICAXE manual 2 does not have anything about the DS18B20 on it.
 

westaust55

Moderator
Looking at the ULN2803 datasheet, the inputs have in effect a 13 kOhm resistor (made up of 3 parts) to ground / 0 volts.
In conjunction with the 4.7 kOhm pull-up resistor that may hold the DS18B20 dataline steady (or at least prevent full voltage swing).

I believe the ULN2803 Darlington chip is in a socket. Can you remove that chip and try your program again.
 

Smitten123

New Member
That should have been page 193
yeah, that's how it's set up. I have ran a debug as well and there is no variation on the temperature.
The LCD is showing 85C high temperature now, it has just went from one extreme to the other when changing the pin from the positive rail to the negative.
 

westaust55

Moderator
yeah, that's how it's set up. I have ran a debug as well and there is no variation on the temperature.
The LCD is showing 85C high temperature now, it has just went from one extreme to the other when changing the pin from the positive rail to the negative.
The 85C temperature reading is a default output if the DS18B20 has not in effect received a command.
That is (from the datasheet): The power-on reset value of the temperature register is +85°C.

Which indicates that the command to perform a temperature conversion ( as sent by the PICAXE READTEMP command) has not been received
 

johnlong

Senior Member
As I've said previously, it's probably the code (and the temperature).
Hi
If you have discounted your wiring problems
Try giving the chip time to digest the inputted data you could add a small loop like
[] for b0 = 0 to 9 'b0 used as a counter
readtemp C.7,b1
pause 20 'gives the picaxe time to process the command
w4=w4+b1 'w4 word variable used as 10 readings over 30 will go beyound the 255
next b0

b1=w4/10[\]
Then look at using gosubs for your 3 choices
your LCD display will be all the more stable for it
regards
john
 

srnet

Senior Member
Hi
If you have discounted your wiring problems
Try giving the chip time to digest the inputted data you could add a small loop like
[] for b0 = 0 to 9 'b0 used as a counter
readtemp C.7,b1
pause 20 'gives the picaxe time to process the command
w4=w4+b1 'w4 word variable used as 10 readings over 30 will go beyound the 255
next b0

b1=w4/10[\]
Then look at using gosubs for your 3 choices
your LCD display will be all the more stable for it
regards
john
My understanding would be that the execution of the readtemp finishes, the result is put in the variable, then it moves onto the next command, no delay required.
 

inglewoodpete

Senior Member
Correct. No need to wait any longer. The PICAXE does all the waiting for you :).

In the command description for ReadTemp:

Function:
Read temperature from a DS18B20 digital temperature sensor and store in
variable. The conversion takes up to 750ms.

There was a problem with the code that has been addressed. Getting a "response" of 85 now focusses the issue to communication with the DS18B20.
 
Top