DS18b20 and an endless loop
Moderator: Benj
-
- Posts: 71
- Joined: Fri Jul 31, 2015 9:21 pm
- Has thanked: 2 times
- Been thanked: 12 times
- Contact:
DS18b20 and an endless loop
Well I see a few posts here and there about the 18b20 one wire device but I am totally confused now. I looked at the example and can see a decision with
if Retval ?
and in the YES part of that a while 1 loop?
My question is what is retval being compared to?
How does the loop end?
All I need to do is read a DS18b20 once a minute using arduino but the above has confused me..
What am I missing?
if Retval ?
and in the YES part of that a while 1 loop?
My question is what is retval being compared to?
How does the loop end?
All I need to do is read a DS18b20 once a minute using arduino but the above has confused me..
What am I missing?
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: DS18b20 and an endless loop
Hi
An "if retval" will take the "yes" path if retval is non-zero, hence the "no" path if it equates to zero.
Hope that helps,
Leigh
An "if retval" will take the "yes" path if retval is non-zero, hence the "no" path if it equates to zero.
Hope that helps,
Leigh
-
- Posts: 71
- Joined: Fri Jul 31, 2015 9:21 pm
- Has thanked: 2 times
- Been thanked: 12 times
- Contact:
Re: DS18b20 and an endless loop
Thanks Leigh. Yes that makes sense and thats what I thought. However in the YES path there is a loop while 1. How does it exit that loop?
Peter
Peter
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: DS18b20 and an endless loop
I don't know .. can you attach the program, a link to it, or an image snippet?
edit: Think I've found it, are you referring to API_Send_Stu_2.fcfx?
If so, looks like it stays in a continuous loop, reading and displaying temperature.
edit: Think I've found it, are you referring to API_Send_Stu_2.fcfx?
If so, looks like it stays in a continuous loop, reading and displaying temperature.
-
- Posts: 71
- Joined: Fri Jul 31, 2015 9:21 pm
- Has thanked: 2 times
- Been thanked: 12 times
- Contact:
Re: DS18b20 and an endless loop
Well I found it in the examples as well as a link on here but I will upload as well
- Attachments
-
- 1. Single OneWire device_v6.fcfx
- (9.15 KiB) Downloaded 250 times
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: DS18b20 and an endless loop
OK, in that flowchart the "While 1" loops do indeed have no exit point,
they follow messages "No Device Found" and "CRC Error"
so it looks like the authors' intention is for the program to effectively stop if an error is encountered
they follow messages "No Device Found" and "CRC Error"
so it looks like the authors' intention is for the program to effectively stop if an error is encountered
-
- Posts: 71
- Joined: Fri Jul 31, 2015 9:21 pm
- Has thanked: 2 times
- Been thanked: 12 times
- Contact:
Re: DS18b20 and an endless loop
Sometimes I think I should stop doubting myself. I couldnt see how it worked and yet I thought I must be missing something.
Ok I will use the rest and see how we go.
Thanks heaps
Ok I will use the rest and see how we go.
Thanks heaps
-
- Posts: 71
- Joined: Fri Jul 31, 2015 9:21 pm
- Has thanked: 2 times
- Been thanked: 12 times
- Contact:
Re: DS18b20 and an endless loop
I am tinkering with this at work and without much in the way of extra tools etc (and my usual LCD screen I use to see whats happening) so excuse my ignorance but what does the function Gettemp return? I see its a 2 byte value so I am assuming its a HEX value so how do I convert that to celcius?
Is the temp returned via HEX or is it something else
Is the temp returned via HEX or is it something else
-
- Posts: 71
- Joined: Fri Jul 31, 2015 9:21 pm
- Has thanked: 2 times
- Been thanked: 12 times
- Contact:
Re: DS18b20 and an endless loop
Ok home on my days off.
I created a loop that fires each couple of seconds. it calls a component macro doing
one wire start- conversion
then
one-wire read scratchpad
then
onewire-gettemp and shoves that value returned by get temp in a float variable called temp
I then send that value using tostring$(temp)
to an lcd screen so for now I can see whats happening.
it shows at around 26 degrees celcius 445
Hold onto that probe it goes up and let it go it comes down.
So is that value a HEX value or is it a number of counts in a 12 bit resolution or what?
Many thanks guys
I created a loop that fires each couple of seconds. it calls a component macro doing
one wire start- conversion
then
one-wire read scratchpad
then
onewire-gettemp and shoves that value returned by get temp in a float variable called temp
I then send that value using tostring$(temp)
to an lcd screen so for now I can see whats happening.
it shows at around 26 degrees celcius 445
Hold onto that probe it goes up and let it go it comes down.
So is that value a HEX value or is it a number of counts in a 12 bit resolution or what?
Many thanks guys
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: DS18b20 and an endless loop
Hi
I'm not familiar with this device, so I suggest that you source a copy of the datasheet for it (a quick glance implies a 9 bit resolution)
Looking at the original SingleOneWire device sample flowchart (mentioned earlier) I see there is a divide by 16.
If you divide 445 by 16 the result is ~28, so I guess that's what you need to do
Leigh
I'm not familiar with this device, so I suggest that you source a copy of the datasheet for it (a quick glance implies a 9 bit resolution)
Looking at the original SingleOneWire device sample flowchart (mentioned earlier) I see there is a divide by 16.
If you divide 445 by 16 the result is ~28, so I guess that's what you need to do
Leigh
-
- Posts: 71
- Joined: Fri Jul 31, 2015 9:21 pm
- Has thanked: 2 times
- Been thanked: 12 times
- Contact:
Re: DS18b20 and an endless loop
Yes I think its sort of like that. It seems it also shows wether its a negative temp by the most sig bit. I will play and report back
Thanks Leigh
Thanks Leigh
-
- Posts: 71
- Joined: Fri Jul 31, 2015 9:21 pm
- Has thanked: 2 times
- Been thanked: 12 times
- Contact:
Re: DS18b20 and an endless loop
Ok all. I have a DS18B20 in and operating. I use the one wire component and simply use the value returned by the gettemp and multiply it by .0625
It seems to be running ok. I have it in an outdoor system I am using to control my Aquaponics setup. I expect to see a - value sometime in winter
I will need to add another one later on to read water temp so will play a bit more but for now its all good.
Many thanks to all those who helped.
Peter
It seems to be running ok. I have it in an outdoor system I am using to control my Aquaponics setup. I expect to see a - value sometime in winter
I will need to add another one later on to read water temp so will play a bit more but for now its all good.
Many thanks to all those who helped.
Peter
-
- Posts: 1333
- Joined: Tue Oct 06, 2009 9:39 am
- Has thanked: 1135 times
- Been thanked: 299 times
- Contact:
Re: DS18b20 and an endless loop
Hi secs!
Would you share your examble, so we can learn...
Thank' in advance
Jorgen
Would you share your examble, so we can learn...
Thank' in advance
Jorgen
-
- Posts: 71
- Joined: Fri Jul 31, 2015 9:21 pm
- Has thanked: 2 times
- Been thanked: 12 times
- Contact:
Re: DS18b20 and an endless loop
I use this in a macro but it seems to work. I only need whole numbers to compare so I convert the float to int. The DS18b20 defaults to 12 bit and I dont change that so as an example the value of 456 is a temp of 28.5 degrees celcius
And for those that are interested. I use the temp to speed up the cycles of my aquaponics system if its hot. At 20 degrees its turn around is 3600 seconds and at 40 its 2700 seconds
Peter
-
- Posts: 1333
- Joined: Tue Oct 06, 2009 9:39 am
- Has thanked: 1135 times
- Been thanked: 299 times
- Contact: