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

    Onewire Temp Sensor Does Not Work on latest 1.20.2.r6 Firmware

    Scheduled Pinned Locked Moved Issues & Bugs
    3 Posts 2 Posters 45 Views 2 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

      Hi

      I've been using the Onewire DS18X20 temp sensor driver provided by @robert-hh for a while now, always running firmware 1.20.2.rc6, no problems at all. Just recently upgraded to 1.20.2.r6, the latest revision, and the temp sensor readings return None after the first initial reading.

      I am running this very simple main.py:

      import time
      from machine import Pin
      from ds18x20 import DS18X20
      from onewire import OneWire
      
      #DS18B20 data line connected to pin P10
      ow = OneWire(Pin('P22'))
      temp = DS18X20(ow)
      roms = temp.scan()
      
      temp.convert_temp()
      while True:
          time.sleep(1)
          for rom in roms:
              print(temp.read_temp(rom), end=" ")
          print()
          temp.convert_temp()
      

      And I am using the onewire.py and ds18x20.py libraries provided here: https://github.com/robert-hh/Onewire_DS18X20. These are the ones I have always used, because the Pycom-provided libraries had a bug in temperature conversion.

      The problem is, if I remove the print() statements in the while loop, the conversions are executed correctly. For example, if I modify the above loop to save the conversions to a list, instead of printing them:

      temp.convert_temp()
      ans = []
      while True:
          time.sleep(1)
          for rom in roms:
              ans.append(temp.read_temp(rom))
          temp.convert_temp()
          #print(ans)
      

      And I later probe the value of ans by stopping the loop and writing ans in the REPL, I get:

      >>> ans
      [22.5, 22.5, 22.5, 22.5, 22.5625, 22.5625, 22.5625, 22.5625]
      

      If instead I uncomment the print(ans) line in the above code, I get:

      [22.5]
      [22.5, None]
      [22.5, None, None]
      [22.5, None, None, None]
      [22.5, None, None, None, None]
      [22.5, None, None, None, None, None]
      

      So every other conversion aside from the first one is incorrect, because of an AssertionError: CRC error (I noticed this by raising the exception in the read_temp() method of the ds18x20 class).

      This does not happen on my past firmware, 1.20.2.rc6. I am using a LoPy4.

      Any ideas, anyone? This seems very odd, why should the print statement affect the communication with the DS18X20 sensor? If it were a timing issue, I'd understand a print would affect if executed in time-critical parts, but this print is called after the temperature has already been read.

      There is, however, one very interesting addition: If I change the print statement to print("foo"), the conversion works again. It only fails when the print is related to ans (the temp conversions list).

      By this point, I am already very frustrated and this seems metaphysical. Someone, please tell me if I am crazy. Thanks.

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

        Hey, @robert-hh, any chance you could try to reproduce this, just to see if it's just an issue on my side?

        robert-hhR 1 Reply Last reply Reply Quote 0
        • robert-hhR Offline
          robert-hh @d.alvrzx
          last edited by

          @d-alvrzx I'v tested that, and it seems to work fine. Sometimes the conversion fails. But that's to be expected. The timing seems acceptable.

          The print problem you talk about indicates a memory corruption somewhere else in the code. Try to switch of WiFi and Bluetooth.

          P.S.: It took me a while and a handful of curses to compile the firmware. Quite a few compile errors and warnings. At least one of them shows a bug. I do not know if people at Pycom verify, that the code the publish builds at least. It seems that no.

          1 Reply Last reply Reply Quote 1

          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