Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Possible bug within Onewire library for DS18S20 temperature sensor

    Scheduled Pinned Locked Moved LoPy
    4 Posts 3 Posters 101 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D Offline
      d.alvrzx
      last edited by

      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, the onewire.py library 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.

      Best wishes,

      Dan

      [1] https://github.com/pycom/pycom-libraries/tree/master/examples/DS18X20
      [2] https://datasheets.maximintegrated.com/en/ds/DS18S20.pdf

      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @d.alvrzx
        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.

        1 Reply Last reply Reply Quote 2
        • A Offline
          andreas
          last edited by andreas

          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

          1 Reply Last reply Reply Quote 1
          • D Offline
            d.alvrzx
            last edited by

            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

            1 Reply Last reply Reply Quote 0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • 1 / 1
            • First post
              Last post

            Pycom on Twitter

            Pycom