DS18b20 and an endless loop

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
secs
Posts: 71
Joined: Fri Jul 31, 2015 9:21 pm
Has thanked: 2 times
Been thanked: 12 times
Contact:

DS18b20 and an endless loop

Post by secs »

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?

User avatar
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

Post by LeighM »

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

secs
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

Post by secs »

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

User avatar
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

Post by LeighM »

I don't know :D .. 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.

secs
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

Post by secs »

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

User avatar
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

Post by LeighM »

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

secs
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

Post by secs »

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

secs
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

Post by secs »

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

secs
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

Post by secs »

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

User avatar
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

Post by LeighM »

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

secs
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

Post by secs »

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

secs
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

Post by secs »

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

jgu1
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

Post by jgu1 »

Hi secs!

Would you share your examble, so we can learn... :lol:

Thank' in advance

Jorgen

secs
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

Post by secs »

onewiretest.fcfx
(5.8 KiB) Downloaded 226 times
No problems.

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

jgu1
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

Post by jgu1 »

Thank's Peter.

Br

Jorgen

Post Reply