Pages: [1]   Go Down
Author Topic: One wire bus problum  (Read 586 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In my Pool Heater Project  I have a strange bug that requires me to read the one wire buss three times  to measure my two temperature sensors.  The code operates fine as written  but  I end up reading the second sensor twice to keep everything in sync.  I can't figure out why this is.

The pool heater project is posted under my name.  
http://arduino.cc/forum/index.php/topic,122878.0.html
« Last Edit: September 15, 2012, 07:20:25 pm by RonSpooner » Logged

South Louisiana
Offline Offline
Full Member
***
Karma: 0
Posts: 178
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

or you could post a link and save someone who is potentially going to attempt to give you assistance from searching for the proper thread.
Logged

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 44
Posts: 2805
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you found the auto-format button in the IDE yet? (ctrl T) your code because if the indentation makes it hard for this noob to C+ very hard to read...
That having been said. Do you have a pull-up on the one wire bus line, recommended is 4K7 or lower depending on conditions and wire length?

Doc
Logged

--> WA7EMS <--
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes   the porject works  just fime  -  I have the right pull up reisitor.  It is the loop counter that does not seem to b e  quite right.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your code looks fine to me, except for one thing.
Short answer: add "break;" after "Temp18B20.reset_search();"

Long answer:
There is a problem with the OneWire library. But that's for an infinite loop, which you aren't running into.
Here's the fix for it anyway:
http://arduino.cc/forum/index.php/topic,18231.msg132780.html#msg132780

Could you post a running output? Something like:
Code:
while(j < 6){
Serial.print(j);
Serial.print(", ");
if ( !Temp18B20.search(addr)) {
    Temp18B20.reset_search();
    Serial.print("reset ");
    }

Serial.print(addr[1], HEX);
}
This will help us get an idea of the pattern that the search function returns.
I think you'll find you get something like:
Code:
0, 0x7C
1, 0x21
2, reset 0x21
3, 0x7C
4, 0x21
5, reset 0x21
This is because the third "unneccesary" loop is necessary in order to hit the "Temp18B20.reset_search();" line.
In the example code, there is a "return;" after this line, but in your case you don't want to break out of the function, just the loop. Thus, replace "return;" with "break;"

A better way would be to loop twice (like you expected) and then add a "Temp18B20.reset_search();" at the end of your function (after all the calculations are done). This should also work, as long as your sensors are all functioning properly and you don't add any more sensors. Then you could have the fail safe conditional "if ( !Temp18B20.search(addr)) {" end with "return false;" so that if you get there (which you shouldn't if you're reading twice, and have two good sensors) you know something is wrong, and the function shuts down the pump.

Glad the project is working! Keep it up!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow,  That fixed it.   I was looking for a good tutorial on the one wire .h  code I used  but  did not find it.  So I was flying blind.  Thank you again for your help. Ron
Logged

Pages: [1]   Go Up
Jump to: