Pages: [1] 2 3 4   Go Down
Author Topic: 1-Wire, DS18B20... How do I search the bus?  (Read 14549 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 75
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Code:

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:
Code:
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 Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Jr. Member
**
Karma: 0
Posts: 75
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was afraid fo that.
Logged

Canberra, Australia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Jr. Member
**
Karma: 0
Posts: 95
Arduino newbie
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Jr. Member
**
Karma: 0
Posts: 95
Arduino newbie
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I got around the problem by using two 1-Wire buses. smiley
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Full Member
***
Karma: 1
Posts: 154
Haven't smoked an Arduino... yet.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Full Member
***
Karma: 1
Posts: 154
Haven't smoked an Arduino... yet.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Newbie
*
Karma: 2
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Cumming, GA
Offline Offline
Edison Member
*
Karma: 18
Posts: 1627
Ultimate DIY: Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

YAY!  Thank you.
Logged

Spain
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1] 2 3 4   Go Up
Jump to: