Possible bug within Onewire library for DS18S20 temperature sensor
-
Hello everyone:
Before reporting this as a bug, I would like to get someone's input, because I may be wrong. I have been attempting to read the temperature on a DS18S20 with a LoPy4 for several hours now, and I had not been able because I was getting odd values. I should point out that I am using the exact code found in [1] to try this out. Instead of getting temperatures around room temperature (20 to 25 °C), I was getting values like 1.875 or 2.2, which did not make sense.
It was not until recently that I noticed that the datasheet for the DS18S20 sensor (see page 6 in [2]) states that the conversion formula for the temperature is
temperature = temp_read - 0.25 + (count_per_c - count_remain)/count_per_c
. However, theonewire.py
library incorrectly (I believe) subtractstemp_read - 25
, instead of0.25
. Is this wrong? Or am I just interpreting it incorrectly?When I manually make this change in the library, I get a more reasonable temperature of 26°C. Although this is still a bit high for the (relatively) cold room I am working in, but at the moment I unfortunately have no other means of checking if this is the correct temperature.
Best wishes,
Dan
[1] https://github.com/pycom/pycom-libraries/tree/master/examples/DS18X20
[2] https://datasheets.maximintegrated.com/en/ds/DS18S20.pdf
-
Thank you @andreas and @robert-hh for your prompt responses. It seems this problem had been solved several months ago by you guys, but unfortunately my google searches hadn't returned any results in that regard. Anyways, glad it's all cleared up. I'm now using Robert's library and it works perfectly.
Best regards,
Dan
-
Dear Dan,
apart from your question, I also would like to outline that we added C-Level support for 1-Wire from Genuine MicroPython the other day [1,2]. @robert-hh was so kind to adapt his driver [3] to have the same interface as the upstream drivers [4].
The benefits are that the timing might be more correct and the implementation is aligned to upstream.
With kind regards,
Andreas.[1] https://github.com/pycom/pycom-micropython-sigfox/pull/356
[2] https://forum.pycom.io/topic/5330/onewire-py-problem/22
[3] https://github.com/robert-hh/Onewire_DS18X20
[4] https://github.com/micropython/micropython/tree/master/drivers/onewire
-
@d-alvrzx You're right. That calculation is wrong. I have made a reshaped lib for that. You can find it here: https://github.com/robert-hh/Onewire_DS18X20
Edit: the temperature at the sensor can be affected by things close to it, like a laptop or even a PyXX device, or by breathing at it.