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

    Lopy4 onewire has SyntaxError

    Scheduled Pinned Locked Moved LoPy
    lopy4 onewire
    4 Posts 3 Posters 256 Views 4 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
      Dylan
      last edited by

      Hello,

      I am running on the latest firmware "1.18.2.r5" with the pysense board. I am using a DS18B20 temperature sensor connected to Pin 10. The code will work for awhile but eventually had this error:

      Traceback (most recent call last):
      File "main.py", line 15, in <module>
      File "onewire.py", line 215
      SyntaxError: invalid syntax

      Line 15 in main.py:

      from onewire import DS18X20
      

      Line 215 in onewire.py:

      temp_msb = data[1]
      

      Any idea what could be causing this? I am using all the libraries supplied by Pycom for DS18X20 and onewire

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jcaron @Dylan
        last edited by

        @Dylan have you checked that the onewire.py file has been correctly uploaded? Maybe try to re-upload it.

        Also check that you don’t have any files with the same name lying around which could cause confusion.

        1 Reply Last reply Reply Quote 0
        • D Offline
          Dylan
          last edited by

          I've uploaded a few times, uploads with no errors. I've got a work around by doing:

          def get_temp():
              temp_value = None
              count = 0
              while temp_value == None:
                  try:
                      count = count + 1
                      print(temp_value)
                      temp2.start_conversion()
                      time.sleep(1)
                      temp_value = temp2.read_temp_async()
                      time.sleep(1)
                      if count == 2:
                          machine.reset()
                  except SyntaxError:
                      print("\n")
                      print("\n")
                      print("\n")
                      print("\n")
                      print("syntax error")
                      print("\n")
                      print("\n")
                      print("\n")
          
                      time.sleep(0.5)
                      machine.reset()
              return(temp_value)
          

          I know machine.reset() is probably not the best approach but it's the simplest that I know :P

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

            @Dylan I just tried that code, and it works. Do you have a 4.7 kOhm Pull-up resistor between Vdd and Data of the DS18B20?

            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