DS18B20 and OneWire lib just plain buggy?

Hi, I’m running two and three DS18B20 sensors via a single pin (D4). I’m constantly missing readings. On the three sensor application, I can get one, two, or three readings. I ran address_scanner.ino and that sees, one, two, and three sensors as it loops. I am bus powering the DS18B20 with 3.3 volt.

By now I have spent enough time to buy the most expensive temperature sensors out there…

TIA

What device, firmware version, and library are you using? Sharing your code wouldn’t hurt either.

Powering the DS18B20s at 5V is much more reliable. The Photon/Electron/P1 are 5V tolerant so this works well. (Do not do this on the Argon/Boron/Xenon which are not 5V tolerant.)

The most important thing is to monitor the checksum. When it’s not valid, retry. With a 5V supply and immediate retry on invalid checksum I have DS18B20s on over 100 feet of wire that read reliably.

3 Likes

Photon, 0.7 and 0.8.

OneWire (2.0.3)

When I was having problems, I simply installed address-scanner.ino for testing. Same issue on both of my Photons each with different sensors. Sometime if finds all three addresses, sometimes none at all, and any combination. I figured if the sensors can’t even be reliably found, there was no way I could get reliable readings.

So simply run the devices off of 5v, and pull-up the input pin with 5v also? 10k pullup?

Thanks

Also have seen where people have put a .01 mF on the signal. I have have not put a scope on this yet but have a nice Tektronix, which is practically never used.

Power the devices from 5V and also pull-up to 5V on D0 and D1. A 4.7K resistor is better, you can even go down to 2.2K. I haven’t needed to add capacitors.

Tried the 5v bias and no change at all. Running address-scanner.ino…

No more addresses.

No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0x3F, 0x9E, 0xC0, 0x17, 0x1, 0xD8
No more addresses.

Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xB5, 0x77, 0xA1, 0x16, 0x5, 0xDF
Chip = DS18B20 Temp sensor
ROM = 0x28, 0xFF, 0xF3, 0xC2, 0xC0, 0x17, 0x1, 0x11

I can’t believe I have that many bad devices as behaviour is the same on two different applications. I can only assume this One Wire library is bad. I’m thinking about trying some I2C devices…

I have dozens of DS18B20s. Many of the busses have two or three devices on them.

I haven’t updated the software in a while but I’m using the DS18B20 library version 0.1.6, which has a dependency on the OneWire library, version 2.0.1.

The newer versions should be fine, but I know that combination works well with Photons, a mix of system firmware 0.6.3 and 0.7.0.

It does automatically retry on failed checksum, but it doesn’t happen very often. Multi-drop definitely works, and I’m using it with 5V and 4.7K pull-up resistors.

OneWire library 2.0.3.

address-scanner.ino just never seems to throw a CRC so now I’m thinking maybe some kind of timing issue… I think I’ll copy address-scanner.ino and make some timing mods to it.
I did assume address-scanner.ino was in the default library as a testing tool but you never know. You might want to try it with 2.0.3 for grins…

Fascinating tidbit … in address-scanner.ino

if (!wire.search(addr)) {
Serial.println(“No more addresses.”);
Serial.println();
wire.reset_search();
//delay(250);
return;
}

will enable this delay…

This very first scan only finds the first device, and it appeared to be better, until it grabbed a two device scan… :frowning:

Turned up the delay 1250 ms, no change. It basically appears…

wire.search(addr) can turn true, at any time after the first device is detected. No CRC are fired, and my applications generally return accurate temperatures…

What is your wire topology?
I had a "tree" configuration with the first wire (20 ft) to sensor #1, then branching out to two 10 ft wires to sensor #2 and sensor #3, respectively. That gave me very unstable results (some sensors not always recognized), similar to what you're experiencing. I changed the wire topology to a linear line with a single 40 ft wire and the sensors attached at 20, 30, and 40 ft from the Photon. This gave me reliable results, the sensors are consistently found. I gained this insight from an article someone posted (thank you), but unfortunately I can't find it anymore.

1 Like

Has anyone used more than 3 DS18B20s on the same pin? I’m using the OneWire library, trying to put 5 on one bus. With 3 sensors I get all addresses and good, clean data – as soon as add a fourth, it just tells me “no more addresses” until I unplug it, then it returns data from the three still connected.

It doesn’t appear to be faulty hardware: each sensor individually and in groups of three works. Only when I add a fourth does it fail. Any thoughts?

Cheers,
Brett

Can you explain 5V tolerant? I didn’t know that the 5V was different between the Photon and Argon.

Although both controllers are running at 3.3V and all output levels will max out at that, the STM32 controller on the Photon can tolerate 5V on most of its GPIO pins, the nRF52840 on the Argon on the other hand cannot and applying 5V to any of its pins will most likely damage it.

1 Like

Thanks, I did not know that. I need to disconnect the 5v devices from my xenon prototype ASAP and explore other options.