Go Down

Topic: One wire bus problum (Read 970 times) previous topic - next topic


Sep 16, 2012, 02:08 am Last Edit: Sep 16, 2012, 02:20 am by RonSpooner Reason: 1
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.  


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.


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?

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


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.


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:

Could you post a running output? Something like:
Code: [Select]
while(j < 6){
Serial.print(", ");
if ( !Temp18B20.search(addr)) {
    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: [Select]
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!


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

Go Up