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

    How to distinguish sensors?

    Scheduled Pinned Locked Moved WiPy 2&3
    lopywipysensor
    6 Posts 2 Posters 431 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.
    • W Offline
      Wolli01
      last edited by

      What are the possibilities to distinguish between different sensors?
      I have 3 different sensors BME280 SHT21 and SHT31.
      How can I find out which sensor is connected to the Wipy/Lopy?
      Is that even possible?
      Who can help me?

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

        @Wolli01 The must have different I2C addresses. If a sensor is responding, it is present (BME280: 0x76, SHT21: 0x40, SHT31: 0x44).

        W 2 Replies Last reply Reply Quote 1
        • W Offline
          Wolli01 @robert-hh
          last edited by

          @robert-hh said in How to distinguish sensors?:

          The must have different I2C addresses. If a sensor is responding, it is present (BME280: 0x76, SHT21: 0x40, SHT31: 0x44).

          Thanks for the info. How can you ask for something like this before?
          Is there a code snippet somewhere?

          1 Reply Last reply Reply Quote 0
          • W Offline
            Wolli01 @robert-hh
            last edited by

            @robert-hh
            I'm so busy now. Are the I2C addresses always the same or is this solution not advisable?

            i2c = I2C(0, I2C.MASTER)
            print(i2c.scan())
            if i2c.scan() == [68]:
            	Sensorwahl = 'sht31' #Vorgabe welcher Sensor verwendet werden soll
            if i2c.scan() == [64]:
            	Sensorwahl = 'sht20_21' #Vorgabe welcher Sensor verwendet werden soll
            
            robert-hhR 1 Reply Last reply Reply Quote 0
            • robert-hhR Offline
              robert-hh @Wolli01
              last edited by

              @Wolli01 You may change I2C addresses by wiring at the module. Besides that, they are constant. But the code should better be:

              i2c = I2C(0, I2C.MASTER)
              device_list = i2c.scan()
              print(device_list)
              if 68 in device_list:
              	Sensorwahl = 'sht31' #Vorgabe welcher Sensor verwendet werden soll
              if 64 in device_list:
              	Sensorwahl = 'sht20_21' #Vorgabe welcher Sensor verwendet werden soll
              

              Reason: i2c.scan() may return more than one entry, if more than one device is connected.

              W 1 Reply Last reply Reply Quote 0
              • W Offline
                Wolli01 @robert-hh
                last edited by

                @robert-hh Thank You!

                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