Shop OBEX P1 Docs P2 Docs Learn Events
DS18B20 on long wire — Parallax Forums

DS18B20 on long wire

I have a weather station program that runs continuously and would like to monitor the temperature in my outside shop also. I've read that 'one wire' devices don't do well with long wires.

Is there an easy way to remedy this? It sounds like the problem is mainly in the signal timing. Would it help to slow down the PROP clock speed while the DS18B20 is read? Or could the 'one wire' object be modified for timing?

I've also looked at this MAXIM discussion but can't see how to use 2 or 3 prop pins for the "one wire' read.

https://www.maximintegrated.com/en/app-notes/index.mvp/id/244

My weather station is here and several other threads in which I was helped by forum members. Thanks!
https://forums.parallax.com/discussion/168567/spurius-characters-occationally#latest


Thanks
Aaron

Comments

  • I would start by using three wires: Vin, Gnd, and Signal. Trying to power the unit from the signal line only adds to complexity. Since the line is long, make Vin about 9V, and regulate it down to Vdd at the far end. Next, I would put pull-ups at both ends of the cable.

    BTW, you need only one Prop pin for the 1Wire read, not two or three.

    -Phil
  • And decoupling cap on the sensor itself. (Don't think the regulator is really needed unless there's a lot
    of resistance in the wiring?
  • Hi

    How long is a piece of string?? er wire to your outside shop.
    what about lightening protection.

    I have had an outdoors 18B20 temp sensor running for some time on about 20 feet of wire- using parasitic power- and no problems.
    A sightly longer run to the hot water tank and I get problems at higher temperatures (80 c plus) again using the parasitic power arrangement. I think it would be ok if I used an extra wire to feed it power.
    The signal timing is etched in silicon- it cant be changed.

    In parasitic mode (data and 0v only) the vcc pin and 0v pin of the 18B20 are s/c and data is sent and received in the same data line, so that's two wires.
    By supplying power directly to the vcc pin of the 18B20 higher temperatures and longer lines can be achieved, so that's 3 wires.


    The prop only needs one pin with a 4k7 pullup.
    set the pin to input.
    write a zero to the pin.
    now when you make the pin output it will pull the pin low.
    when you set the pin to input the pullup resistor pulls it high.
    while in input mode you can read the pins value- it doesnt matter that you have written a zero to it already- that only effects the pin when it is made output.

    You can achieve better performance in parasitic mode by sending a full binary 1 enhancing the current supply to the 18B20 during idle periods and when transmitting, but not when receiving! ALL transactions are initiated by the controlling microprocessor.

    Study the data sheet.
    Its a good beginners project as the protocol is simple- a short pulse low is a 1, a long pulse is a 0. (if I recall correctly)
    for the values of short and long- study the data sheet.

    Dave
  • I definitely recommend avoiding parasite power in the first instance, its something many
    people seem to have had issues with judging by various forums. Once its working you can
    try changing to parasitic mode, but remember to take out the decoupling caps if you had any.

    In particular before trying a long wire configuration, test on a breadboard in case your sensor
    is broken or counterfeit (DS18B20 is expensive enough that there are definite reports of counterfeits).

    These days CAT5 seems to be the goto cheap signal cable choice, using 3 wires rather than 2 isn't
    so pressing...
  • I wasn't planning on using parasite power but +, - and signal. It will be about 70' away. The cable is underground and is multi conductor shielded telephone wire
    (the type they bury directly) inside of conduit.
    I've used these sensors several times before but less than 10' away.

    How would the decoupling cap be? On + wire?
  • kwinnkwinn Posts: 8,697
    AGCB wrote: »
    I wasn't planning on using parasite power but +, - and signal. It will be about 70' away. The cable is underground and is multi conductor shielded telephone wire
    (the type they bury directly) inside of conduit.
    I've used these sensors several times before but less than 10' away.

    How would the decoupling cap be? On + wire?

    Decoupling cap goes between + & - on the sensor end/board.
  • Despite what others have recommended, I would still put pull-ups on both ends. The reason is that you want current flowing through the signal wire on both transmit and receive. That's what will help eliminate noise issues. Putting a pull-up only on the Propeller end will result in virtually no current flowing during transmit, leaving the line in a high-impedance state, susceptible to noise.

    -Phil
  • The timing constraints are tight, and whether it will work or not comes down to the time constant of the cable capacitance with the pullup resistor.

    I'm using Cam Thompson's onewire.spin. He has the Prop pull the one-wire pin LOW for 4 microseconds in order to start a read operation. The DS18B20 expects to respond within 15 microseconds, that is, within 11 microseconds after the end of the low pulse, so the pullup resistor has to bring the line back high within 11 microseconds. There isn't much you can do with that timing, since the 15 microseconds is set in stone in the one-wire protocol.

    For one project that was measuring temperature profiles in a reservoir, I constructed a 26 meter cable, which had 16 DS18B20's strung out along its length. The time constant works out something like this: 150 pF per meter for the cable, which multiplies out to 3.9 nF. And with a 1000Ω pullup resistor, it comes out to 3.9 µs time constant. The cable has a three-wire direct power arrangement. I'm sure it would not have worked with parasite power.

    You should have no problem with 20 feet, especially given the 3-wire arrangement.

  • AGCB,

    In Nuts and Volts #82, JonnyMac used a 1K pull-up, and in this tread from August 2009 he says that this allows 3.3 mA to flow from 3.3V.
    https://forums.parallax.com/discussion/115369/1-wire-object-has-no-way-of-talking-to-the-configuration-registers-anybody-kn
  • MJBMJB Posts: 1,235
    I run dozens of DS18B20's on a over 30 m bus without problems.

    If possible avoid parasitic power
    and have a look here:

    https://maximintegrated.com/en/app-notes/index.mvp/id/148
  • Thanks all
    I'm out of town till weekend but will be trying this ASAP when I get home. Much good info and encouraging too!
    I like monitoring things, some just for fun but others for important reasons. If I can get the shop temperature working good there may be other things to checkup on.

    Thanks again

    Aaron
  • That Maxim-ic app note shows cables of up to 300 meters. Wow. It does get more complicated with active pullups.

    Here's a 'scope shot from my 26m cable driven simply by a Prop pin with 1kΩ pullup, and also a 100Ω resistor in series with the Prop pin. The 100Ω in series is part of the pin protection, but it also helps to distinguish pulses from the Prop from responses from the DS18B20.

    The bottom yellow trace shows the Prop issuing first the long reset pulse, followed by the presence pulse that is put on the bus by all of the DS sensors simultaneously. Then the Prop is sends a skip rom command followed immediately by a convert-T command. That makes all of the sensors on the bus at once start their temperature conversion, which takes time, up to 750ms for 12 bit resolution. Subsequent commands (not shown on the 'scope) test if the conversion is complete and then read back the readings one sensor at a time.

    The middle orange trace is zoomed in on the skip rom command, $CC (=%11001100), sent least significant bit first, and then the convert-T, $44 (=%01000100). The top red trace is further zoomed in on a zero bit and a one bit. The falling edge is fast due to only 100Ω and the pin low impedance to ground. The rising edge is slower, due to the 1kΩ pull up to the +3.3V supply, and the time constant with the cable capacitance is close to 6µs. Cam's oneWire driver allows 8 microseconds for both the low time and for the recovery between bits.
    519 x 448 - 16K
  • Got it to work with no mods except using a 1K pullup. Power is 3.3 volts from Quickstart board.

    3 different wire types with soldered splices. Next I'm going to try adding 1 or 2 more sensors and see what happens.
    Thanks
    Aaron
  • I ran about 60' of coax cable in PVC conduit buried in the ground with several one-wire devices operating in parasitic mode. Everything worked well until it rained. With the humidity changes, water collected in the conduit and the one-wire communications ceased to function. I pulled the coax out of the conduit and hung it in air to dry and the communications returned to normal.

    Discovery
  • kwinnkwinn Posts: 8,697
    Discovery wrote: »
    I ran about 60' of coax cable in PVC conduit buried in the ground with several one-wire devices operating in parasitic mode. Everything worked well until it rained. With the humidity changes, water collected in the conduit and the one-wire communications ceased to function. I pulled the coax out of the conduit and hung it in air to dry and the communications returned to normal.

    Discovery

    Better to use a single piece of plastic well pipe rather than conduit. That way no water can get into the pipe as long as the ends are sealed or start and end indoors. Used it to connect two out buildings to the main house several years ago and had no problems with comms during my time there. As a bonus the pipe is much lower cost than PVC conduit.
  • The cheapest pipe I've found is economy grade irrigation tubing sold at Tractor Supply Company.
    Comes in 1" and maybe larger, 100' rolls and maybe longer
Sign In or Register to comment.