# Multiple DS18B20 Thermometers on Single OneWire Bus

**URL:** <https://forum.xod.io/t/multiple-ds18b20-thermometers-on-single-onewire-bus/4317>\
**Category:** Hardware Interfacing Questions\
**Created:** [August 18, 2020, 5:28pm UTC](https://forum.xod.io/t/multiple-ds18b20-thermometers-on-single-onewire-bus/4317 "2020-08-18T17:28:44Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![spuj](https://avatars.discourse-cdn.com/v4/letter/s/67e7ee/32.png) [@spuj](https://forum.xod.io/u/spuj)\
**Post date:** [August 18, 2020, 5:28pm UTC](https://forum.xod.io/t/multiple-ds18b20-thermometers-on-single-onewire-bus/4317/1 "2020-08-18T17:28:44Z")

</div>

Hi Folks

I’m new here and liking the look of XOD.

My project uses multiple DS18B20 sensors connected to a OneWire bus, each one addressable using it’s unique OneWire address.

I have seen the XOD node to read a single DS18B20 but haven’t found a nodes (or nodes) that support my use case. Does anyone know if this is possible?

Many thanks.

---

<div class="post-metadata">

**Author:** ![spuj](https://avatars.discourse-cdn.com/v4/letter/s/67e7ee/32.png) [@spuj](https://forum.xod.io/u/spuj)\
**Post date:** [September 6, 2020, 10:59pm UTC](https://forum.xod.io/t/multiple-ds18b20-thermometers-on-single-onewire-bus/4317/2 "2020-09-06T22:59:31Z")

</div>

Sorry for the bump. Just thought I’d try one more time to see if anyone has thoughts on this topic? Thanks for any guidance.

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [September 7, 2020, 12:06am UTC](https://forum.xod.io/t/multiple-ds18b20-thermometers-on-single-onewire-bus/4317/3 "2020-09-07T00:06:28Z")

</div>

If it is possible with Arduino IDE, it is probably possible in XOD. That does not mean it will be easy…

If you can find existing nodes or library for one wire communication, that would be a good starting point, but I don’t know that there are any. If it is a simple protocol, you could code it yourself. If it is more complicated and there is an existing IDE library for it, it might be easier to write a XOD wrapper for the library (information about this on the XOD document page, but it is not trivial).

---

<div class="post-metadata">

**Author:** ![spuj](https://avatars.discourse-cdn.com/v4/letter/s/67e7ee/32.png) [@spuj](https://forum.xod.io/u/spuj)\
**Post date:** [September 10, 2020, 9:38am UTC](https://forum.xod.io/t/multiple-ds18b20-thermometers-on-single-onewire-bus/4317/4 "2020-09-10T09:38:21Z")

</div>

Many thanks for your reply @gweimer . It certainly is possible in the Arduino IDE and there are libraries for it. There is the ‘OneWire’ library for the bus itself and the ‘DallasTemperature’ library for the DS18B20 thermometers.

I’m not yet familiar with XOD to understand how it would handle/represent multiple devices connected to a bus (connected to a single Arduino pin) or how to handle the instantiation of the bus itself. I’ll give it a go when I get some time though.

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [September 10, 2020, 1:18pm UTC](https://forum.xod.io/t/multiple-ds18b20-thermometers-on-single-onewire-bus/4317/5 "2020-09-10T13:18:35Z")

</div>

I would start with a project that can be built using existing nodes and libraries to get a feel for XOD before trying to dive in and write your own nodes. When you are ready, the built-in i2c nodes can give you an idea how to organize and configure communication nodes that address multiple devices on a bus.

---

<div class="post-metadata">

**Author:** ![wayland](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/wayland/32/1590_2.png) [@wayland](https://forum.xod.io/u/wayland)\
**Post date:** [September 11, 2020, 9:58pm UTC](https://forum.xod.io/t/multiple-ds18b20-thermometers-on-single-onewire-bus/4317/6 "2020-09-11T21:58:34Z")

</div>

@spuj, I’ve just published a library for working with multiple DS18B20 thermometers on a single 1-wire bus:  
[https://xod.io/libs/wayland/ds18b20/](https://xod.io/libs/wayland/ds18b20/)

I followed the wiring instructions in this guide:

> **[Interfacing Multiple DS18B20 Digital Temperature Sensors with Arduino](https://lastminuteengineers.com/multiple-ds18b20-arduino-tutorial/)**
>
> Learn 2 Methods(by Index & by Address) to Interface Multiple DS18B20 Digital Temperature Sensors On Single Bus along with its Wiring & Arduino Code

I have the waterproof version of the thermometers:  
 ![ds18b20](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/e/e0d5ccd8a0e8c0d170398010016258ee603842ac.jpeg)  
red = VDD  
black = ground  
yellow = signal

The first thing you need to do is determine the eight byte address of each of your thermometers. Connect just one of your thermometers and run the **example-read-address** patch in the debugger:  
 ![Screenshot 2020-09-11 at 18.01.15](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/3/30fff4af7d71db5525930bf70d31a52aa9d5c9a0.png)  
Make a note of the eight byte address of your thermometer. Repeat process for each of your other thermometers. I label my thermometers so that I can match them to their addresses.

Once you know the addresses of all of your thermometers you can connect them all in parallel. To check that you can get a temperature reading from all thermometers, use patch **example-read-temp-multi-devices** :

 ![Screenshot 2020-09-11 at 18.43.51](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/2/20a9e73feb52496d3cb7d55546360f5844e15314.png)  
The **ds18b20-bus** node represents the 1-wire bus connecting your thermometers. You can change the resolution of all thermometers on the bus using the **set-resolution** node. The **request-temperatures** node has to be pulsed before using the **get-temp-c** nodes to read each thermometer. You’ll obviously need a **get-temp-c** for each of your thermometers. **get-temp-c** output the temperature in degrees Celsius. If you prefer Fahrenheit you can use **get-temp-f**.

A note of caution: if any of the **get-temp-c** nodes output the value **85** , check your wiring (see discussion here: [https://www.raspberrypi.org/forums/viewtopic.php?t=63085](https://www.raspberrypi.org/forums/viewtopic.php?t=63085)). Initially I was using relatively heavy test leads in my circuit and I frequently got these erroneous **85** readings. After replacing the test leads with short dupont wires the dodgy readings disappeared. If a sensor becomes disconnected its **get-temp-c** will output **-127**.

---

<div class="post-metadata">

**Author:** ![m-b](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@m-b](https://forum.xod.io/u/m-b)\
**Post date:** [September 15, 2020, 4:40pm UTC](https://forum.xod.io/t/multiple-ds18b20-thermometers-on-single-onewire-bus/4317/7 "2020-09-15T16:40:09Z")

</div>

Hi @wayland

I saw that XOD 0.35.1 is availabel include the fix for ds18b20.  
If I upload those code ( **example-read-temp-multi-devices** ) to an UNO it works perfect, but if I tried to do that with an DUE and I can’t compile your example.

I get this error:

C:\Users\MDHL\AppData\Local\Temp\xod\_temp\_sketchbookl42hxR\xod\_1600187780038\_sketch\xod\_1600187780038\_sketch.ino: In instantiation of ‘void xod::wayland\_\_ds18b20\_\_set\_resolution::Node\<typeof\_DEV\>::evaluate(xod::wayland\_\_ds18b20\_\_set\_resolution::Node\<typeof\_DEV\>::Context) [with typeof\_DEV = DallasTemperature\*; xod::wayland\_\_ds18b20\_\_set\_resolution::Node\<typeof\_DEV\>::Context = xod::wayland\_\_ds18b20\_\_set\_resolution::Node\<DallasTemperature\*\>::ContextObject\*]’:  
C:\Users\MDHL\AppData\Local\Temp\xod\_temp\_sketchbookl42hxR\xod\_1600187780038\_sketch\xod\_1600187780038\_sketch.ino:2176:37: required from here  
C:\Users\MDHL\AppData\Local\Temp\xod\_temp\_sketchbookl42hxR\xod\_1600187780038\_sketch\xod\_1600187780038\_sketch.ino:1469:40: error: invalid conversion from ‘xod::identity\<DallasTemperature\*\>::type {aka DallasTemperature\*}’ to ‘uint8\_t {aka unsigned char}’ [-fpermissive]  
sensors-\>setResolution(getValue\<input\_DEV\>(ctx));  
^

In file included from C:\Users\MDHL\AppData\Local\Temp\xod\_temp\_sketchbookl42hxR\xod\_1600187780038\_sketch\xod\_1600187780038\_sketch.ino:1084:0:  
C:\Users\MDHL\AppData\Local\Temp\xod\_temp\_sketchbookl42hxR\libraries\Arduino\_Temperature\_Control\_Library/DallasTemperature.h:114:7: error: initializing argument 1 of ‘void DallasTemperature::setResolution(uint8\_t)’ [-fpermissive]  
void setResolution(uint8\_t);

---

<div class="post-metadata">

**Author:** ![wayland](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/wayland/32/1590_2.png) [@wayland](https://forum.xod.io/u/wayland)\
**Post date:** [September 15, 2020, 5:17pm UTC](https://forum.xod.io/t/multiple-ds18b20-thermometers-on-single-onewire-bus/4317/8 "2020-09-15T17:17:33Z")

</div>

Hi @m-b,

Thanks for letting me know about the problem. There was an error in my **set-resolution** node. It’s fortunate that you received an error message when compiling for the DUE, because I did my testing on the Uno and the bug slipped through undetected. I’ve just published an updated version (0.4) of the library in which the bug is fixed.

---

<div class="post-metadata">

**Author:** ![spuj](https://avatars.discourse-cdn.com/v4/letter/s/67e7ee/32.png) [@spuj](https://forum.xod.io/u/spuj)\
**Post date:** [September 16, 2020, 7:05am UTC](https://forum.xod.io/t/multiple-ds18b20-thermometers-on-single-onewire-bus/4317/9 "2020-09-16T07:05:40Z")

</div>

Many thanks @wayland this is just what I was looking for. I will give it a try later.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/1X/eb7348baa04192c2ef932d1db54d44f09f8a7888.png) [@system](https://forum.xod.io/u/system)\
**Post date:** [October 16, 2020, 7:05am UTC](https://forum.xod.io/t/multiple-ds18b20-thermometers-on-single-onewire-bus/4317/10 "2020-10-16T07:05:49Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
