# DS18B20 smoothing and PID tuning

**URL:** <https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015>\
**Category:** General\
**Created:** [22 June 2018 22:57 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015 "2018-06-22T22:57:42Z")\
**Posts on this page:** 20\
**Page:** 5

<div class="post-metadata">

**Author:** ![Backup](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/backup/32/862_2.png) [@Backup](https://discourse.nodered.org/u/Backup)\
**Post date:** [30 June 2018 14:56 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/81 "2018-06-30T14:56:54Z")

</div>

I was working on a flow that would save my data to a file last night. I ran into an error that wouldn’t go away, no matter what I did so I rebooted Raspberry Pi and it fixed my problem. I wonder if the -infinity% problem might have been something similar?

I can restore the original pid.js and try again if you think it might work.  
Charles

---

<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:** [30 June 2018 14:58 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/82 "2018-06-30T14:58:40Z")

</div>

> [@Backup](#):
>
> As you can see I’m getting output=0 from the PID now.

I notice the value has disappeared from the pid status too. Can you send me the old pid.js file please? You can private email me: gt at clanlaw dot org dot uk since the forum won't allow .js files as attachments it seems.

---

<div class="post-metadata">

**Author:** ![Backup](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/backup/32/862_2.png) [@Backup](https://discourse.nodered.org/u/Backup)\
**Post date:** [30 June 2018 14:58 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/83 "2018-06-30T14:58:58Z")

</div>

Come to think of it, my profile pic does look like i’m smirking. hmmmm, didn’t mean to do that.

---

<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:** [30 June 2018 15:00 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/84 "2018-06-30T15:00:23Z")

</div>

And yes, restore the old file too and see what happens.

---

<div class="post-metadata">

**Author:** ![Backup](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/backup/32/862_2.png) [@Backup](https://discourse.nodered.org/u/Backup)\
**Post date:** [30 June 2018 15:12 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/85 "2018-06-30T15:12:15Z")

</div>

Old file restored. I don't see any change but curiously, no output either. (?)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/b721569b8d7a386aa27b1cf068b0026cca2aac97.png)

---

<div class="post-metadata">

**Author:** ![Backup](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/backup/32/862_2.png) [@Backup](https://discourse.nodered.org/u/Backup)\
**Post date:** [30 June 2018 15:13 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/86 "2018-06-30T15:13:36Z")

</div>

I also rebooted my pi3 again.

---

<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:** [30 June 2018 15:23 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/87 "2018-06-30T15:23:19Z")

</div>

> [@Backup](#):
>
> Old file restored. I don’t see any change but curiously, no output either.

The file looks fine. It does look as if something was horribly confused and the reboot fixed it. Very odd.

By no output do you mean payload of 0? When the pv is high (as it is) the output will be low or zero as the algorithm assumes a process where power increases the setpoint (as in a heating system). So when the process is above setpoint the power is low. When used in a cooling loop the bit following that needs to be set such that 0 generates full cool and 1 generates no cool. When you have the heat/cool splitter node that does that for you so each output is 0 for off, 1 for on. To get it working in heat only mode you can either set (or clear) the Invert checkbox in the Timeprop node (if you are using mine) or if you want to leave that the same then insert a Scale node set to scale 0 to 1 and1 to 0.

---

<div class="post-metadata">

**Author:** ![Backup](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/backup/32/862_2.png) [@Backup](https://discourse.nodered.org/u/Backup)\
**Post date:** [30 June 2018 15:28 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/88 "2018-06-30T15:28:37Z")

</div>

Should I restore the split heat/cool and see what happens?

---

<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:** [30 June 2018 15:30 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/89 "2018-06-30T15:30:24Z")

</div>

Just noticed you have somehow got the Max Sample Interval setting in the node at zero. That is not valid as it means you expect the max time between process values to be zero. Set it to something larger than the normal interval (I usually have mine at 5 mins). The purpose of this is that if that long elapses between samples then it knows there is something wrong and locks the integral calculations to prevent the error condition winding the integral up to one end. With it at zero the integral will be permanently locked.

---

<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:** [30 June 2018 15:32 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/90 "2018-06-30T15:32:57Z")

</div>

> [@Backup](#):
>
> Should I restore the split heat/cool and see what happens?

I think you can get on with trying to tune just the cool loop first, which if can remember that far back was what the idea was when it all went banana shaped (to use a politically correct metaphor).

---

<div class="post-metadata">

**Author:** ![Backup](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/backup/32/862_2.png) [@Backup](https://discourse.nodered.org/u/Backup)\
**Post date:** [30 June 2018 15:39 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/91 "2018-06-30T15:39:21Z")

</div>

hahaha! I haven’t heard that one before but I know exactly what you mean.  
I reset all the process parameters and am watching it work as expected. ugh, why didn’t I remember the reboot thing. I’m an old Windows 3.0 user and that should have been the first thing I thought of (The big red switch-fix). In the early days of visual basic (v1.0) a persistent error that defied logic could often be fixed by a reboot.

Thanks for all the help. I learned a lot and hope I didn’t waste to much of your time.

Charles

---

<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:** [30 June 2018 15:41 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/92 "2018-06-30T15:41:50Z")

</div>

> [@Backup](#):
>
> a persistent error that defied logic could often be fixed by a reboot.

Fortunately that is much less common a situation on Linux.

---

<div class="post-metadata">

**Author:** ![Backup](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/backup/32/862_2.png) [@Backup](https://discourse.nodered.org/u/Backup)\
**Post date:** [30 June 2018 15:56 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/93 "2018-06-30T15:56:59Z")

</div>

I’m restoring my PID flow and noticed that when I disable the PID my cool status out of the “Split heat/cool” node remains at 1. Is there a way to disable PID so both outputs of the spliter are 0?

---

<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:** [30 June 2018 16:09 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/94 "2018-06-30T16:09:54Z")

</div>

When you disable it, it goes to the “Output when power disabled” value, so if you set that 0.5 then both should be off.

---

<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:** [30 June 2018 16:36 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/95 "2018-06-30T16:36:42Z")

</div>

node.status is the only thing that should set the status (or maybe this.status if you use it that way.)

---

<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:** [30 June 2018 16:41 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/96 "2018-06-30T16:41:48Z")

</div>

> [@dceejay](#):
>
> node.status is the only thing that should set the status (or maybe this.status if you use it that way.)

OK, thanks, that what I thought. It seems that it has stopped doing it and the node is behaving correctly following a reboot - very strange.

---

<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:** [30 June 2018 16:44 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/97 "2018-06-30T16:44:07Z")

</div>

@backup - that copyright statement is for the contrib one (from Ben) - not the one we released… (node-red-node-pidcontrol). As Nick pointed out Ben wrote it when he as at IBM - but as his own (contrib) work - not part of the core code /node set - so was never transferred to JS foundation and indeed the copyright would still be with IBM.

---

<div class="post-metadata">

**Author:** ![gmag11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gmag11/32/477_2.png) [@gmag11](https://discourse.nodered.org/u/gmag11)\
**Post date:** [3 July 2018 17:53 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/98 "2018-07-03T17:53:47Z")

</div>

As of my own experience with this kind of sensors, I prefer median function better than mean. With a depth of only 10 samples you can get good smoothing without spikes.  
It get last readings, order them and select central value.

---

<div class="post-metadata">

**Author:** ![Backup](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/backup/32/862_2.png) [@Backup](https://discourse.nodered.org/u/Backup)\
**Post date:** [3 July 2018 18:07 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/99 "2018-07-03T18:07:58Z")

</div>

Hi gmag11!  
The smoother I wrote was just an average of 10 samples. How do you get a median? Do you have some sample code?

Charles

---

<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 July 2018 18:26 UTC](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015/100 "2018-07-03T18:26:02Z")

</div>

FYI The node-red-node-smooth node will do a moving average over the last x readings

[Previous page](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015.md?page=4)

[Next page](https://discourse.nodered.org/t/ds18b20-smoothing-and-pid-tuning/1015.md?page=6)
