SHT30

SHT30 is a sensor that can be used to measure temperature and humidity.

UiFlow2 Example

get temperature and humidity

Open the paper_sht30_example.m5f2 project in UiFlow2.

This example reads the temperature and humidity from the SHT30 sensor.

UiFlow2 Code Block:

example.png

Example output:

None

MicroPython Example

get temperature and humidity

This example reads the temperature and humidity from the SHT30 sensor.

MicroPython Code Block:

 1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8from hardware import SHT30
 9
10
11sht30 = None
12
13
14def setup():
15    global sht30
16
17    M5.begin()
18    Widgets.fillScreen(0xEEEEEE)
19
20    sht30 = SHT30()
21
22
23def loop():
24    global sht30
25    M5.update()
26    print((str("Humidity:") + str((sht30.get_humidity()))))
27    print((str("Temperature:") + str((sht30.get_temperature()))))
28
29
30if __name__ == "__main__":
31    try:
32        setup()
33        while True:
34            loop()
35    except (Exception, KeyboardInterrupt) as e:
36        try:
37            from utility import print_error_msg
38
39            print_error_msg(e)
40        except ImportError:
41            print("please update to latest firmware")

Example output:

None

API

SHT30

class hardware.sht30.SHT30

Bases: SHT30

class driver.sht30.SHT30(i2c=None, delta_temp=0, delta_hum=0, i2c_address=68)

Bases: object

Create a SHT30 object.

Parameters:
  • i2c (I2C) – The I2C bus object.

  • delta_temp (int) – The temperature delta to apply to measurements.

  • delta_hum (int) – The humidity delta to apply to measurements.

  • i2c_address (int) – The I2C address of the sensor.

UiFlow2 Code Block:

init.png

MicroPython Code Block:

from hardware import Pin
from hardware import I2C
from hardware import SHT30

# Paper
i2c0 = I2C(0, scl=Pin(22), sda=Pin(21), freq=100000)
sht30 = SHT30(i2c0)
get_temperature()

Get the temperature in Celsius.

UiFlow2 Code Block:

get_temperature.png

MicroPython Code Block:

sht30.get_temperature()
get_humidity()

Get the relative humidity in percent.

UiFlow2 Code Block:

get_humidity.png

MicroPython Code Block:

sht30.get_humidity()