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");
}
}