🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Micropython - SHT30 in BTC Base

    Bases
    5
    7
    14.3k
    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.
    • K
      kedulowt
      last edited by

      If someone would try work with SHT30, I recommend:

      https://github.com/rsc1975/micropython-sht30

      but in this base you should propertly sel scl, sda pins and i2c addres SHT30 is 0x44.

      Code:
      from sht30 import SHT30
      sht30_sensor = SHT30(scl_pin=22, sda_pin=21, delta_temp=-3, i2c_address=0x44)
      temperature, humidity = sht30_sensor.measure()

      Also what i noticed that is showed temperature is higher than real. To correct it i use delta_temp.

      ajb2k3A 1 Reply Last reply Reply Quote 3
      • TitiMobyT
        TitiMoby
        last edited by

        It is a bit too early because MicroPython is still not there on M5Paper that I own, but as it uses the same SHT30, I also noticed some delta issue in temperature using Arduino.
        Is it a common thing with this component ?

        1 Reply Last reply Reply Quote 0
        • S
          sj3fk3
          last edited by

          I honestly don't understand M5Stack's way of working. There is this ENV2 with python support: https://docs.m5stack.com/#/en/unit/envII it has a SHT30, but then you spend $80 on a M5Paper and you don't get python support for the SHT30. How hard is it to put in the the right lib.

          I know I can do it myself, but M5stack should have done this already :-/

          ajb2k3A 1 Reply Last reply Reply Quote 1
          • ajb2k3A
            ajb2k3 @sj3fk3
            last edited by

            @sj3fk3 said in Micropython - SHT30 in BTC Base:

            I honestly don't understand M5Stack's way of working. There is this ENV2 with python support: https://docs.m5stack.com/#/en/unit/envII it has a SHT30, but then you spend $80 on a M5Paper and you don't get python support for the SHT30. How hard is it to put in the the right lib.

            I know I can do it myself, but M5stack should have done this already :-/

            Micropython on the M5Paper is in early alpha because we pushed M5Stack to get it out before the holiday. I spent yesterday doing some testing and I cannot get any SHT30 devices to work no matter if its the internal SHT30 on the paper or the env2 unit.
            What lib are you using as I cant even get raw reg read and writes to work.

            UIFlow, so easy an adult can learn it!
            If I don't know it, be patient!
            I've ether not learned it or am too drunk to remember it!
            Author of the WIP UIFlow Handbook!
            M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

            S 1 Reply Last reply Reply Quote 0
            • ajb2k3A
              ajb2k3 @kedulowt
              last edited by

              @kedulowt said in Micropython - SHT30 in BTC Base:

              temperature, humidity = sht30_sensor.measure()

              I can't get this to work

                File "<stdin>", line 1, in <module>
                File "sht30.py", line 40, in __init__
              NameError: name 'I2C' isn't defined
              >>> 
              

              UIFlow, so easy an adult can learn it!
              If I don't know it, be patient!
              I've ether not learned it or am too drunk to remember it!
              Author of the WIP UIFlow Handbook!
              M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

              1 Reply Last reply Reply Quote 1
              • W
                Wolli01
                last edited by Wolli01

                Vielleicht hilft euch das weiter. Läuft auf einem M5Stick-C

                main.py

                import unit
                import machine
                import array
                import sht31

                from machine import I2C, Pin
                i2c = I2C(freq=100000, scl=Pin(32), sda=Pin(33) )
                sensor = sht31.SHT31(i2c, addr=0x44)

                while True:
                #Sensor SHT31-----------------------------------------------------------
                temp_humi = sensor.get_temp_humi()
                wait_ms(600)
                Temperatur = round(temp_humi[0],2)
                Feuchte = round(temp_humi[1],2)
                #Sensor SHT31-----------------------------------------------------------

                sht31.py

                from machine import I2C
                import time

                R_HIGH = const(1)
                R_MEDIUM = const(2)
                R_LOW = const(3)

                class SHT31(object):
                """
                Diese Klasse implementiert eine Schnittstelle zur SHT31 Temperatur und Luftfeuchtigkeit.
                Sensor von Sensirion.
                """
                # Diese statische Karte hilft, den Heap und die Programmlogik sauber zu halten.
                _map_cs_r = {
                True: {
                R_HIGH : b'\x2c\x06',
                R_MEDIUM : b'\x2c\x0d',
                R_LOW: b'\x2c\x10'
                },
                False: {
                R_HIGH : b'\x24\x00',
                R_MEDIUM : b'\x24\x0b',
                R_LOW: b'\x24\x16'
                }
                }

                def __init__(self, i2c, addr=0x44):
                    """
                    Initialisiert ein Sensorobjekt auf dem angegebenen I2C-Bus, auf das von der
                    angegebene Adresse.
                    """
                    if i2c == None or i2c.__class__ != I2C:
                        raise ValueError('I2C-Objekt als Argument benötigt!')
                    self._i2c = i2c
                    self._addr = addr
                
                def _send(self, buf):
                    """
                    Sendet das angegebene Pufferobjekt über I2C an den Sensor.
                    """
                    self._i2c.writeto(self._addr, buf)
                
                def _recv(self, count):
                    """
                    Lesen von Bytes vom Sensor über I2C. Die Anzahl der Bytes kann angegeben werden.
                    als Argument.
                    Liefert ein Bytearray für das Ergebnis.
                    """
                    return self._i2c.readfrom(self._addr, count)
                
                def _raw_temp_humi(self, r=R_HIGH, cs=True):
                    """
                    Lesen Sie die Rohtemperatur und Luftfeuchtigkeit vom Sensor ab und überspringen Sie CRC. Überprüfung.
                    Liefert ein Tupel für beide Werte in dieser Reihenfolge.
                    """
                    if r not in (R_HIGH, R_MEDIUM, R_LOW):
                        raise ValueError('Falscher Wiederholbarkeitswert angegeben!')
                    self._send(self._map_cs_r[cs][r])
                    time.sleep_ms(50)
                    raw = self._recv(6)
                    return (raw[0] << 8) + raw[1], (raw[3] << 8) + raw[4]
                
                def get_temp_humi(self, resolution=R_HIGH, clock_stretch=True, celsius=True):
                    """
                    Lesen Sie die Temperatur in Grad Celsius oder Fahrenheit und relativ dazu ab.
                    Feuchtigkeit. Auflösung und Taktverlängerung können festgelegt werden.
                    Liefert ein Tupel für beide Werte in dieser Reihenfolge.
                    """
                    t, h = self._raw_temp_humi(resolution, clock_stretch)
                    if celsius:
                        temp = -45 + (175 * (t / 65535.0))
                    else:
                        temp = -49 + (315 * (t / 65535.0))
                    return temp, 100 * (h / 65535.0)
                
                1 Reply Last reply Reply Quote 0
                • S
                  sj3fk3 @ajb2k3
                  last edited by

                  @ajb2k3 said in Micropython - SHT30 in BTC Base:

                  Micropython on the M5Paper is in early alpha because we pushed M5Stack to get it out before the holiday. I spent yesterday doing some testing and I cannot get any SHT30 devices to work no matter if its the internal SHT30 on the paper or the env2 unit.
                  What lib are you using as I cant even get raw reg read and writes to work.

                  For now I have abandoned micro python and switched to (yuck) C and platformio.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post