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

    DSB1820 Onewire sensor on SiPy

    Scheduled Pinned Locked Moved SiPy
    sipypymakronewireds18b20
    18 Posts 3 Posters 5.4k 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.
    • B Offline
      bucknall @sk
      last edited by

      @sk where have you placed the ds18x20.py file? Normally I use this file structure for my library .py file (imports):

      • /flash
        • /lib
          • ds18x20.py
        - boot.py
        - main.py
        

      Developer Evangelist - Pycom

      S 1 Reply Last reply Reply Quote 0
      • S Offline
        sk @bucknall
        last edited by

        @bucknall
        How do I structure it that way. Currently when I open up a project I have all my py files in /flash i.e boot.py, main.py, ds18x20.py and my tempSensor.py are on the same folder.

        ![0_1487285028222_Capture4.PNG](Uploading 100%)

        1 Reply Last reply Reply Quote 0
        • B Offline
          bucknall @sk
          last edited by

          @sk is this from your main.py or your tempSensor.py?

          Developer Evangelist - Pycom

          S 1 Reply Last reply Reply Quote 0
          • S Offline
            sk @bucknall
            last edited by

            @bucknall im running from my tempsensor.py.

            B 1 Reply Last reply Reply Quote 0
            • B Offline
              bucknall @sk
              last edited by bucknall

              @sk Ok, when you import the module ds18x20 it should work fine if it's in the same folder as your tempSensor.py.

              If you open your REPL (either in Pymakr or another tool) and type the following commands, what is your output?

              import os
              os.listdir('/flash')
              

              This should show your the file structure of /flash

              Developer Evangelist - Pycom

              S 1 Reply Last reply Reply Quote 0
              • S Offline
                sk @bucknall
                last edited by

                @bucknall I did this in my tempsensor.py file:

                from machine import Pin
                #from ds18x20 import DS18X20
                import os
                os.listdir('/flash')
                #d=DS18X20(Pin('G17', mode=Pin.OUT))
                #result=d.read_temps()
                #print(result)
                

                Which gave this output:

                Running TempSensor.py
                >
                MicroPython v1.8.6-422-g516b861 on 2017-02-07; SiPy with ESP32
                Type "help()" for more information.
                >>>
                
                B 1 Reply Last reply Reply Quote 0
                • B Offline
                  bucknall @sk
                  last edited by

                  @sk I think you need to either wrap the code in a print statement to see an output

                  print(os.listdir('/flash'))
                  

                  or run it from the REPL to see the output

                  >>> import os
                  >>> os.listdir('/flash')
                  

                  Developer Evangelist - Pycom

                  S 1 Reply Last reply Reply Quote 0
                  • S Offline
                    sk @bucknall
                    last edited by

                    @bucknall

                    Running TempSensor.py
                    ['boot.py', 'sys', 'lib', 'cert', 'main.py', 'project.pymakr']
                    >
                    MicroPython v1.8.6-422-g516b861 on 2017-02-07; SiPy with ESP32
                    Type "help()" for more information.
                    >>> 
                    

                    So How can I add it to lib?

                    B 1 Reply Last reply Reply Quote 0
                    • B Offline
                      bucknall @sk
                      last edited by

                      @sk it looks like your ds18x20.py didn't upload to the SiPy. To use the sync function in Pymakr, to copy your code over to your SiPy, you need to first create a project.

                      Once you're got a new project, if you create a folder called 'lib' and place the ds18x20.py into this folder and then press sync, it should put it into the lib folder!

                      Developer Evangelist - Pycom

                      S 1 Reply Last reply Reply Quote 0
                      • S Offline
                        sk @bucknall
                        last edited by sk

                        @bucknall
                        Ok so I made a new project called 'TempSensor' and in the same folder of this project I made another folder called 'lib'.
                        Inside lib folder I pasted the ds18x20.py, onewire.py and onewire.diff libraries.
                        Then in the project folder I made boot.py:

                        from machine import UART
                        import os
                        import machine
                        uart = UART(0, 115200)
                        os.dupterm(uart)
                        

                        and main.py:

                        import os
                        import pycom
                        from machine import Pin
                        #from ds18x20 import DS18X20
                        print(os.listdir('/flash'))
                        pycom.rgbled(0x000000) # rblack
                        #d=DS18X20(Pin('G17', mode=Pin.OUT))
                        #result=d.read_temps()
                        #print(result)
                        machine.idle()
                        

                        Then I synced and then ran my program and this is the output:

                        Running main.py
                        ['__init__.py', 'sys', 'lib', 'cert', 'TempSensor.py', 'main.py', 'boot.py', 'project.pymakr']
                        >
                        MicroPython v1.8.6-422-g516b861 on 2017-02-07; SiPy with ESP32
                        Type "help()" for more information.
                        >>> 
                        

                        As you can see the library is still not there. But if I go

                        print(os.listdir('/flash/lib'))
                        

                        The output says its there:

                        Running main.py
                        ['ds18x20.py']
                        >
                        MicroPython v1.8.6-422-g516b861 on 2017-02-07; SiPy with ESP32
                        Type "help()" for more information.
                        >>> 
                        

                        Why doesn't it show the onewire.py/diff?

                        1 Reply Last reply Reply Quote 0
                        • S Offline
                          sk
                          last edited by

                          @bucknall
                          Ok all libraries seem to be in the right place now. My main.py:

                          import os
                          import pycom
                          from machine import Pin
                          from ds18x20 import DS18X20
                          
                          #pycom.rgbled(0x000000) # rblack
                          
                          d=DS18X20(Pin('G17', mode=Pin.OUT))
                          result=d.read_temps()
                          print(result)
                          machine.idle()
                          

                          My output however gives this error:

                          Syncing the project with the SiPy. Please wait...
                          Successfully synced!
                          
                          
                          MicroPython v1.8.6-422-g516b861 on 2017-02-07; SiPy with ESP32
                          Type "help()" for more information.
                          >>> 
                          
                          Running main.py
                          Traceback (most recent call last):
                            File "<stdin>", line 8, in <module>
                            File "/flash/lib/ds18x20.py", line 47, in __init__
                            File "/flash/lib/onewire.py", line 246, in scan
                            File "/flash/lib/onewire.py", line 274, in _search
                            File "/flash/lib/onewire.py", line 148, in write_byte
                          NameError: name 'pin_lalue' is not defined
                          >
                          MicroPython v1.8.6-422-g516b861 on 2017-02-07; SiPy with ESP32
                          Type "help()" for more information.
                          >>> 
                          

                          "pin_lalue" isn't in any of my files or libraries? Why is it looking for something that doesn't exist?

                          1 Reply Last reply Reply Quote 0
                          • S Offline
                            sk
                            last edited by sk

                            I've also followed this pycom Onewire DS18X20 tutorial but the output is again looking for something that doesn't exist:

                            Running main.py
                            Traceback (most recent call last):
                              File "<stdin>", line 9, in <module>
                              File "/flash/lib/onewire.py", line 162, in __init__
                              File "/flash/lib/onewire.py", line 124, in scan
                              File "/flash/lib/onewire.py", line 132, in _search_rom
                              File "/flash/lib/onewire.py", line 36, in reset
                            NameError: name 'enabXe_irq' is not defined
                            >
                            MicroPython v1.8.6-422-g516b861 on 2017-02-07; SiPy with ESP32
                            Type "help()" for more information.
                            >>> 
                            

                            at line 36 in the onewire library it is enable_irq(1)... not enabXe_irq. Paymkr is replacing the 'l' with 'X'???

                            1 Reply Last reply Reply Quote 0
                            • L Offline
                              livius
                              last edited by livius

                              use official onewire driver
                              https://github.com/pycom/pycom-libraries/tree/master/examples/onewire
                              it work for me on Wipy2.0

                              but first check if your file is not corrupted
                              try compare it in text editor e.g Notepad++, Total Comander, WinMerge ...
                              i mean - read file e.g. throught ftp and compare with file you thing that should be stored
                              because i see in your error message corrupted name "enabXe_irq" which not exists in onewire driver

                              think about people first, then computers

                              S 1 Reply Last reply Reply Quote 0
                              • S Offline
                                sk @livius
                                last edited by

                                @livius

                                0_1487543077630_onewire.py
                                this doesnt have enableXe_irq, I don't think its the files thats faulty. Something is wrong with my code or the order I'm doing things, I'm pretty sure, I just don't know what?

                                L 1 Reply Last reply Reply Quote 0
                                • L Offline
                                  livius @sk
                                  last edited by livius

                                  @sk
                                  Is this what you downloaded from board or what you have on the computer?
                                  Previously (for me still - however less than before) there are some corruption of files stored on the board.

                                  try something like this

                                  f = open('onewire.py', 'r+')
                                  d = f.readall()
                                  print(d)
                                  

                                  do you see some corruption in content?

                                  Try also downloading file throught ftp - is this file same as your on the computer?

                                  think about people first, then computers

                                  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