DS18B20 library on Boron has trouble with multidrop to get sensor addresses

Setup:

  • Boron 2G/3G (0.8.0-rc.27)
  • DS18B20 (0.1.9) library
  • Using ds18b20_MultiDrop example
  • 2x DS18B20 sensor (attached parallel to one port), each with a cable length of 25 cm
    • red wires -> 3v3
    • black wires -> GND
    • yellow wires -> D2
    • 4.86K pull-up resistor

The temp readings are either both NAN, or one succussful reading and one NAN (first or second), or somtimes both actually show temp readings. That means, the senor reading itself works in principle, but not reliable.

When serial.print the result of getChipName(), I get “DS18B20” for the senor which also returns then the temp reading, however, if I get NAN for the chip name, then also its corresponding temp reading is NAN. That’s why I assume that the respective sensor address was initially not recognized, hence no temp reading?

I have tested the very same test code on an electron (0.8.0-rc.14, also 3v3 power supply), and that worked just perfectly fine. Out of 5 restarts of the electron all of them returned rigth away both temp readings.

Is this a Boron firmware issue, or is there anything else I overlooked?

Thanks for any insights!

I was able to reproduce some inconsistent behavior but I don’t know the cause at this time.

I used two TO-92 DS18B20s in a breadboard with a 4.7K pull-up resistor. Power was 3.3V. Boron 2G/3G with 0.8.0-rc.27.

From the output of my test program, the first test ran perfectly. Then the no devices could be scanned for a while. Sometimes only one of the two would be found:

0000197261 [app] INFO: DS18B20 addr=0x2899040b08000097 found (index=0)
0000197280 [app] INFO: DS18B20 addr=0x288b210b08000088 found (index=1)
0000198054 [app] INFO: index=0 tempF=69.800003 tempC=21.000000 try=1 addr=0x2899040b08000097
0000198829 [app] INFO: index=1 tempF=71.037498 tempC=21.687500 try=1 addr=0x288b210b08000088
0000202247 [app] INFO: no sensors found
0000207245 [app] INFO: no sensors found
0000212255 [app] INFO: no sensors found
0000217246 [app] INFO: no sensors found
0000222259 [app] INFO: no sensors found
0000227245 [app] INFO: no sensors found
0000232258 [app] INFO: no sensors found
0000237261 [app] INFO: DS18B20 addr=0x288b210b08000088 found (index=0)
CRC Failed
CRC Failed
CRC Failed
0000240350 [app] INFO: index=0 tempF=71.150002 tempC=21.750000 try=4 addr=0x288b210b08000088
0000242261 [app] INFO: DS18B20 addr=0x2899040b08000097 found (index=0)
0000242281 [app] INFO: DS18B20 addr=0x288b210b08000088 found (index=1)
CRC Failed
CRC Failed
0000244599 [app] INFO: index=0 tempF=69.912498 tempC=21.062500 try=3 addr=0x2899040b08000097
CRC Failed
0000246145 [app] INFO: index=1 tempF=71.150002 tempC=21.750000 try=2 addr=0x288b210b08000088
0000247261 [app] INFO: DS18B20 addr=0x2899040b08000097 found (index=0)
CRC Failed
CRC Failed
CRC Failed
CRC Failed
CRC Failed
0000251127 [app] INFO: DS18B20 index=0 addr=0x2899040b08000097 read failure
0000252260 [app] INFO: no sensors found

This is the test code I used:

// dependencies.DS18B20=0.1.9
#include "DS18B20.h"

// TO-92 case:
// With flat side facing you and the device with leads facing down to plug into a breadboard:
// 1   2   3
// GND DQ  VCC

SerialLogHandler logHandler;

const uint16_t ONE_WIRE_PIN = D2;
const size_t MAX_SENSORS = 10;
const size_t MAX_TRIES = 5;
const unsigned long TEST_PERIOD_MS = 6000;

DS18B20 ds(ONE_WIRE_PIN);
size_t numSensors = 0;
uint8_t sensorAddresses[MAX_SENSORS][8];
unsigned long lastTest = 0;

void runTest();

void setup() {

}

void loop() {
	if (millis() - lastTest >= TEST_PERIOD_MS) {
		lastTest = millis();
		runTest();
	}
}

void runTest() {
	ds.resetsearch();
	for (numSensors = 0; numSensors < MAX_SENSORS; numSensors++) {
		if (!ds.search(sensorAddresses[numSensors])) {
			break;
		}
		Log.info("DS18B20 addr=0x%02x%02x%02x%02x%02x%02x%02x%02x found (index=%u)",
				sensorAddresses[numSensors][0], sensorAddresses[numSensors][1], sensorAddresses[numSensors][2], sensorAddresses[numSensors][3],
				sensorAddresses[numSensors][4], sensorAddresses[numSensors][5], sensorAddresses[numSensors][6], sensorAddresses[numSensors][7],
				numSensors);
	}

	if (numSensors > 0) {
		for(size_t ii = 0; ii < numSensors; ii++) {
			bool success = false;

			for(size_t tries = 0; tries < MAX_TRIES; tries++) {
				float tempC = ds.getTemperature(sensorAddresses[ii]);
				if (ds.crcCheck()) {
					float tempF = tempC * 9.0 / 5.0 + 32.0;
					Log.info("index=%u tempF=%f tempC=%f try=%u addr=0x%02x%02x%02x%02x%02x%02x%02x%02x",
							ii, tempF, tempC, (tries + 1),
							sensorAddresses[ii][0], sensorAddresses[ii][1], sensorAddresses[ii][2], sensorAddresses[ii][3],
							sensorAddresses[ii][4], sensorAddresses[ii][5], sensorAddresses[ii][6], sensorAddresses[ii][7]);
					success = true;
					break;
				}
			}
			if (!success) {
				Log.info("DS18B20 index=%u addr=0x%02x%02x%02x%02x%02x%02x%02x%02x read failure",
						ii,
						sensorAddresses[ii][0], sensorAddresses[ii][1], sensorAddresses[ii][2], sensorAddresses[ii][3],
						sensorAddresses[ii][4], sensorAddresses[ii][5], sensorAddresses[ii][6], sensorAddresses[ii][7]);
			}
		}
	}
	else {
		Log.info("no sensors found");
	}

}
1 Like

Thanks for checking! I used your test code on my Boron setup and can confirm that the sensors are randomly not found, see below the output:

0000162006 [app] INFO: no sensors found
0000168013 [app] INFO: no sensors found
0000174008 [app] INFO: no sensors found
0000180017 [app] INFO: DS18B20 addr=0x280c59c81f1301d2 found (index=0)
0000180803 [app] INFO: index=0 tempF=73.962502 tempC=23.312500 try=1 addr=0x280c59c81f1301d2
0000186004 [app] INFO: no sensors found
0000192017 [app] INFO: no sensors found
0000198017 [app] INFO: DS18B20 addr=0x280c59c81f1301d2 found (index=0)
0000198035 [app] INFO: DS18B20 addr=0x284952d31f130190 found (index=1)
0000198807 [app] INFO: index=0 tempF=73.962502 tempC=23.312500 try=1 addr=0x280c59c81f1301d2
0000199579 [app] INFO: index=1 tempF=73.625000 tempC=23.125000 try=1 addr=0x284952d31f130190
0000204017 [app] INFO: DS18B20 addr=0x280c59c81f1301d2 found (index=0)
0000204791 [app] INFO: index=0 tempF=73.962502 tempC=23.312500 try=1 addr=0x280c59c81f1301d2
0000210016 [app] INFO: no sensors found
0000216017 [app] INFO: DS18B20 addr=0x280c59c81f1301d2 found (index=0)
0000216794 [app] INFO: index=0 tempF=73.962502 tempC=23.312500 try=1 addr=0x280c59c81f1301d2
0000222017 [app] INFO: DS18B20 addr=0x280c59c81f1301d2 found (index=0)
0000222035 [app] INFO: DS18B20 addr=0x284952d31f130190 found (index=1)
0000222807 [app] INFO: index=0 tempF=73.962502 tempC=23.312500 try=1 addr=0x280c59c81f1301d2
0000223579 [app] INFO: index=1 tempF=73.625000 tempC=23.125000 try=1 addr=0x284952d31f130190
0000228003 [app] INFO: no sensors found
0000234017 [app] INFO: no sensors found
0000240017 [app] INFO: DS18B20 addr=0x280c59c81f1301d2 found (index=0)
0000240035 [app] INFO: DS18B20 addr=0x284952d31f130190 found (index=1)
0000240807 [app] INFO: index=0 tempF=73.962502 tempC=23.312500 try=1 addr=0x280c59c81f1301d2
0000241580 [app] INFO: index=1 tempF=73.737503 tempC=23.187500 try=1 addr=0x284952d31f130190
0000246017 [app] INFO: no sensors found
0000252012 [app] INFO: no sensors found
0000258017 [app] INFO: DS18B20 addr=0x280c59c81f1301d2 found (index=0)
0000258036 [app] INFO: DS18B20 addr=0x284952d31f130190 found (index=1)
0000258807 [app] INFO: index=0 tempF=73.962502 tempC=23.312500 try=1 addr=0x280c59c81f1301d2
0000259580 [app] INFO: index=1 tempF=73.737503 tempC=23.187500 try=1 addr=0x284952d31f130190
0000264011 [app] INFO: no sensors found
0000270017 [app] INFO: DS18B20 addr=0x280c59c81f1301d2 found (index=0)
0000270036 [app] INFO: DS18B20 addr=0x284952d31f130190 found (index=1)
0000270807 [app] INFO: index=0 tempF=73.962502 tempC=23.312500 try=1 addr=0x280c59c81f1301d2
0000271579 [app] INFO: index=1 tempF=73.737503 tempC=23.187500 try=1 addr=0x284952d31f130190
0000276005 [app] INFO: no sensors found
0000282017 [app] INFO: DS18B20 addr=0x280c59c81f1301d2 found (index=0)
CRC Failed
CRC Failed
0000284342 [app] INFO: index=0 tempF=74.074997 tempC=23.375000 try=3 addr=0x280c59c81f1301d2
0000288017 [app] INFO: DS18B20 addr=0x280c59c81f1301d2 found (index=0)
CRC Failed
CRC Failed
0000290339 [app] INFO: index=0 tempF=74.074997 tempC=23.375000 try=3 addr=0x280c59c81f1301d2
0000294017 [app] INFO: no sensors found
0000300017 [app] INFO: DS18B20 addr=0x280c59c81f1301d2 found (index=0)
0000300035 [app] INFO: DS18B20 addr=0x284952d31f130190 found (index=1)
0000300807 [app] INFO: index=0 tempF=74.074997 tempC=23.375000 try=1 addr=0x280c59c81f1301d2
0000301579 [app] INFO: index=1 tempF=73.737503 tempC=23.187500 try=1 addr=0x284952d31f130190
0000306008 [app] INFO: no sensors found
0000312007 [app] INFO: no sensors found
0000318007 [app] INFO: no sensors found
0000324017 [app] INFO: no sensors found
0000330011 [app] INFO: no sensors found
0000336017 [app] INFO: no sensors found
0000342017 [app] INFO: DS18B20 addr=0x280c59c81f1301d2 found (index=0)
0000342792 [app] INFO: index=0 tempF=74.074997 tempC=23.375000 try=1 addr=0x280c59c81f1301d2
0000348017 [app] INFO: DS18B20 addr=0x280c59c81f1301d2 found (index=0)
0000348800 [app] INFO: index=0 tempF=74.074997 tempC=23.375000 try=1 addr=0x280c59c81f1301d2
0000354017 [app] INFO: DS18B20 addr=0x280c59c81f1301d2 found (index=0)