1
\$\begingroup\$

I'm trying to setup a network of temperature sensors for my house connected to a Raspberry PI. I'm using Cat6 unshielded cable (data + ground running on one pair, 5v/ground running on another). To test. the lines (5v, GPIO4, Ground) from the RPI are connected to a breadboard, which has a pair of punchdown blocks pushed into it; ~60m of unshielded CAT6 UTP is run between the two blocks. If I connect my DS18B20 direct to the RPI without the CAT6, it works fine - the RPI detects it and it shows up under "/sys/bus/w1/devices"; if I connect it to the punchdown block at the far end of the CAT6, I either get nothing at all, or an unstable collection of "ghost" devices with incorrect IDs under there. Interestingly, if I connect the sensor direct to the RPI, but also connect the CAT6 after it (with nothing on the end), it doesn't work any more.

Things I've tried:

  • Using RPI internal pull-up on 1-wire bus, or using external 4.7k resistor between the RPI 5v line and the data line
  • Putting a schottky diode between the ground and the signal line next to the sensor (Using a Vishay 1N5817 - should I be using a different diode?)
  • Powering the sensor with a 5v line from the RPI GPIO, or letting it use parasite power from the data line
  • Putting a 100 ohm resistor in series with the data pin of the sensor (this shouldn't really be necessary with only one sensor - it seems mainly relevant for reducing signal reflections in networks with longer stubs - but I tried it anyway)

I've also measured the resistance and capacitance of the cable, which come to about 6ohms each way for resistance, and 2.8nF of capacitance between the data line and ground. AFAICT the resistance should be fine (these devices draw very little power). I'm not sure if the capacitance is an issue but I would assume not since this is pretty much bang on for CAT6 cable (14pF/foot) and a 60m run is well within what should be possible for a 1 wire bus over CAT6 from everything I've read.

What else can I try? Ideally things that don't require an oscilloscope since I I don't currently have one...

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can't pull-up the GPIO pin to 5V, the IO pin is not 5V tolerant. \$\endgroup\$ Commented Jan 10, 2021 at 13:10

2 Answers 2

2
\$\begingroup\$

The real reason is that the cable adds up just so much capacitance, that the internal weak pull-up of the Raspberry Pi or even an external 4.7kohm resistor is not strong enough to charge the cable capacitance fast enough to logic high level, so devices on the bus sample the data pin while the voltage is still rising, but is not yet reliably detected as logic high.

The internal pull-up is in the order of 50 kilo-ohms or so.

Another problem is that the pull-up resistor for the GPIO can't be connected to 5V, the Raspberry Pi IO pin is not 5V tolerant, and it will get clamped to about 3.6V by as the internal protection diodes start to conduct current. Fortunately, 4k7 does not allow a lot of current to flow, so it is not immediately damaged, but this is something that should not be done.

Generally the strongest pull-up value to 5V accepted by the electrical specs is 1k5 which allows for 3.3mA. Converting that to 3.3V pull-up means 1 kohm to 3.3V, so you can put a stronger pull-up, as long as it is to 3.3V.

The DS1820B will understand 3.3V as logic 1, and it can pull at least 4mA on data pin, so it can be possible to drop the pull-up resistor value to 825 ohms. The Raspberry Pi IO pins should be able to handle much more than 4mA of sink current.

So simply change the pull-up to be stronger, and connect the pull-up to 3.3V. Keep the sensor supply voltage at 5V like it is.

\$\endgroup\$
3
  • \$\begingroup\$ This is useful information, thanks. I was mislead by the fact that some people seem to have had success with running this configuration at 5v (see e.g. hackaday.io/project/12418-garden-squid/log/…). Anyway, I've moved to 3.3v and lowered the pull-up to 1k but still no joy. This is odd because there are definitely plenty of people on the internet who have managed to do what I'm trying to achieve without all these problems \$\endgroup\$ Commented Jan 10, 2021 at 14:54
  • \$\begingroup\$ Ok, I've made it work, in part by following your advice. What I ended up doing was pulling the data line up to 3.3V with the 1k resistor but powering the sensor with the 5v from the RPI, and that worked. Could you tweak your answer to reflect this is a potential way and I will accept it? \$\endgroup\$ Commented Jan 10, 2021 at 16:44
  • \$\begingroup\$ I can edit it - but do note that I never mentioned changing the sensor power supply from 5V to 3.3V \$\endgroup\$ Commented Jan 10, 2021 at 16:45
1
\$\begingroup\$

I don't have a definitive answer but when I investigated this topic for my home heating I was sufficiently persuaded by my reading that direct bit-banging on the Pi GPIOs might be problematic due to timing jitter. I found this 1-wire Pi-plus and decided it was worth the investment if it saved me some trouble as it buffers the data electrically and should help with timing accuracy.

enter image description here

Figure 1. 1-wire Pi-plus timing is independent of the Pi.

You may be on the edge of working and the cable capacitance is just pushing you over the edge. This device might help with your troubles.

\$\endgroup\$
1
  • \$\begingroup\$ Good to know. If I have more problems with the built-in 1-wire support I may consider this. \$\endgroup\$ Commented Jan 10, 2021 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.