arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
22.2k stars 4.81k forks source link

Wrong temperature calculation with a DS18S20 sensor at negative temperatures #8777

Closed tanoko closed 4 years ago

tanoko commented 4 years ago

PROBLEM DESCRIPTION

A clear and concise description of what the problem is. This problem was already addressed in issue #5375, which has been closed though user wecl wrote: 'But i didn't test the calculation when the temperature is lower than 0 degrees.'. I used a mix of sensors DS18S20 and DS18B20 to monitor temperatures in a refrigerator and observed strange zigzag shaped plots from DS18S20 sensor placed in the freezer (negative Centigrade). Checking the problem with different GPIO numbers and different modules (D1 mini, ESP-12F, ESP-3M) brought no difference. This behavior is illustrated on plots made with a DS18S20 and DS18B20 placed at the same point when crossing the 0°C mark: DS18S20 vs  DS18B20

Then I tried to analyze the code of the file xsns_05_ds18x20.ino and found out, that this part of the code must cause the problem: case DS18S20_CHIPID: { if (data[1] > 0x80) { data[0] = (~data[0]) +1; sign = -1; // App-Note fix possible sign error } float temp9 = (float)(data[0] >> 1) * sign; ds18x20_sensor[index].temperature = ConvertTemp((temp9 - 0.25) + ((16.0 - data[6]) / 16.0)); ds18x20_sensor[index].valid = SENSOR_MAX_MISS; return true; }

Instead of the unsigned variable temp9 I used a signed one, which I named tempS and replaced this part of the code by: case DS18S20_CHIPID: { int16_t tempS = (((data[1] << 8) | (data[0] & 0xFE)) << 3) | ((0x10 - data[6]) & 0x0F); ds18x20_sensor[index].temperature = ConvertTemp(tempS * 0.0625 - 0.250); ds18x20_sensor[index].valid = SENSOR_MAX_MISS; return true; }

The result you can see on these plots: DS18S20 vs  DS18B20_new

REQUESTED INFORMATION

Make sure your have performed every step and checked the applicable boxes before submitting your issue. Thank you!

- [ x ] If using rules, provide the output of this command: `Backlog Rule1; Rule2; Rule3`:
18:48:59 MQT: stat/tasmota/RESULT = {"Rule1":"ON","Once":"OFF","StopOnError":"OFF","Free":435,"Rules":"ON MCP230_OUT#OUT_D15 DO backlog sensor29 15,1; delay 1; sensor29 15,0 ENDON"}
18:48:59 MQT: stat/tasmota/RESULT = {"Rule2":"OFF","Once":"OFF","StopOnError":"OFF","Free":511,"Rules":""}
18:49:00 MQT: stat/tasmota/RESULT = {"Rule3":"OFF","Once":"OFF","StopOnError":"OFF","Free":511,"Rules":""}
  Rules output here:
18:50:44 RUL: MCP230_OUT#OUT_D15 performs "backlog sensor29 15,1; delay 1; sensor29 15,0"
18:50:44 MQT: stat/tasmota/RESULT = {"S29cmnd_D15":{"COMMAND":"ON","STATE":"ON"}}
18:50:44 MQT: stat/tasmota/RESULT = {"Delay":2}
18:50:45 MQT: stat/tasmota/RESULT = {"S29cmnd_D15":{"COMMAND":"OFF","STATE":"OFF"}}

``` has no relevance to discussed problem...
- [ ] Provide the output of this command: `Status 0`:

  STATUS 0 output here:
18:58:02 MQT: stat/tasmota/STATUS = {"Status":{"Module":0,"FriendlyName":["Tasmota-6215"],"Topic":"tasmota","ButtonTopic":"0","Power":0,"PowerOnState":3,"LedState":7,"LedMask":"FFFF","SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0}}
18:58:02 MQT: stat/tasmota/STATUS1 = {"StatusPRM":{"Baudrate":115200,"GroupTopic":"tasmotas","OtaUrl":"http://thehackbox.org/tasmota/release/tasmota.bin","RestartReason":"Power on","Uptime":"8T01:16:28","StartupUTC":"2020-06-16T15:41:34","Sleep":50,"CfgHolder":4617,"BootCount":103,"SaveCount":550,"SaveAddress":"F9000"}}
18:58:02 MQT: stat/tasmota/STATUS2 = {"StatusFWR":{"Version":"8.1.0(lite)","BuildDateTime":"2020-05-08T16:44:42","Boot":31,"Core":"2_6_1","SDK":"2.2.2-dev(38a443e)","Hardware":"ESP8285","CR":"366/699"}}
18:58:02 MQT: stat/tasmota/STATUS3 = {"StatusLOG":{"SerialLog":2,"WebLog":2,"MqttLog":0,"SysLog":0,"LogHost":"","LogPort":514,"SSId":["unknown",""],"TelePeriod":60,"Resolution":"D58180C0","SetOption":["00008009","2805C8000100060000005A00000000000000","00000000","00000000"]}}
18:58:02 MQT: stat/tasmota/STATUS4 = {"StatusMEM":{"ProgramSize":483,"Free":520,"Heap":26,"ProgramFlashSize":1024,"FlashSize":1024,"FlashChipId":"144051","FlashMode":3,"Features":["00000809","8F282185","040013A0","00008441","010000F1","00000010"],"Drivers":"1,2,9,10,13","Sensors":"1,2,5,9,12,29,54"}}
18:58:02 MQT: stat/tasmota/STATUS5 = {"StatusNET":{"Hostname":"tasmota-6215","IPAddress":"192.168.111.109","Gateway":"192.168.111.11","Subnetmask":"255.255.255.0","DNSServer":"192.168.111.11","Mac":"84:0D:8E:72:78:47","Webserver":2,"WifiConfig":4}}
18:58:02 MQT: stat/tasmota/STATUS6 = {"StatusMQT":{"MqttHost":"192.168.111.168","MqttPort":1883,"MqttClientMask":"DVES_%06X","MqttClient":"DVES_727847","MqttUser":"DVES_USER","MqttCount":2,"MAX_PACKET_SIZE":1000,"KEEPALIVE":30}}
18:58:02 MQT: stat/tasmota/STATUS7 = {"StatusTIM":{"UTC":"Wed Jun 24 16:58:02 2020","Local":"Wed Jun 24 18:58:02 2020","StartDST":"Sun Mar 29 02:00:00 2020","EndDST":"Sun Oct 25 03:00:00 2020","Timezone":99,"Sunrise":"04:54","Sunset":"20:58"}}
18:58:02 MQT: stat/tasmota/STATUS10 = {"StatusSNS":{"Time":"2020-06-24T18:58:02","DS18S20-1":{"Id":"0008035561F0","Temperature":2.938},"DS18S20-2":{"Id":"000803556EC3","Temperature":4.437},"DS18S20-3":{"Id":"00080355AC44","Temperature":5.562},"DS18S20-4":{"Id":"000803619FA0","Temperature":44.813},"DS18S20-5":{"Id":"000803629DBA","Temperature":23.563},"DS18S20-6":{"Id":"00080362F981","Temperature":4.000},"DS18B20-7":{"Id":"0114553E57AA","Temperature":-2.188},"DS18B20-8":{"Id":"01145546B2AA","Temperature":2.438},"DS18B20-9":{"Id":"01145577E5AA","Temperature":1.875},"DS18B20-10":{"Id":"011455811CAA","Temperature":-16.250},"DS18B20-11":{"Id":"01145587CDAA","Temperature":-19.500},"ADS1115":{"A0":3134 ...
18:58:02 MQT: stat/tasmota/STATUS11 = {"StatusSTS":{"Time":"2020-06-24T18:58:02","Uptime":"8T01:16:28","UptimeSec":695788,"Heap":26,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":38,"MqttCount":2,"POWER":"OFF","Wifi":{"AP":1,"SSId":"unknown","BSSId":"14:CC:20:2F:A6:3E","Channel":7,"RSSI":54,"Signal":-73,"LinkCount":1,"Downtime":"0T00:00:06"}}}


### TO REPRODUCE
_Steps to reproduce the behavior:_
Check the readings of a DS18S20 at slow enough changes of temperature, when it's below 0°C and compare the readings with another sensor (e.g. DS18B20)

### EXPECTED BEHAVIOUR
_A clear and concise description of what you expected to happen._
I think, the attached plots explain it clear enough.

### SCREENSHOTS
_If applicable, add screenshots to help explain your problem._

### ADDITIONAL CONTEXT
_Add any other context about the problem here._
Sorry, when my code is not perfect, but I'm not a software developer...
N.B. I'm using the SW Version 8.1.0, but as I can see, this part of the code is still the same in the newest version.

**(Please, remember to close the issue when the problem has been addressed)**
tanoko commented 4 years ago

Recently, I repeated tests of the temperature sensor DS18S20 with Tasmota V. 8.3.1. Here the plot with the pre-compiled version of tasmota.bin: DS18S20 (8 3 1)

Then, I modified the file xsns_05_ds18x20.ino as described above and compiled the tasmota.bin using PlatformIO. The result may be seen on the plot below made under similar conditions as the first one: DS18S20 (8 3 1_mod )

Here the output of Status 2 on the console: 08:54:47 MQT: stat/tasmota_08DE86/STATUS2 = {"StatusFWR":{"Version":"8.3.1(tasmota)","BuildDateTime":"2020-07-03T10:58:41","Boot":31,"Core":"2_7_1","SDK":"2.2.2-dev(38a443e)","Hardware":"ESP8266EX","CR":"394/699"}}

ascillato2 commented 4 years ago

Cool, Thanks for sharing. Please help us and provide a PR. Thanks.