DS18B20: Inconsistent ID/ROM?

I’m simply trying to read temps from a DS18B20 temp sensor. I’ve worked with them a long time, and it’s generally working okay. But ID and ROM are NOT dependable using the lib I have.
If I’m monitoring via Serial…
I plug it in and something like 15-20% of the time, the chip type returns junk, rather than the proper chip type.
Also, the ROM address itself doesn’t come back right. It’s wrong more times than not!

What am I doing wrong?? HELP!

-Jeff

---- Sample debugging output  ---
Serial monitor opened successfully:
ROM1: [**28 FF 15 99 00 00 00 00**]
1: Chip type [28:DS18B20]
ROM2: [00 00 00 00 00 00 00 00]
2: Chip type [0:Unknown]
ROM3: [00 00 00 00 00 00 00 00]
3: Chip type [0:Unknown]
Serial connection closed.  Attempting to reconnect...
Serial monitor opened successfully:
ROM1: [**28 FF 15 99 00 16 02 00**]
1: Chip type [28:DS18B20]
ROM2: [00 00 00 00 00 00 00 00]
2: Chip type [0:Unknown]
ROM3: [00 00 00 00 00 00 00 00]
3: Chip type [0:Unknown]
#include <DS18B20.h>

const int ONE_WIRE_BUS_1 = D4; 
const int ONE_WIRE_BUS_2 = D5; 
const int ONE_WIRE_BUS_3 = D6; 

DS18B20* tempSensor1Ptr;
DS18B20* tempSensor2Ptr;
DS18B20* tempSensor3Ptr;

//---------------------------------------------------------
void setup() {
  Serial.begin(14400);
 
  digitalWrite(ONE_WIRE_BUS_1, LOW ) ;
  pinMode(ONE_WIRE_BUS_1, INPUT);

  digitalWrite(ONE_WIRE_BUS_2, LOW ) ;
  pinMode(ONE_WIRE_BUS_2, INPUT);

  digitalWrite(ONE_WIRE_BUS_3, LOW ) ;
  pinMode(ONE_WIRE_BUS_3, INPUT);


  char myAddr[64+1];

  tempSensor1Ptr = new DS18B20(ONE_WIRE_BUS_1, true);
  tempSensor1Ptr->getROM( myAddr ) ;
  Serial.printlnf("ROM1: [%s]", myAddr ) ;
  Serial.printlnf("1: Chip type [%x:%s]", tempSensor1Ptr->getChipType(), tempSensor1Ptr->getChipName() );

  tempSensor2Ptr = new DS18B20(ONE_WIRE_BUS_2, true);
  tempSensor2Ptr->getROM( myAddr ) ;
  Serial.printlnf("ROM2: [%s]", myAddr ) ;
  Serial.printlnf("2: Chip type [%x:%s]", tempSensor2Ptr->getChipType(), tempSensor2Ptr->getChipName() );

  tempSensor3Ptr = new DS18B20(ONE_WIRE_BUS_3, true);
  tempSensor3Ptr->getROM( myAddr ) ;
  Serial.printlnf("ROM3: [%s]", myAddr ) ;
  Serial.printlnf("3: Chip type [%x:%s]", tempSensor3Ptr->getChipType(), tempSensor3Ptr->getChipName() );
}

void loop() {
}

I have noticed rather inconsistent results with OneWire and mesh devices too.
That’s also why a multidrop setup isn’t very reliable (as discussed here)

I guess it’s due to different timing on Gen1&2 vs. Gen3.

1 Like

Note I’m actually using just one per pin. Not sure that affects what you are saying though.
Could using the separate system thread help with the timing issue?

Oddly, seems the device ID, whether right or wrong, stays the same past a reset (onboard button). Only power cycling changes the situation.

Not really. The timing issue I'm suspecting happens on a more fundamental level.

No it shouldn't make a difference, multi drop would just suffer harder as it actually relies on the correct ID to address the wanted device on the bus.
For single drop the one and only device will be found for temperature reading no matter what the ID - in fact searching for the device via ID is skipped entirely in single drop mode.

But to get the correct ID you should probably do something like this

  uint8_t addr[8];
  bool foundSensor = false;
  for (uint32_t ms = millis(); millis() - ms < 30000; ) { // scan for ID - max 30sec
    sensor->resetsearch();                                // prepare for sensor search
    if (sensor->search(addr)) {                           // only when a valid ID was found
      foundSensor = true;
      break;
    }
    else 
      delay(100);
  }