geekinthesticks
Posts: 96
Joined: Fri Feb 08, 2013 7:22 pm

DS18B20 Max Distance

Wed Mar 06, 2013 9:07 am

OK this is a "How long is a bit of string" question :) I have already read a similar thread: http://www.raspberrypi.org/phpBB3/viewt ... 37&t=30026

I want to place one of these sensors outside. The distance is around 3m, which as I understand it should be no problem. I have tried both Cat 6 and some telephone wire (2 twisted pairs). However, I always get the following result:

Code: Select all

[ian@alarmpi ~]$ cat /sys/bus/w1/devices/28-00000400b056/w1_slave
50 05 4b 46 7f ff 0c 10 1c : crc=1c YES
50 05 4b 46 7f ff 0c 10 1c t=85000
As I understand it the 85 degrees means the sensor is either still initialising, or has some other problem. It's definitely the length of the wire because attaching it to a short length (1m) works fine. I have also tried several different sensors.

Any suggestions on how to overcome this problem. My Arduino worked fine with the same sensor on a 5m length of the same wire.

User avatar
malakai
Posts: 1382
Joined: Sat Sep 15, 2012 10:35 am

Re: DS18B20 Max Distance

Wed Mar 06, 2013 9:11 am

The difference between the Pi and Arduino would most likely be 3v on the Pi and 5v on the Arduino could you re wire it to use 5v on the Pi if your not already doing that. Note the GPIO pins on the Pi are not 5v tolerant so some resistors would have to be put in place.
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)

geekinthesticks
Posts: 96
Joined: Fri Feb 08, 2013 7:22 pm

Re: DS18B20 Max Distance

Wed Mar 06, 2013 9:24 am

Thanks I'll try that as I have it running from 3.3V at the moment. If I connect a 4K7 between that data line and the Pi 3V3, the connect VDD to 5V would that be safe?

albundy
Posts: 31
Joined: Tue Jul 17, 2012 4:56 pm

Re: DS18B20 Max Distance

Wed Mar 06, 2013 9:49 am

I believe, but I am not 100% sure, that the ds18b20 can be used with 5V while the data line is using a pull-up resistor to 3V3. According to the manufacturer the data line of the ds18b20 uses an open drain.

This was my question I've sent to the manufacturer:
Currently I have several DS18B20 connected. They are externally
powered by a 3.3V power supply. There is also a 4K7 pull up
between the 3V3 power supply and the data line. The pin of the
CPU that is used to communicate with the DS18B20 can withstand
3V3 max. Any higher and it will be fried.
This works fine for relative short lines but not for longer
lines. The 3V3 power supply drops below 3V due to cable length.

Is it possible to use an external 5V power supply for the DS18B20
while the data line stays below 3V3 max?
What I mean is connecting the VDD line of the DS18B20 to +5V and
connecting the 4K7 pull up on the data line to 3V3.
I believe the DS18B20 uses a pull down transistor on the data
line so using a 4K7 pull up connected to 3V3 will suffice to keep
the dataline at 3V3 max while VDD of the DS18B20 is connected to
+5V.

Will this work and keep the dataline at 3V3 max while powering
the DS18B20 with 5V?

This was their response:
Yes, you can make VDD = 5V and Vpullup = 3.3V. The Data line (DQ)
is open-drain so it can only go as high as the Vpullup voltage.

geekinthesticks
Posts: 96
Joined: Fri Feb 08, 2013 7:22 pm

Re: DS18B20 Max Distance

Wed Mar 06, 2013 12:48 pm

Thanks. I tried running it off 5v, but same result. The only other thing I can think of is that my PSU (Samsung Galaxy 2) isn't beefy enough. I am awaiting delivery of a powered hub from ModMyPi, which can also act as a PSU. I'll see if that make any difference.

If that doesn't work would something like a GertBoard help? I want to run several temperature sensors, but the max distance I need to go is about 10m.

joshmosh
Posts: 62
Joined: Fri Aug 03, 2012 12:04 pm

Re: DS18B20 Max Distance

Wed Mar 06, 2013 1:34 pm

Hi,
I have two DS18B20 connected. Longest distance is about 3 m. Vcc is connected to 3.3 V. In the beginning, I had exactly the same readings you had: 85 degrees. Lowering the pull up to 2k helped in my case. I am using poor quality cabling (simply three wires in parallel). With cat5 or cat7 cabling you should make even longer distances. Also, bringing down the pull up to 1.2 k may help, although I would'nt go below that.

Good luck
Josh

geekinthesticks
Posts: 96
Joined: Fri Feb 08, 2013 7:22 pm

Re: DS18B20 Max Distance

Sat Mar 09, 2013 11:45 am

Thanks for all the suggestions. Changing to 5v and dropping the load resistor value helped when I used bare sensors. However, I want to use one of Adafruits waterproof sensors. The sensor will be outside and I have had several problems with bare sensors suffering from condensation, even though they have been inside a box. The waterproof sensor will only work on a very short extended wire.

So, I have decided that the simplest solution is to buy another Pi, which I can place in the garage. This allows me to have a very short cable run to the outside sensor with the added benefits of making it easy to put sensors on the central heating pipes and the hot water pipe from the Aga.

pgman
Posts: 22
Joined: Sun Jan 06, 2013 8:34 pm

Re: DS18B20 Max Distance

Sat Mar 09, 2013 3:42 pm

Are you running in 1-wire mode?

According to the datasheet 1-wire mode, also called parasitic power mode, only needs ground and DQ with a pull-up resistor to +ve. In this mode the chip can pull as much as 1.5mA, so for 3.3v the resistor should be no greater than 2.2k for a single DS18b20. If you have more than one on the bus, you will need to lower that resistance.

Also if you are running in 1-wire mode you have to allow sufficient time for the A/D conversions to take place, as I believe it takes longer to happen (750ms in 12-bit mode).

If you go for 2-wire mode (0v, +ve and DQ) then the pull-up resistor is just for the DQ bus, and it doesn't need to change if you have more devices on the bus. It is possible to make your own waterproof sensors with an old radial electrolytic capacitor case and some sealant (epoxy, potting compound or silicon sealant), and then you can run in 2-wire mode.

Alternatively use an Arduino to connect to the DS18B20s and talk to that over serial. This is what the gertboard can be used for, but a small arduino board (or even a chip with a crystal and bootloader) is very inexpensive.

User avatar
spennig
Posts: 84
Joined: Mon Aug 29, 2011 11:34 am
Location: New Forest

Re: DS18B20 Max Distance

Sat Mar 09, 2013 7:15 pm

At least 20m here in 1-wire mode.

fraklapince
Posts: 1
Joined: Sun Feb 23, 2014 9:58 am

Re: DS18B20 Max Distance

Sun Feb 23, 2014 10:15 am

for information, it seems that the DS18B20P works only in parasite mode http://www.sbprojects.com/projects/rasp ... rature.php (search "18B20-P")
http://lookvisor.com/2012/11/13/hand-ma ... mperaturu/ confirms

changing for the right reference makes the difference.

User avatar
some_evil
Posts: 209
Joined: Thu Dec 18, 2014 3:16 am
Location: Albury, Australia

Re: DS18B20 Max Distance

Sun Mar 08, 2015 11:47 pm

spennig wrote:At least 20m here in 1-wire mode.
spennig can you please elaborate on how you achieved 20m? I am about to embark on a project where cable > 20m and am after all the tips i can get.

Cheers
PiZeroW - May 2017
Pi 3 - Oct 2016
PiZero - June 2016
Pi 2 - Jan 2016
Pi B+ - Dec 25 2014

User avatar
some_evil
Posts: 209
Joined: Thu Dec 18, 2014 3:16 am
Location: Albury, Australia

Re: DS18B20 Max Distance

Sat Apr 25, 2015 10:31 am

I can now report back that I have my Pi in my server cabinet at one end of the house, and the furthest Ethernet port from the server is about 30-35m and I am receiving signals back from my therm in this socket.... working flawlessly!
PiZeroW - May 2017
Pi 3 - Oct 2016
PiZero - June 2016
Pi 2 - Jan 2016
Pi B+ - Dec 25 2014

xN0Cx
Posts: 1
Joined: Tue Jul 28, 2015 12:58 pm

Re: DS18B20 Max Distance

Tue Jul 28, 2015 1:00 pm

Can you please give details on how you achieved that distance. what did you use for power and resistor?

jonp
Posts: 1
Joined: Fri May 03, 2013 9:35 am

Re: DS18B20 Max Distance

Tue Jul 28, 2015 6:22 pm

I'm also managing multi-10m distance but I'm using a proper 1-wire driver i.e. http://www.sheepwalkelectronics.co.uk/p ... ucts_id=30

I'm also using a 1-wire hub so I have multiple 10m+ sensors.

samip537
Posts: 32
Joined: Sat Aug 02, 2014 5:06 pm
Location: Turku, Finland

Re: DS18B20 Max Distance

Sat Jan 14, 2017 3:46 pm

jonp wrote:I'm also managing multi-10m distance but I'm using a proper 1-wire driver i.e. http://www.sheepwalkelectronics.co.uk/p ... ucts_id=30

I'm also using a 1-wire hub so I have multiple 10m+ sensors.
Could I have a picture of how are you using the 1-wire driver via possible RJ11 or RJ12 or RJ45?

Also network topology of that 1-wire network would be much appreciated.

P.S Sorry to bump an old thread.


JohnsUPS
Posts: 338
Joined: Fri Jul 06, 2018 2:13 am
Location: USA

Re: DS18B20 Max Distance

Fri Jul 06, 2018 3:15 am

I am in the process of building a data center temp monitor for my work, and have settled on the DS18B20's for the sensors. However, I was concerned about the 1 wire protocol distance, until tonight when I was able to test this. I have five sensors at the end of 470 feet (143 meters) of Cat6 working flawlessly. I am able to take sequential 12bit readings of all five sensors and have yet to see anything other than a valid response. Also, to add insult to injury for the data signal, the wire is still on the spool (actually, the coil may not be too significant). The 470 foot length is just a remainder of something that I had laying around.
My setup is as follows:
-Running OWFS.
-Raspberry PI 3 Raspbian Jessie.
-Using I2C to a DS2482 single channel 1 wire master. I wanted the slew rate control and the output driver this provides.
-The DS2482 is powered with 5V for maximum output swing.The I2C is through discrete level converters made up of TO-92 packaged 2N7000's, each of which has a 10k pullup between source & gate to 3v3. It is just the standard (easily Googleable circuit) level shifter.
-The cat6 cable is configured as follows:
At each end of the cable, I connected the following wires together - for ground, 4 wires - Brn/wht & brn and grn/wht + grn. Blu/wht & blu for data, and for VCC I used orange. This was to try to minimize any interelectrode capacitance versus using, say, Org/wht for data and Org for GND or VCC.
-At the end of the cable by the sensors, I put a 22uf tantalum capacitor between Gnd and VCC.
-All five temp sensors are in parallel at the end of the cable, and there is no more than an inch of wiring between them. They are not being used in parasitic mode.
I intentionally didn't take any care (i used longer wires than I could have) when it came to the breadboard wiring of the 1 wire data signal to the DS2482. Breadboard is a rats nest - I'm almost surprised that it works. When I do finally finish the code and rewire this neatly and pull cable through the data center, I'll have some confidence in it working reliably right off the bat. The actual distance will be way under 328ft/100m anyway. The sensors will be spread out along the length, but after this test I don't think this is going to be a problem.
FYI......

User avatar
yv1hx
Posts: 393
Joined: Sat Jul 21, 2012 10:09 pm
Location: Now an expatriate, originally from Zulia, Venezuela

Re: DS18B20 Max Distance

Fri Jul 06, 2018 5:57 pm

JohnsUPS

That's are very good news, please check you PM inbox.

BR,
Marco
Telecom Specialist (Expatriate, Now working in Lima, Peru!)

http://www.meteoven.org
http://twitter.com/yv1hx

DirkS
Posts: 10882
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: DS18B20 Max Distance

Fri Jul 06, 2018 6:01 pm

yv1hx wrote:
Fri Jul 06, 2018 5:57 pm
please check you PM inbox.
:?: PM :?:

JohnsUPS
Posts: 338
Joined: Fri Jul 06, 2018 2:13 am
Location: USA

Re: DS18B20 Max Distance

Sat Jul 07, 2018 2:28 am

yv1hx wrote:
Fri Jul 06, 2018 5:57 pm
JohnsUPS

That's are very good news, please check you PM inbox.

BR,
YV1HX,
I wanted to post my test results because the search results I got when researching the distance were not too inspiring. I am the type that will test something like this for myself. Because I know that my previous post is searchable, it may provide answers to some folks who are struggling with the distance issue. This is why I was specific on how I utilized the wires in the cable. Maxim's own app notes say this protocol will go quite a distance, but they are light on the details of their wiring other than to say they used category cable. How you choose to connect those twisted pairs make a huge difference.

Also, I do not see an inbox? PM?

User avatar
rpdom
Posts: 22351
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: DS18B20 Max Distance

Sat Jul 07, 2018 4:40 am

JohnsUPS wrote:
Sat Jul 07, 2018 2:28 am
I do not see an inbox? PM?
Forum messaging has been disabled because of possible legal issues. It will probably return if/when those get sorted out.

jackaroo
Posts: 6
Joined: Wed Sep 05, 2018 9:23 pm

Re: DS18B20 Max Distance

Wed Sep 05, 2018 10:07 pm

Hi, folks,

I had the same issue with 1-wire bus length, and found the maxim's app notes not too helpful at first.

Firstly, it is vitally important to understand one thing: The "data" line will be held up by the pull-up resistor until one master or one slave will pull it down according to the protocol. So signalling is created by pulling down this line.

If now the line is too "heavy" (app note) that a single slave can pull it all down, or there are collisions due to signal reflections, serial communication must fail.

So let's start thinking the easy way: On a very short wire, this won't ever become a real problem. But, as others here already wrote, even on 3 metres (which is not even considered a "stub" at maxims, in my case I had those "85000"-readings at some 8 mtrs single line) may fail. Now why?

First of all, it has to do with proper cabling. My line was ok when testing, but then went along with other - relatively high frequency - data and even powered ac-powerlines. So shielded cable is one of the first things to cater for if talking about distances.

Then, Farads come into play: Those of you who remember ol' "10BaseT" coax-networking cables will surely remember this "terminating resistor", which was usually 50 ohms. With 1-wire, this is not really necessary any more, but hey, what was that thing good for at all...?
It feathered those signal reflections that occur at "unterminated line terminals", i. e. signal lines that simply end. Full stop. - Here, capacities are being bounced back into the capacitance (wire), disturbing data communication.

Last then is the design question, how to put all this together. Quoting the app note, there are many uncertainties regarding reliability, "like temperature, humidity and a unpredictable diversion in the device timings" [they use other words there, but the idea may be clear; scale is microseconds].

In so far this odd "application note" of maxims is really good: The don't promote any formulas like "if you want this, do that", but they are honest and say "just try". One subscriber here even had a 470ft coil and got it working (with a booster, though), so it is not a bus problem, but one of the proper wiring.

Hope this helps, cheers, Jack.

====

My eyes see "MicroSoft", my brain reads "NanoWeak" - Linux since Kernel 1.0.36
====

My eyes see "MicroSoft", my brain reads "NanoWeak" - Linux since Kernel 1.0.36

JohnsUPS
Posts: 338
Joined: Fri Jul 06, 2018 2:13 am
Location: USA

Re: DS18B20 Max Distance

Sun Sep 09, 2018 12:32 am

The setup is still working perfectly (and has been for weeks now), but a 1 wire bus master is not a "booster". It is just a proper driver. If someone has a distance requirement, using a driver is the logical place to start. The common method I see is by using a GPIO pin with a pullup, which may be OK for short runs and breadboarding. In my application, doing it this way wasn't even considered. Also, you risk stressing the GPIO pin with too low of a pullup, not to mention exposing the BCM pin to the outside world when the sensor is located a distance away. Conditioning the signal (such as slew rate control and timing) is taken care of by the chip, alleviating reflections and other problems. In my case, I was wanting to read the data over I2C, and also have the data line swing the maximum amount my design would accommodate, which is 5 volts. It also freed up other GPIOs that I needed to use.

As I mentioned in my original post, when using Category cable, how that cable is configured makes a huge difference. You basically want to minimize any capacitance on the data line.

User avatar
rpdom
Posts: 22351
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: DS18B20 Max Distance

Sun Sep 09, 2018 3:13 am

jackaroo wrote:
Wed Sep 05, 2018 10:07 pm
Those of you who remember ol' "10BaseT" coax-networking cables
There was no such thing as "10BaseT" coax. The "T" stands for "Twisted pair" and refers to the CAT-5 type cables that most people are familiar with. Coax Ethernet was 10Base2 (or 10Base5 for the thicker version).

jackaroo
Posts: 6
Joined: Wed Sep 05, 2018 9:23 pm

Re: DS18B20 Max Distance

Fri Sep 14, 2018 11:14 am

"10Base2", correct. Sorry.

But as JohnsUPS mentioned, it is always the better idea to separate such projects from the core in the first place: It reduces the risk of damage and/or intrusion, it makes the "subsystem" more flexible, and it will end up in lesser IO-pin usage.

Quote: "A 1 wire bus master is not a "booster". It is just a proper driver." - Exactly. The difference is: When testing, people often start off with a "proof of concept" attitude. You went the other way right from the beginning, because you knew where you wanted to go. On my way here into this discussion I fell over many, many threads and posts where people didn't even think about that at all.

Anyways, thank you for sending your experience. For me, that will be of great help when expanding the grid, probably next year.

Cheers, Jack

====

My eyes see "MicroSoft", my brain reads "NanoWeak" - Linux since Kernel 1.0.36
====

My eyes see "MicroSoft", my brain reads "NanoWeak" - Linux since Kernel 1.0.36

Return to “Interfacing (DSI, CSI, I2C, etc.)”