# Fastest OneWire (ds18b20) update rate on Raspberry Pi

**URL:** <https://discourse.nodered.org/t/fastest-onewire-ds18b20-update-rate-on-raspberry-pi/16520>\
**Category:** General\
**Created:** [9 October 2019 21:20 UTC](https://discourse.nodered.org/t/fastest-onewire-ds18b20-update-rate-on-raspberry-pi/16520 "2019-10-09T21:20:21Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [2 June 2020 22:09 UTC](https://discourse.nodered.org/t/fastest-onewire-ds18b20-update-rate-on-raspberry-pi/16520/21 "2020-06-02T22:09:15Z")

</div>

@meeki007 - have you also looked at [https://flows.nodered.org/node/node-red-contrib-sensor-ds18b20](https://flows.nodered.org/node/node-red-contrib-sensor-ds18b20) - how does that compare in terms of read speed ?

---

<div class="post-metadata">

**Author:** ![meeki007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/meeki007/32/12499_2.png) [@meeki007](https://discourse.nodered.org/u/meeki007)\
**Post date:** [3 June 2020 01:40 UTC](https://discourse.nodered.org/t/fastest-onewire-ds18b20-update-rate-on-raspberry-pi/16520/22 "2020-06-03T01:40:08Z")

</div>

Because the node is locked into GPIO4  
Quote from Documentation on the contrib.....  
"The DS18B20 sensors must be connected on GPIO4 (or physical pin #7) because this is the only pin that supports native 1-Wire protocol"

Well this is not true any more. I use any pin I want with

```auto
    dtoverlay=w1-gpio,gpiopin=x

```

So I never gave **[node-red-contrib-sensor-ds18b20](https://github.com/charlielito/node-red-contrib-sensor-ds18b20)** a look.

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [3 June 2020 04:26 UTC](https://discourse.nodered.org/t/fastest-onewire-ds18b20-update-rate-on-raspberry-pi/16520/23 "2020-06-03T04:26:29Z")

</div>

I doubt it will do well due to its synchronous code. So read spread will be high and it will block the event loop as well.

Consider this post:

> [@Quick note if you're a) reading multiple ds18b20's with a raspberry pi and b) struggling with flow stalls](https://discourse.nodered.org/t/quick-note-if-youre-a-reading-multiple-ds18b20s-with-a-raspberry-pi-and-b-struggling-with-flow-stalls/25747/3):
>
> I had a quick look at the source code of the contrib node: [https://github.com/bpmurray/node-red-contrib-ds18b20-sensor/blob/master/ds18b20-node/ds18b20-node.js](https://github.com/bpmurray/node-red-contrib-ds18b20-sensor/blob/master/ds18b20-node/ds18b20-node.js) They use synchronous file access to the sensors. This prevents the NodeJS event loop to process other tasks until the operation has finished. Depending on the sensor's resolution, the DS18B20 readings can take over a second per sensor. So the blocking behavior you described is to be expected. I see you have already found your way to usi…

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [3 June 2020 05:54 UTC](https://discourse.nodered.org/t/fastest-onewire-ds18b20-update-rate-on-raspberry-pi/16520/24 "2020-06-03T05:54:52Z")

</div>

That is a different node, hence why I was asking if the other suffered in the same way.

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [3 June 2020 05:56 UTC](https://discourse.nodered.org/t/fastest-onewire-ds18b20-update-rate-on-raspberry-pi/16520/25 "2020-06-03T05:56:46Z")

</div>

Ooops, sorry for that. I shouldn't post before I had my first cup of coffee. 🙈

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [3 June 2020 06:20 UTC](https://discourse.nodered.org/t/fastest-onewire-ds18b20-update-rate-on-raspberry-pi/16520/26 "2020-06-03T06:20:09Z")

</div>

That one uses the [https://www.npmjs.com/package/ds18b20](https://www.npmjs.com/package/ds18b20) library and makes proper use of callbacks. So it _should_ work better from that point of view.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [3 June 2020 07:59 UTC](https://discourse.nodered.org/t/fastest-onewire-ds18b20-update-rate-on-raspberry-pi/16520/27 "2020-06-03T07:59:14Z")

</div>

Another useful feature of owserver is that it can cache values, so if a value is requested multiple times (possibly by different clients) then it can provide the last value read rather than having to read the sensor again. I have mine set to timeout the cache at 15 seconds, which with DS18B20 is fine as nothing much happens in that timescale.

[Previous page](https://discourse.nodered.org/t/fastest-onewire-ds18b20-update-rate-on-raspberry-pi/16520.md?page=1)
