Problem using DS18B20 temp. sensor.

The bear

Senior Member
#1
Temp DS18B20 Exp-1 jpeg.JPG

Hello,
My first post, please be gentle with me.
Using 08M2 & DS18B20 with 4k7 pull-up resistor, my circuit will not switch ON (Using a LED as an indicator/load).
The DS18B20 is chilled to approx. 5°C . Circuit working on 5 volts
Debug is disabled.
Advice please.
Regards, Bear..
 

Paix

Senior Member
#2
Welcome to the Forum The Bear.

A quick question, if you don't need to use Logicator, then I would strongly advise you to use Picaxe Basic as it will give you more flexibility in the long run and also ensure a greater assistance base. Most people tend to use Basic scripting. However, to answer your question directly.

If I understand Logicator correctly (never looked!) then variables are specified as A, B, C . . . etc?
Code:
readtemp 4, A ' reading is put into variable A
if A4 < 18       ' A4? I think that you really mean
if A < 18         ' not A4. Similarly when you test again later you are
                     ' testing A4 instead of A
Someone else will come along and help you further, but I think you should get some mileage from my comment and your code working.

I like to use SERTXD ("This is a test", cr,lf) for debug messages. I am usually only interested in one or two and it's often neater than debug.
 

hippy

Technical Support
Staff member
#3
I would agree with Paix's analysis - it's the "A4" in the comparison cells.

"A4" is analogue input 4, not the variable "A" you have read the temperature into.
 

The bear

Senior Member
#4
I would agree with Paix's analysis - it's the "A4" in the comparison cells.

"A4" is analogue input 4, not the variable "A" you have read the temperature into.
Hello,
Thanks to you both, for your quick response and help.
When I changed A4 to A, it switched ON at low temp.(Below 18) as it should, but stayed ON regardless of raised temp.
(24°).
I inserted a second ReadTemp & Debug. Now the set-up appears to be working.

Any further help and/or comments would be very much appreciated.
Regards, Bear..


See attachment: Temp DS18B20 Exp-2 .JPG
 
#5
Going back to post #2,

can you convert,
then re - post your code as BASIC.

Then, you may get more replies.

Sorry I can't help further on the Logicator.

e
 

hippy

Technical Support
Staff member
#7
There's no reason I can see that the program should not be working. Perhaps re-enable debug and see what results you are getting in varA. You may think it's 24C but it could be the temperature as read by the DS18B20 is lower than that.
 

nick12ab

Senior Member
#8
There's no reason I can see that the program should not be working. Perhaps re-enable debug and see what results you are getting in varA. You may think it's 24C but it could be the temperature as read by the DS18B20 is lower than that.
I inserted a second ReadTemp & Debug. Now the set-up appears to be working.
Has eclectic just caused confusion by posting one of his usual rather generic replies? It certainly sounds like it is now working. The problem that has been fixed was that the readtemp command wasn't executed again in the loop formed by the second decision cell so the old value would always be in that variable regardless of the actual temperature.

How is coming into the Logicator forum and basically stating that you don't know and that you should convert it into BASIC supposed to be helpful?

As expected, Logicator produced spaghetti code which is much harder to read than even unindented uncommented code posted by a newbie.

Going back to post #2,

can you convert,
then re - post your code as BASIC.

Then, you may get more replies.

Sorry I can't help further on the Logicator.
 

Paix

Senior Member
#9
It did produce code that was understandable and clarified a few things. Automatic code generation is understandably going to be less than optimal, but that is a secondary thing.

I understand a flowchart, but not the details of Logicator that might render my assistance mute. I picked up on the variable "A" from a previous thread some time ago, but have only just twigged that A4 is an analogue port. I spent a few minutes this afternoon trying to find that information, but it escaped my cursory search. Is there a nutshell guide to non Logicator users to help us help them in this regard?

Glad that everything is now working TheBear,
 

hippy

Technical Support
Staff member
#10
The problem that has been fixed was that the readtemp command wasn't executed again in the loop formed by the second decision cell so the old value would always be in that variable regardless of the actual temperature.
Looking at the converted basic code that does not appear to be the problem. If it gets to Label_18 it then gets to Label_30 where the second READTEMP is, and after that either branches to Label_20, or back to Label_30 for another READTEMP.

If the problem has been fixed I am intrigued what the problem actually was.


I have now realised the code listing was for the altered and working code, not the original non-working code.

How is coming into the Logicator forum and basically stating that you don't know and that you should convert it into BASIC supposed to be helpful?
The problem with flowcharting is that what's visible does not necessarily reflect what has actually been programmed into the flowchart cells. For example it's entirely possible for a comparison to show "A > B" when the code actually checks "C < D".

Converting to Basic is a quick and easy way to get to what the code is actually doing. If eclectic had not asked for a Basic conversion then I would have or asked for the .plf file to check the conversion myself.
 

The bear

Senior Member
#11
Looking at the converted basic code that does not appear to be the problem. If it gets to Label_18 it then gets to Label_30 where the second READTEMP is, and after that either branches to Label_20, or back to Label_30 for another READTEMP.

If the problem has been fixed I am intrigued what the problem actually was.


I have now realised the code listing was for the altered and working code, not the original non-working code.



The problem with flowcharting is that what's visible does not necessarily reflect what has actually been programmed into the flowchart cells. For example it's entirely possible for a comparison to show "A > B" when the code actually checks "C < D".

Converting to Basic is a quick and easy way to get to what the code is actually doing. If eclectic had not asked for a Basic conversion then I would have or asked for the .plf file to check the conversion myself.
Hello Everyone,
Thank you for all your help and comments.

Now that the circuit is working, may I ask if any one can suggest, is it possible to manually adjust the temperature by a degree or two. Its set to come on at 18° & go off at 20°. I know that I can change these settings in the program mode.
Regards, Bear..

Circuit attached 08M2 & DS18B20.jpg
 

nick12ab

Senior Member
#12
Now that the circuit is working, may I ask if any one can suggest, is it possible to manually adjust the temperature by a degree or two. Its set to come on at 18° & go off at 20°. I know that I can change these settings in the program mode.
Yes - instead of comparing the ADC reading with the fixed values, you can compare it with other variables. Use two different variables for the comparisons and set the value of the variables to the temperatures you want.
 

hippy

Technical Support
Staff member
#13
Now that the circuit is working, may I ask if any one can suggest, is it possible to manually adjust the temperature by a degree or two.
Instead of comparing to 18 and 20 you could compare to varB and VarC. Then you need to put the values into varB and varC.

You could do that from two pots ( using two READADC ), or use one pot and create both varB and varC from its value. It's probably easiest to do the later, so something like ...

READADC into varB ( which will read a value 0 to 255 into varB )

Convert varB to a value more sensible for use, such as 15 to 25 ( varB = varB / 25, varB = varB + 15 )

Set varC to varB + 2

You can put that in a subroutine which you can call after each READTEMP.
 

Paix

Senior Member
#14
@TheBear, In your circuit at post #11, I am assuming that it is a short form and that you do actually have a 4k7 resistor from C.4 (the DS18B20 data pin) to +5V (Vcc)?

The purpose of the two potential dividers is merely to generate a positive number, suitably scaled, to product a number to add to an artificially low fixed temperature value against which to compare the sensor reading?

In honesty, I thought at first that Nick had missed the fact that a DS18B20 was being used and didn't follow the plot at all.

Your example Hippy was a lot more lucid, but I suspect that some might have a little more difficulty grasping it than I did - it took a moment or two for my penny to drop!

It's one of those things that needs worked through on paper to become obvious that it's just one or more offsets to add or subtract from a nominal fixed reference temperature. Or I may have it quite wrong . . .
 

The bear

Senior Member
#15
Thanks hippy for your suggestion, I'm working on it mentally. I struggle with Logicator, never mind Basic, but I can see it's the way to go.

Paix, Well spotted, I did omit the 4k7 pull-up resistor in the circuit diagram, but it was in the actual circuit.

Nice forum.

Regards, Bear..
 

JPB33

Senior Member
#17
Following on for the post of my good friend the bear I also want to use the same approach for temperature control and I have altered as suggested. The circuit runs in logicator simulation but not when I wire up inputs 2 &3 to the sliders on my breadboard which give a varying voltage. The o/p 1 stays high all the time.

Not sure if my attachemnt has worked as the boxes are greyed out?

View attachment Temp hi & low set 27-11-13 .plf
 

JPB33

Senior Member
#18
Tried running the plf file in the excellent V6 editor and it comes out with a problem on line 56 if varC > varA4 then but converted it to basic in logicator and that then runs fine in V6. Only problem is I have not found the analogue inputs to simulate properly yet?

Ideally I would also like to read the tem and settings temp on a LCD display but dont think the 8m2 as enough in/outs for that? And not sure how to do that as well!

Attached is the file in basic in case it helps


Many Thanks
 

Attachments

Top