SHT30
SHT30 是一款用于测量温度和湿度的传感器。
UiFlow2 示例
获取温度和湿度
在 UiFlow2 中打开 paper_sht30_example.m5f2 项目。
本示例从 SHT30 传感器读取温度和湿度。
UiFlow2 代码块:
示例输出:
None
MicroPython 示例
获取温度和湿度
本示例从 SHT30 传感器读取温度和湿度。
MicroPython 代码块:
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")
示例输出:
None
API参考
SHT30
- class driver.sht30.SHT30(i2c=None, delta_temp=0, delta_hum=0, i2c_address=68)
基类:
object创建一个 SHT30 对象。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
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()
获取摄氏温度。
UiFlow2 代码块:

MicroPython 代码块:
sht30.get_temperature()
- get_humidity()
获取相对湿度(百分比)。
UiFlow2 代码块:

MicroPython 代码块:
sht30.get_humidity()
