milesburton / Arduino-Temperature-Control-Library

Arduino Temperature Library

Home Page:https://www.milesburton.com/w/index.php/Dallas_Temperature_Control_Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Intermittent very high readings

jaggzh opened this issue · comments

For some years my thermostat reads very high readings.
It should be nice and clean like this:
image

(it was working for a year or so, but eventually it started failing, and even switching the esp's and ds18b20's out didn't fix it). Then it started doing things like this:
image

This was all when requesting temperatures only every 2 minutes.

Now I've switched to taking multiple samples and the median value, but every 1s (that might be a problem if it can take 750ms, but I'm not sure). I am using gnd, vcc, and the data line. I'm using it on an esp8266 (d1 mini), on pin 0 (which is apparently D3). Most recent version:
https://www.flickr.com/photos/32284628@N05/51462507855/sizes/l/

Note that I don't believe I've ever seen a -127 in this -- only those high values.

Thanks. :)

[Edit] Actually, I'm not 100% sure I swapped out the esp/d1 mini. I'm not sure if that could be a problem. Another thing: I think it tends to happen when the fan is turned on. The ds18b20 is connected with short (3 or 4") female->male leads (jumper wires), with a 4.7k pullup from data to vcc, which are inserted into a female header on the d1 mini.

I assume your code, the sensor and the library are all OK. You just have too many good readings

Sudden high values can come from a flipping bit, e.g.
if the raw T reads 0x0100 temperature = 256 * 1/16C = 16.0000 °C
if the LSB flips the raw T is read as 0x0101 => temperature = 257 * 1/16 = 16.0625 °C ==> hardly notice
if the MSB flips the raw T is read as 0x8100 => temperature = 2064 °C
Any other bit gives other unwanted offsets.

Reasons why bits can flip are different, to name a few

  1. interference of the fan motor ==> does problem happen when the fan is on/off/both?
  2. the voltage level can be too low ==> change the pull up resistor to 2K2 or better to 1K
  3. loose wires, bad soldering but I assume you checked those.
  4. ..

Depending on the number of faulty reads after one another (bursts) and the window size of your median filter,
faulty reads can still enter your system.
You might check out my https://www.arduino.cc/reference/en/libraries/runningmedian/ class which is faster than just taking median of N samples as it sorts efficiently.

Another, possibly simpler solution is to wrap the reading of the temperature with a filter.
If the temperature read differs more than X degrees from the last one, skip or retry. (X is the max delta expected x 2)

Skip gives a hole in the readings (replace by last value might be a strategy)
Retry costs time so, do you need 12 bit resolution for every measurement?
Taking 4 samples at 9 bits is faster and you can average them, providing:

  • possibly enough resolution, and
  • the option to apply the retry strategy mentioned above.