DavidAntliff / esp32-ds18b20

ESP32-compatible C library for Maxim Integrated DS18B20 Programmable Resolution 1-Wire Digital Thermometer.
MIT License
100 stars 32 forks source link

Temperature reading is too high #6

Closed gbetsan closed 5 years ago

gbetsan commented 5 years ago

Hello, I have issue with all of my DS12B20 sensors: they all are about 5 degrees too high: I get 28-30 as my room temperature. I am sure that all wiring is done correct, I have tested it with sensors from 2 different sources. TO-92 is soldered directly to male header on PCB carefully at low temperature using tweezers as a heatsink to prevent it from overheating. Using sensor in solo mode.

Debug information: ds18b20: temp_LSB 0xbf, temp_MSB 0x01, temp 27.937500

Thank you for your help

DavidAntliff commented 5 years ago

Can I assume we are both talking degrees Celsius?

Are the sensors near anything producing heat on the PCB? Perhaps they are picking up heat from nearby components?

The calculation to determine the temperature from data read from the device is a simple bit shift on the combined 12-bit value. Are you using CRC mode to allow the driver to verify that the data is being received correctly? If so, then the temperature being reported is what the device is measuring.

The calculation is basically (MSB 256 + LSB) / 16, so that gives (0x01 256 + 0xbf) / 16 = 27.9375. Reducing the resolution from 12 to, say, 9 bit just zeros the least significant bits, so the calculation remains the same. See page 5 in the datasheet.

Can you try alternative software and see if you get the same result from your hardware?

Frankly I can't think of anything in the driver that would result in an approximate 5 degree difference in temperature, but if you can collect more data, and test your sensors with different software, or move them off the PCB temporarily, then maybe we'll have more info to work from.

EDIT: I should note that I did originally test the driver with water at various temperatures with an external thermometer, and the values seemed to be consistently within about a degree C across the 0 - 100 degree C range.

DavidAntliff commented 5 years ago

Is "DS12B20" a typo? Do you mean DS18B20?

gbetsan commented 5 years ago

Yes, Celsius

I have double checked that but I haven't reached even close to 20°C by letting the whole device to cool down, using new sensors without soldering it. Temperature fluctuations seems to be correct.

CRC is enabled as far as I remember.

Problem is really strange but I have heard other people reporting this https://forum.arduino.cc/index.php?topic=56307.0 I will test it more and report later, thank you.

DS12B20 is of course typo)

DavidAntliff commented 5 years ago

Yes, it does sound strange - how confident are you in your room temperature? Note that a typical room thermostat might be on the wall, which can be several degrees cooler (or warmer) than static air on a desk or bench. You need to be able to accurately measure the device temperature to get to the bottom of this problem.

What I'd do myself is connect one of your sensors via a 1 metre cable and then put it in a mix of ice and water (should be almost exactly 0 degrees C) - perhaps in a thin plastic wrap if it's not in a sealed case. If that shows a significant error then you can be sure there's an issue with hardware or software.

Then repeat with tap water at, say, 25C, with a third-party thermometer to verify.

Until you can be sure about the error, it will be difficult to figure out where it's coming from.

If you don't mind, I'll close this for now (feel free to keep commenting) and you can re-open it if you discover that there is a software fault. Obviously there's not much I can do about a hardware or temp measurement problem! :)

gbetsan commented 5 years ago

I am confident at 100%, I am not even comparing it to another thermometer, 5 degrees C is easily distinguishable by feeling: just can't be that in room with air conditioning it is 28C, while it feels no more than 22C

I will try this as well. Thank you for your help, I will dig deeper into this problem.

gbetsan commented 5 years ago

By the way, here is graph of temperature in last 3h/12h:

https://ibb.co/Lxcm99j https://ibb.co/tKsNJR5

Few times temperature has dropped to real value, EXACTLY 5 degrees below previous measurement

DavidAntliff commented 5 years ago

Not quite exactly 5 degrees but I see your point.

Are your devices legitimate? Are they genuine Maxim parts? Can you trace the supply line back to Maxim?

I'm at a loss to explain these glitches. What I can say is that my devices, which I bought through a retailer who guarantees genuine devices, do not show this behaviour.

Can you try one of these devices with an Arduino and see if the same thing happens?

BTW what's your supply voltage? Are you using active or parasitic power mode? Do you have enough capacitance on the power line to cope with the (small) current draw during temperature measurement?

DavidAntliff commented 5 years ago

I found a possible bug with 9 and 10 bit resolution - fix: https://github.com/DavidAntliff/esp32-ds18b20/commit/d624499a39b618359bf5d20b2066ea193c300d8e

Which resolution are you using?

That said I don't think any lingering bits in the 11th position would cause a 5 degree variation since that bit's value is only 0.125, so I doubt this change will fix your problem.

gbetsan commented 5 years ago

I am not 100% confident, but I have tried parts from 2 different suppliers and both of them has good feedbacks. I trust you) I will ASAP when I will get back home At programming and debugging, supply voltage is 3.3V from LDO with a few MLCCs regulated from 5V bus coming from USB-UART. ESP32 takes power from exact same 3.3V Bus (WROVER module). I can measure power supply ripple or drops, etc with an oscilloscope if will help. Data line has no pull-ups, but communication is fine. I am using 12 bit resolution, but I believe at was the same with 9 bits (haven't tried 10).

Attached photo of the board, where you can see all components (except for 2 extra MLCCs for 3V3 on the other side) IMG_20190710_112937

gbetsan commented 5 years ago

I can give you access to my code as well, I really can't tell why is it so... Power line is definitely in spec, according to datasheet... IMG_20190710_114546

DavidAntliff commented 5 years ago

Data line has no pull-ups, but communication is fine.

I'm a little confused by this sentence - are you saying you don't have a pull-up resistor on your OneWire bus data line? How many DS18B20 devices are you communicating with on a single bus?

gbetsan commented 5 years ago

As shown on photos, I communicate with only one DS18B20. Yes, I don't have pull-up resistor since I intended to use internal pull-up of ESP32. Is it a problem?

DavidAntliff commented 5 years ago

I'm not sure if it's a problem - the resistance needs to be around 4k7 ohms from memory, although values between about 2k - 10k seemed to work OK when I was testing things out originally. According to one of the ESP32 developers, Espressif use the estimated value of 50kohm for the internal pull-up value, which might be too high for the DS18B20 (and starve it of current). Can you try disabling the internal pull-up and temporarily install a 4k7 ohm resistor between data and VCC?

wrwetzel commented 1 year ago

I know that this is an old discussion but I recently had a similar problem with a simple resolution. I'm using a DS18B20 with an ESP8266 and a 4.7k terminating resistor. The DS18B20 is on a small proto board mounted above the ESP8266 development board. The DS18B20 was on the opposite side of the proto board from the ESP8266 and there was a lot of copper on the board. I was getting consistently higher readings of at least five degrees both indoors and outdoors.

It turns out that the error arose from heat from the ESP8266. I isolated the problem by blowing a fan over the assembly, which eliminated the error.

I resolved the problem by putting the ESP8266 into a deep sleep for five minutes, waking up to make the measurement, then returning to a deep sleep. Temp is now correct. There still may be some heat from the regulator and USB->serial converter but it is not a problem.