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

    Wer hat den Sensor SHT20 oder SHT21 erfolgreich an laufen?

    Scheduled Pinned Locked Moved LoPy
    lopyfipywipysensoric2
    4 Posts 2 Posters 382 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

      Ich versuche es noch mal in Deutsch, vielleicht habe ich es in einen anderen Post schlecht übersetzen lassen.
      Wer arbeitet mit den folgenden SHT20 SHT21 Sensoren und kann mir dabei mit einem Code Snippet helfen wie man sie in Dezimalzahlen auslesen kann. Oder wer kennt eine Seite wo Infos darüber stehen.
      Ich bin für jede Hilfe dankbar.
      Bis jetzt habe ich immer Hilfe bekommen, hoffe auch diesmal darauf.

      1 Reply Last reply Reply Quote 0
      • FridaF Offline
        Frida
        last edited by

        Probieren Sie diesen Ausschnitt aus.

        Es läuft auf der neuesten Version mit Erweiterungskarte v2.1a

        Pycom MicroPython 1.18.2.r4 [v1.8.6-849-ba178ae] am 2019-04-01; WiPy mit ESP32

        from machine import I2C
        #import array
        import time
        #import binascii
        import math
        
        #Init bus
        #remove jumper from led
        #SDA=P9 aka G16 aka GPIO12  SCL=P10 aka G17 aka GPIO13
        #expansionboard v2.1a
        i2c = I2C(0, I2C.MASTER,  baudrate=100000)
        
        i2c.scan()
        
        i2cadr = 0x40
        A = 8.1332;
        B = 1762.39;
        C = 235.66
        
        def crc8(raw):
          check = raw[0] << 16 | raw[1] << 8 | raw[2]
          #print(check)
          #print(raw[0], ' ', raw[1], ' ', raw[2])
        
          check1 = check
        
          divsor = 0x988000 # 1 0011 0001 0x131
        
          for i in range(0, 16):
            if( check & 1 << (23 - i) ):
              check ^= divsor
        
            divsor = divsor >> 1
        
          if not check == 0:
            #print('True')
          #else:
            print('False')
        
        
        while 1:
          ## read Temperature, hold
          #i2c.writeto(i2cadr, b'\xE3')
          ## read Temperature, no hold
          dummy = i2c.writeto(i2cadr, b'\xF3')
          time.sleep(0.1)
          raw = i2c.readfrom(i2cadr, 3)
        
          crc8(raw)
          raw = raw[0] << 8 | raw[1]
          #raw = raw & 0xFFFC;
          #tempV = -46.85 + (175.72 * raw / 65536)
          raw = raw >> 2;
          tempV = -46.85 + (175.72 * raw / 16384)
        
          ## read Humidity, hold
          #i2c.writeto(i2cadr, b'\xE5')
          ## read Humidity, no hold
          dummy = i2c.writeto(i2cadr, b'\xF5')
          time.sleep(0.1)
          raw = i2c.readfrom(i2cadr, 3)
          raw = raw[0] << 8 | raw[1]	
          #raw = raw & 0xFFFC;
          #humdV = -6 + (125.0 * raw / 65536)
          raw = raw >> 2;
          humdV = -6 + (125.0 * raw / 16384)
        
          ## compute dewpoint
          pp = math.pow(10, A - B / (tempV + C))  
          tm = math.log(humdV * pp / 100, 10)
          dp = -(B / (tm - A) + C)
        
          #print('temp: ', tempV, '  relH: ', humdV,' dew: ',dp)
          print('temp: {:<10} relH: {:<10} dew: {:<10}'.format(tempV, humdV, dp))
          time.sleep(2)
        
        
        
        
        W 1 Reply Last reply Reply Quote 0
        • W Offline
          Wolli01 @Frida
          last edited by

          @Frida Scheint zu laufen!
          Vielen vielen Dank. Sie haben mir sehr geholfen.

          1 Reply Last reply Reply Quote 0
          • FridaF Offline
            Frida
            last edited by

            Gern geschehen.
            Grüße aus Dänemark

            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