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

    DS18B20 temperature sensor

    Scheduled Pinned Locked Moved LoPy
    36 Posts 16 Posters 24.0k Views 15 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.
    • G Offline
      Guizmolux @dchappel
      last edited by

      @dchappel
      I'm very new to this (and LoPy and python) : where is your lib directory ?(I'll adapt to my own config).

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

        @Guizmolux
        I do not know if you ask for this
        but fully working examlpe code you can find in official docs
        https://docs.pycom.io/pycom_esp32/pycom_esp32/tutorial/includes/onewire.html

        think about people first, then computers

        G 1 Reply Last reply Reply Quote 0
        • G Offline
          Guizmolux @livius
          last edited by

          @livius
          I get that. Copied the code into a onewire.py file. Where should I put it?
          I've tried to execute before the main.py file and I always get the "cannot import name OneWire" or "DS18X20".
          is the const() a problem in class OneWire ?

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

            @Guizmolux

            but do you have upgraded firmware?
            current is 1.6.12.b1
            what is yours? you can check firmware version by

            os.uname()
            

            if it is really old then go to
            https://www.pycom.io/resources/

            next, is this how your onewire looks like?
            https://github.com/pycom/pycom-libraries/blob/master/lib/onewire/onewire.py

            put it in the same place where you have main.py or in lib subfolder

            and then you can simply use it

            import time
            from machine import Pin
            from onewire import DS18X20
            from onewire import OneWire
            
            #DS18B20 data line connected to pin P10
            ow = OneWire(Pin('P10'))
            temp = DS18X20(ow)
            
            while True:
                print(temp.read_temp_async())
                time.sleep(1)
                temp.start_convertion()
                time.sleep(1)
            

            think about people first, then computers

            G sorenS 2 Replies Last reply Reply Quote 0
            • G Offline
              Guizmolux @livius
              last edited by

              @livius
              it didn't seem to work with Pymakr. The Atom IDE with Pymakr pluggin solution that was updated as a tutorial last week definitely helped.
              It seems to be good now.
              Thank you!

              1 Reply Last reply Reply Quote 0
              • sorenS Offline
                soren @livius
                last edited by soren

                @livius said in DS18B20 temperature sensor:

                https://github.com/pycom/pycom-libraries/blob/master/lib/onewire/onewire.py

                When I do exactly as you state here, and connect the temperature sensor to 3.3v, and with the 4,7k resistor between sig and 3.3v - I get this error:

                File "main.py", line 22, in <module>
                File "/flash/lib/onewire.py", line 190, in read_temp_async
                IndexError: list index out of range

                I have latest firmware and atom plugin

                EDIT: after checking that I have latest onewire from here https://github.com/pycom/pycom-libraries/blob/master/lib/onewire/onewire.py this error was gone. I then had to correct your spelling mistake in "convertion" and now it's working, but despite everything being hooked up correctly - it prints out "None"...

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

                  @soren

                  1. what you got from (you must change P10 to pin you use):
                  ow = OneWire(Pin('P10'))
                  ow.roms
                  

                  if nothing then test(double ow)

                  ow.ow.scan()
                  
                  1. which sensor do you have exactly? woterproof or some different?

                  think about people first, then computers

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    jimpower @dchappel
                    last edited by

                    @dchappel I followed your main.py with both onewire.py and ds18x20.py in my lib, this works for the first temp reading, every following temp reading doesn't change from the first. I moved the sensor into the fridge and then freezer and the readings styed the same. Once I reset the device it will bring the new reading but only again for the first reading. Did you find this with yours?

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

                      @jimpower
                      better look here
                      https://github.com/pycom/pycom-libraries/tree/master/examples/DS18X20

                      think about people first, then computers

                      J 1 Reply Last reply Reply Quote 1
                      • J Offline
                        jimpower @livius
                        last edited by

                        @livius thanks that did the trick

                        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
                        • 2
                        • 2 / 2
                        • First post
                          Last post

                        Pycom on Twitter

                        Pycom