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

    SHT20 i2c sensor

    Scheduled Pinned Locked Moved LoPy
    4 Posts 2 Posters 49 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.
    • S Offline
      Sudosu132
      last edited by

      My code looks like this

      from machine import I2C
      import array
      import time
      import binascii
      
      #Init bus
      i2c = I2C(0, I2C.MASTER,  baudrate=100000)
      
      #SHT20 Temperature command (use no hold master only commands --> 0xF3 )
      command = array.array('B', [0xF3])
      result = array.array('B',  [0, 0, 0])
      
      print(i2c.writeto(0x40, command))
      time.sleep(0.1)
      result = binascii.hexlify(i2c.readfrom(0x40, 3))
      print(result)
      

      it prints values like this : b'6f40f1'
      how do I get it to print temperature decimal?

      robert-hhR 2 Replies Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @Sudosu132
        last edited by robert-hh

        @Sudosu132 The first two bytes are the temp return value. You can make that a decimal number with:

        T = result[0] * 256 + result[1]

        In you example, that should give 28480. That value then goes into the formulat from the data sheet:

        temp = -46.85 + 175.72 * (T / 65538.0)

        Resulting in about 29.5 °C.

        Edit: The third byte from result is the checksum.

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

          @Sudosu132 You could try to use my Si7021 module. It looks as if it could work. The commands and formula are pretty much the same.
          https://github.com/robert-hh/SI7021
          Edit: Just tried it with an SHT21. Works fine.

          1 Reply Last reply Reply Quote 0
          • S Offline
            Sudosu132 @robert-hh
            last edited by

            @robert-hh
            Thank you so much! Works well

            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