tpyo kingg
Posts: 626
Joined: Mon Apr 09, 2018 5:26 pm
Location: N. Finland

Multiple DS18B20 data lines on one GPIO pin?

Wed May 15, 2019 3:38 am

Can I use multiple DS18B20 temperature sensors on the same pins? Specifically, can the data wires (DQ) for several sensors all be run to a single GPIO pin and share the pull-up resistor? The specifications mention a unique 64-bit address so that would imply it is possible to share the same one-wire bus. I suppose it makes no difference about shared GND and Vdd.

User avatar
omegaman477
Posts: 148
Joined: Tue Feb 28, 2017 1:13 pm
Location: Sydney, Australia

Re: Multiple DS18B20 data lines on one GPIO pin?

Wed May 15, 2019 3:49 am

Yes.

The DS18B20 is an I2C bus device, or 1-Wire. Yes, each DS18B20 has an internal unique address. Follow the datasheet examples for topology and pullup resistor.

The default I2C libraries for Raspbian support multiple I2C devices on the one bus/pin. The application suite I2C-tools provides valuable debugging and diagnostic tools. Python (as with most languages for Raspbian) has libraries for full I2C device specific support
..the only thing worse than a stupid question is a question not asked.

tpyo kingg
Posts: 626
Joined: Mon Apr 09, 2018 5:26 pm
Location: N. Finland

Re: Multiple DS18B20 data lines on one GPIO pin?

Wed May 15, 2019 3:52 am

Thanks. That will simplify things.

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

Re: Multiple DS18B20 data lines on one GPIO pin?

Wed May 15, 2019 4:11 am

omegaman477 wrote:
Wed May 15, 2019 3:49 am
Yes.

The DS18B20 is an I2C bus device, or 1-Wire.
1-Wire and I2C are entirely different buses.

The DS18B20 is a 1-wire device. You are correct that it is possible to run several of them on one bus. It is also possible to run multiple buses on the Pi.

dmagill4
Posts: 5
Joined: Wed May 15, 2019 12:25 pm

Re: Multiple DS18B20 data lines on one GPIO pin?

Wed May 15, 2019 12:45 pm

Just remember the DS18b20's are each given a unique somewhat random serial number during production. once you have 3 or 4 all hooked up there will be a folder for each one (by name -- name = serial number) under the W1_master folder on the system drive. IIRC the system will find them each time based on the serial number in alphabetical order -- so once you know which one is which, they should stay the same (until you introduce a new sensor)

tpyo kingg
Posts: 626
Joined: Mon Apr 09, 2018 5:26 pm
Location: N. Finland

Re: Multiple DS18B20 data lines on one GPIO pin?

Wed May 15, 2019 6:58 pm

Ok. Thanks. The order is not an issue as long as the folders don't change names. For example, I have these two on one machine now:

/sys/bus/w1/devices/28-00000a2a3d2e/w1_slave
/sys/bus/w1/devices/28-00000916ba9c/w1_slave

Can I presume that if I add a third, those two will remain as they are?

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

Re: Multiple DS18B20 data lines on one GPIO pin?

Wed May 15, 2019 7:46 pm

tpyo kingg wrote:
Wed May 15, 2019 6:58 pm
Can I presume that if I add a third, those two will remain as they are?
Yes. Those names are based on the serial numbers of the sensors and those will never change.

dmagill4
Posts: 5
Joined: Wed May 15, 2019 12:25 pm

Re: Multiple DS18B20 data lines on one GPIO pin?

Thu May 16, 2019 11:05 am

tpyo kingg wrote:
Wed May 15, 2019 6:58 pm
Ok. Thanks. The order is not an issue as long as the folders don't change names. For example, I have these two on one machine now:

/sys/bus/w1/devices/28-00000a2a3d2e/w1_slave
/sys/bus/w1/devices/28-00000916ba9c/w1_slave

Can I presume that if I add a third, those two will remain as they are?
Your Third may pop into any position (based on its serial #) - So if you are using code that finds them for you and returns something like Device[0] = 28-00000a2a3d2e and your new device has a lower serial number it will become device[0] and this one will be device[1]

it's just a matter of how you are calling the devices (spelled out like above) or having a subroutine find them and build an array.
As stated above folder 28-00000a2a3d2e/W1-slave will always equal that physical sensor

Return to “Other projects”