Multiple 1-wire buses on the raspberry pi 3 and multiple DS18B20

I have a technical question related to Home Assistant.
I’m trying to connect about 12 DS18B20 sensors to Raspberry Pi 3 running Home Assistant.
Wires are about 10-15 meters each, and I can only connect about 4 sensors when I connect more the Pi doesn’t see any sensors.
I tried changing the resistor value, but that didn’t help a lot (I manage to connect 5 with 2.2K instead of 4.7K).
I have all sensors in star topology - each sensor is connected to CAT 5e cable at one end and on the other ends cables are connected (according to the schema) and then connected to Pi.
I found one interesting blog post: https://blog.oddbit.com/post/2018-03-27-multiple-1-wire-buses-on-the-/
that shows how to enable multiple 1-Wire buses on Pi

In /boot/config.txt instead of adding:

dtoverlay=w1-gpio

you can add:

dtoverlay=w1-gpio,gpiopin=4
dtoverlay=w1-gpio,gpiopin=17

According to the article, this works just fine on Pi, but I don’t know will it work with Home Assistant.
I don’t know the technical details of the implementation of 1-wire support.

I can’t rewire the sensors (they are below the floor) and I don’t want to use WiFi sensors or other wireless networks.

Searching over the internet I found some posts on Domoticz forum that mentioned that some code rewrite was needed there, so I’d like to ask here the devs for information.

For anyone interested: this works perfect
I’ve added:

dtoverlay=w1-gpio,gpiopin=4
dtoverlay=w1-gpio,gpiopin=17

to config.txt on my SD card and I am able to connect multiple 1-wire sensors (DS18B20) to my Pi.
I’m aware that I can connect multiple sensors to one GPIO, but I have very long cables and connecting more than 4 sensors (each on 15m cable) causes problems.
With this setup, I’ll try to connect two sensors to a single bus and hopefully, the problem will be solved.

I’ll update my answer with the results and the schema if everything goes well.

Thanks. I’m about to try to do something similar using existing phone lines coming back to a patch panel where my pi is located. Some of those existing phone lines will probably be 10-15m so I could well hit the same problem you did.

Did you ever get it working with a single gpio pin?

Sadly no, I used 3 pins.
I recently replaced two sensors with Wemos D1, because I needed more sensors, but this produced other problems.
There isn’t a “best way”. MQTT sensors can be used with thermostat but if the WiFi is weak they will be unavailable from time to time and the thermostat can be running without control.

How many of the DS18B20 sensors were you able to get in total with 3 pins? Presumably 9-12 if it’s 4 max successfully per pin?

I’m wanting to use my (unused) pots phone lines but those are all connected together at the patch panel. There’s two panels connected together so I could relatively easily split them and limit the number of sensors per gpio pin but I’d be limited to only 2 pins if I did that and also limited by which panels happened to serve which rooms. Or I could really butcher the wiring to split sensors up any way I wanted but I’m hoping to leave the pots wiring as intact as possible - ideally just disconnect it from the unused incoming wiring but leave all the patch panel punch downs untouched.

It all depends from the topology. 1Wire doesn’t work well with star topology.
I had 5 sensors, each about 20m from Raspberry Pi. In my case max 3 sensors per pin.
If you need more sensors than that consider using ESP8266.
I think you will have problems with phone wires because they don’t have proper shielding. I had cat5 Ethernet cables, but I think phone cables are worst.
Do you have WiFi in all places you want to put sensors?

My phone line wiring is all cat5E, so there’s that.

But yeah I was reading last night about total ‘line weight’ being a limit for 1-wire and with the pots star arrangement of all long wiring, I’m sure I will have too much total weight unless I start disconnecting things. So given your experiences if I were to disconnect all the telephones lines from the patch panel that I want to use and connect only ~3 together then I can likely get to 9 temperature sensors? Can I use any number of the general purpose gpio pins on the pi? I.e. 4 pins = 12 sensors etc. I assume I’ll need to keep the 5V lines separate for each bundle as well? Or is it mostly the data line that suffers from total line weight? There are only the 2 5V lines on the pi itself - what did you do for powering your 3 separate one-wires?

I can augment with wireless if needed - I got pointed at ESP8266 in another thread so I’m learning about that now too. I guess I’ll see how the pots attempt goes.

In the original post you said you managed 4 and 5 if you reduced the resistor. But now you’re down to only 3 per pin? Was it unreliable with 4? I.e. Devices got detected but didn’t function reliably longer term?

Exactly.
At first AI tried 4.7k resistors. It failed after adding fifth sensor. Then I replaced them with 2.2k. It was working bit then suddenly all sensors were offline, after restart some were offline, so in the end it wast a stable solution.
I’ve tried different approaches with the wiring. The GNG and VCC cables can be joined together, in theory the data cables too, but I attached each sensor to separate pin.
I think that in my case the problem was the cables length and other cables in the walls. Ethernet cables are near the electric cables.
I tried connecting GND to shielding, ane pable out of every pair, but that didn’t helped.
Maybe I did something wrong. I’m not an expert, but I spend many hours on that. I’ve even cut 20m cables to try everything in my room, but that wasn’t working stable.
There are 1wire hats for raspberry or ds2482 chip but I didn’t tried them.

Wemos D1 is less that 2$ on aliexpress.
In my case I use those cat5 cables to power the wemos (5v). I used espeasy firmware, but esphome is even easier and can be used from home assistant.

I still have 3 sensors on 1wire but they are very close to pi, but if I’ll need additional sensors I’m sure I’ll replace them with Wemos.
I can help you with setting things up, but I’m sure you’ll wind lots of info how to setup MQTT and use ESP8266 with it.

I do have excellent wifi coverage throughout my house so I’m not averse to using wifi devices.

So something like this or is there a better price that I missed?

Not sure why that’s cheaper than this?

And then I still use the DS18B20 but they are 1:1 connect to the D1s and their output gets pushed over the wifi via mqtt? Edit: Found a web page showing hooking up the temperature sensor to an 8266.

What do people do to pretty these up a little / protect them?

Ah, 30-50 day delivery estimate. aliexpress is in China? I might need to pay a bit more to get a set of them from amazon…

The first one is a clone, second is from LOLIN, the company that created those modules.
I used both in the past.
The delivery can take longer, but I ordered a couple of those devices and waited for about two weeks.
Not sure how the situation looks now.

What do people do to pretty these up a little / protect them?
I put them in an electrical box inside the wall and I used this:
image
image

This looks nice and has opening on the bottom to put the sensor.
If you have a 3d printer you can print a case for them. Something like this:
image
There are many ideas on https://www.thingiverse.com/

The best part is that you can use single Wemos board to connect multiple sensors, so if you have rooms or places that are nearby and have existing wiring you can use them.

If you will have a problem with setting things up please create a new thread and mention me. I’ll be more than happy to help with the setup :slight_smile:

I got 2 sensors per gpio working (star topology). 3 didn’t work. Since I have plenty of available gpio (I pulled 5 plus 3.3v/gnd out of the pi), I’m going to go with that for now and the 8266 boards only for the 1-2 rooms without an available wire.

What resistors did you use? Probably 4.7k (every tutorial recommends that :slight_smile: )
Try replacing them with 2.2k. This should help, maybe 3 will work per GPIO.
You need 3 wires per sensor. When using, for example, green as a data pin, consider connecting green-white to gnd on the raspberry site. This should help with the interference.

Sadly I’m not an expert, but maybe others might help with this.
I think that wire-based sensors are always better than WIFi based, but communication must be rock-solid!

Also, try reading this: https://www.maximintegrated.com/en/design/technical-documents/tutorials/1/148.html maybe you’ll find something useful.

Ah, I already started with using blue for power, blue/white for data and orange for ground and crimped 4 sensors in that arrangement. Not sure I want to start over since having half the sensors wired one way and the other half another would annoy me :).

RJ11pins are (looking at the socket and with cat5+ wiring colors):
G / OW / B / BW / O / GW
For simplest connection the sensor wires crimp easily to 3 adjacent RJ11 pins. And (depending on the sensor orientation) will be:
Gnd / Data / Vcc
or
Vcc / Data / Gnd.
Since I wasn’t sure if the sockets would have all 6 wires connected to the jacks, I decided to keep to the middle 4 pins. So I arbitrarily crimped the sensor to B/BW/O as Vcc/Data/Gnd. So to get Data and Gnd on a twisted pair of wires, I’d want to have crimped the sensor one wire further to the left, or crimped the sensor the other way up.

Now I’m wondering how much better it would be to have the data/gnd be a single twisted pair.

With the Pi you need to use 5V to power the one wire sensors but read with 3V3 reliability will be there. Sounds like a issue with power I had the same problem before. So keep the Vdd line at 5V but pull up data line with a 4.7K to 3V3 works for me

Thanks. I’d read about that but had yet to try it. What I’m scratching my head about now is that it was perfectly stable for a day… until I tried 3 sensors on one gpio. Now it isn’t even stable with just 2. And it seems but I haven’t fully confirmed that GPIO4 (the one I tried 3 sensors on) is markedly less able to handle the sensors - even a single sensor is sometimes not being found now.

Something like this?


I’ve tried that, sadly it didn’t work well with very long cables (20-30 meters).
I used 5V to power up DS18B20 and 4,7k or 2.2k resistors, but this didn’t work.
I ended up with ESP8266, but I’m very interested in what others used to solve similar problems.

Maybe this will help: https://www.raspberrypi.org/forums/viewtopic.php?t=64477
They suggested getting a 1-wire host, similar to this: http://www.sheepwalkelectronics.co.uk/product_info.php?products_id=73
I didn’t tried this, but maybe someone did.

Yes thats what I use for 5 sensors I think the farthest sensor is 60’ so about 18 meters. The 5V power with PullUP on 3V3

That’s a good read. At the very least I might throw out the 6 sensors I crimped already and flip the sensors the other way for the replacements - that’ll get the data/gnd on the blue twisted pair cables as suggested in that article. But my setup seems to be working reliably now but with only 2 sensors per pin since it’s a (2 leg) star layout still which is the worst possible wiring choice. I am going to re-test with 3 sensors now that I have a more reliable way of connecting them to the bread board, I think I was having some connectivity issues just from poor connections at the board. And if that doesn’t initially work, I’ll try halving the pull up resistor.

Oh wait, I hadn’t quite finished the thread:
‘If you must, you actually want to stay away from using the twisted pairs with the Data line at all. Twisted pair increases capacitance.’
Well that’s unfortunate. No easy way to get to the data line onto a twisted pair where the second isn’t used unless I start using the outside pins and I don’t know if all 6 wires have been consistently connected at the sockets - I’d have to check them to see. And if that statement is true then no point flipping the sensors over in their RJ12 jacks. Guess I’ll hold off on that.