Possible bug within Onewire library for DS18S20 temperature sensor
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  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 ) states that the conversion formula for the temperature is
temperature = temp_read - 0.25 + (count_per_c - count_remain)/count_per_c. However, the
onewire.pylibrary incorrectly (I believe) subtracts
temp_read - 25, instead of
0.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.
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.
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  to have the same interface as the upstream drivers .
The benefits are that the timing might be more correct and the implementation is aligned to upstream.
With kind regards,
robert-hh last edited by robert-hh
@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.