0
Offline
Jr. Member
Karma: 0
Posts: 72
Arduino rocks
|
 |
« on: March 25, 2009, 08:51:35 pm » |
I have 5 DS18B20's hooked up to my Arduino. Â I am trying to scan the bus once, store all the addresses, then move on in the code. I cant even seem to get the basic scan to give me the 5 addresses. It works fine with up to 3 devices, any more and it endless loops. Â It never finishes. Â Any ideas? void loop(void) { Â byte i; Â byte present = 0; Â byte done = 0; Â byte data[12]; Â byte addr[8];
 while ( !done )  {   if ( ds.search(addr) != 1)   {    Serial.print("No more addresses.\n");    ds.reset_search();    done = 1;    return;   }   else   {    Serial.print("Unique ID=");    for( i = 1; i < 7; i++)    {     Serial.print(addr[i], HEX);     Serial.print(":");    }    Serial.println();     } delay(100);  } }
From the console out: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0: Unique ID=DE:E3:F6:1:0:0: Unique ID=9E:C1:F6:1:0:0:
|
|
|
|
|
Logged
|
|
|
|
|
Canberra, Australia
Offline
Jr. Member
Karma: 0
Posts: 53
Arduino rocks
|
 |
« Reply #1 on: March 26, 2009, 01:33:07 am » |
There is a bug in the OneWire library that creates the problem you are experiencing. The best way around this is to find the addresses of all the sensors one by one, and directly use these addresses to interface with your sensors.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 72
Arduino rocks
|
 |
« Reply #2 on: March 26, 2009, 09:30:00 am » |
I was afraid fo that.
|
|
|
|
|
Logged
|
|
|
|
|
Canberra, Australia
Offline
Jr. Member
Karma: 0
Posts: 53
Arduino rocks
|
 |
« Reply #3 on: March 31, 2009, 05:13:46 am » |
I played around with the library to see I could find the bug, but I don't have enough 1-Wire devices to actually reproduce this problem. So I'll need your help. Could you see if the following change fixes it? Just open the library's OneWire.cpp file, and comment out line 268.
|
|
|
|
|
Logged
|
|
|
|
|
New England
Offline
Jr. Member
Karma: 0
Posts: 95
Arduino newbie
|
 |
« Reply #4 on: March 31, 2009, 05:39:49 am » |
What's the bug? Where's it detailed? I ran into a problem where I was unable to resolve more than three devices on the bus, but I thought that was due to a poor wiring job on my part (I have DS18B20s running all over my house with some hefty wiring runs). I was getting CRC errors when scanning the bus. Is that what's happening here? I see that the sample code above isn't performing a checksum...
|
|
|
|
|
Logged
|
|
|
|
|
Canberra, Australia
Offline
Jr. Member
Karma: 0
Posts: 53
Arduino rocks
|
 |
« Reply #5 on: March 31, 2009, 05:46:20 am » |
To my knowledge nobody has ever posted what the bug is exactly. I've made a best guess by "simulating" a bunch of 1-Wire devices in C# and ported the OneWire library search code across and debugged it there. In my simulation commenting out that line makes the search algorithm work (otherwise it loops between two devices in the same way shown in the first post of this thread).
I don't believe this bug has anything to do with CRC errors. That must be a different issue. Maybe you need try a different pull-up resistor? Try a 2k or 1.5k resistor (don't go lower than this).
|
|
|
|
|
Logged
|
|
|
|
|
New England
Offline
Jr. Member
Karma: 0
Posts: 95
Arduino newbie
|
 |
« Reply #6 on: March 31, 2009, 06:16:23 am » |
I got around the problem by using two 1-Wire buses. 
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 3
Arduino rocks
|
 |
« Reply #7 on: April 26, 2009, 10:43:47 am » |
I have experienced the same problem with search not terminating when there are more than four devices on the wire. Last night I put together a test system, demonstrated it has the same problem, studied the signaling with a scope, and tracked the problem to what appears to be a misplaced statement, line 268.
The logic is complex enough that I want to go through it again with a clear head. I would like to know more about Waffle's simulation. What search tree configurations did you simulate? I ask because I suspect some missing flag initialization which removing line 268 does not address.
Kudos to Waffle, and to my friend Wayne, for their assistance tracking down this problem.
|
|
|
|
|
Logged
|
|
|
|
|
Van Alstyne, TX
Offline
Full Member
Karma: 1
Posts: 154
Haven't smoked an Arduino... yet.
|
 |
« Reply #8 on: April 26, 2009, 07:10:34 pm » |
FWIW, I currently have 4 1-wire devices hooked up to my Arduino, 2 1820's and 2 18B20's and have not had a single problem although the distance between the Arduino and my sensors is about 6-inches (15-cm). Â
|
|
|
|
« Last Edit: April 26, 2009, 07:11:15 pm by Fe2o3Fish »
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 3
Arduino rocks
|
 |
« Reply #9 on: April 27, 2009, 11:23:42 am » |
Rusty -- Can you hook up a couple more devices and see if search still works? I found that the OneWire search code would fail when adding the 5th or 4th device, depending on which devices were already on the bus. I assume this is because the particular id bit patterns lead the search algorithm toward or away from the faulty logic. Perhaps having two different device codes is protecting you from the faulty logic too. -- Ward
|
|
|
|
|
Logged
|
|
|
|
|
Van Alstyne, TX
Offline
Full Member
Karma: 1
Posts: 154
Haven't smoked an Arduino... yet.
|
 |
« Reply #10 on: April 27, 2009, 08:11:50 pm » |
Ward, Â Â I've dumped 4 1820's and 2 18B20's onto my Arduino. Â I'm having no problems with the search algorithm although search() is only called after a system reset/powerup. Parasitic power is NOT used and the data line has a 4k7 ohm resistor pulling it up to +5v.
|
|
|
|
« Last Edit: April 27, 2009, 08:15:31 pm by Fe2o3Fish »
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 3
Arduino rocks
|
 |
« Reply #11 on: April 28, 2009, 01:10:24 am » |
I have now commented out line 268 as suggested by Waffle, deleted the OneWire.o file to cause a recompile, and tested the revised code with seven devices. It works.
For those who might want to duplicate this fix, here is a print out of the area in question with the commented line in place.
 263   } else {               // we are blazing new tree, take the 0  264 a = 0;  265 searchJunction = i;  266 done = 0;  267   }  268   // lastJunction = i;  269 }  270 if ( a) address[ ibyte] |= ibit;  271 else address[ ibyte] &= ~ibit;
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 1
Posts: 20
Arduino rocks
|
 |
« Reply #12 on: May 14, 2009, 08:13:41 pm » |
I had the same problem as soon as I added a 6th device to my prototype DS18B20 network (parasite powered). Only 2 devices were affected; as soon as I removed either of them, the search function worked properly. The symptom of the problem was a search that endlessly cycled between device 28 C6 and 28 5E
My devices (all values in hex):
28 78 09 06 02 00 00 92 28 1C 23 02 02 00 00 C6 28 C6 0D 06 02 00 00 99 <-- remove either device 28 C6 28 5E FB 05 02 00 00 3B <-- or device 28 5E for search to work 28 01 47 02 02 00 00 D9 28 D9 FF 05 02 00 00 4B
Once I commented out line 268 and recompiled the OneWire library, all devices work fine.
Rx
|
|
|
|
|
Logged
|
|
|
|
|
Port Angeles, Wa
Offline
Edison Member
Karma: 13
Posts: 1411
Ultimate DIY: Arduino
|
 |
« Reply #13 on: May 14, 2009, 08:57:25 pm » |
YAY! Thank you.
|
|
|
|
|
Logged
|
|
|
|
|
Spain
Offline
Newbie
Karma: 0
Posts: 2
Arduino rocks
|
 |
« Reply #14 on: May 31, 2009, 01:07:01 pm » |
This is great, I was stuck with the same problem: I could connect the AAG weather station (3 sensors) but when i tried to add one more ds18s20 the search program got in a loop. Thank you for the detailed solution.
|
|
|
|
|
Logged
|
|
|
|
|
|