问 天问文档中心
⌕
文档

SHT30 - 温湿度传感器

更新于 2025-03-06 · 文档路径 esp32c3/02-天问ESP32C3-Pro/09-扩展类库/02-SHT30---温湿度传感器

SHT30是一种常见的温湿度传感器,是一款完全校准的线性化的温湿度数字传感器,增强了数字信号。I2C通讯频率达1MHz。具有高可靠性及高稳定性。该传感器广泛应用于各种场景。

一.初始化

from board import *
import sht30

sht = sht30.SHT30(scl ,sda )
  • 参数
    • scl:I2C时钟线(SCL)引脚
    • sda:I2C数据线(SDA)引脚

二.获取温湿度


获取温度

sht.measure_temperature()
  • 返回值
    • 返回获取到的温度数值,单位:摄氏度(°C)

使用示例

from board import *
import sht30
import time

sht = sht30.SHT30(scl = Pin(0),sda = Pin(1))
while True:
    try:
        oled.fill(0)
        oled.DispChar(str((str('温度:') + str(round((sht.measure_temperature()), 2)))), 0, 0, 1)
        oled.show()
    except:
        pass
    print(str('温度:') + str(round((sht.measure_temperature()), 2)))
    time.sleep(1)

获取湿度

sht.measure_humidity()
  • 返回值
    • 返回获取到的湿度百分比,单位:相对湿度(%RH)

使用示例

from board import *
import sht30
import time

sht = sht30.SHT30(scl = Pin(0),sda = Pin(1))
while True:
    try:
        oled.fill(0)
        oled.DispChar(str((str('湿度:') + str(round((sht.measure_humidity()), 2)))), 0, 0, 1)
        oled.show()
    except:
        pass
    print(str('湿度:') + str(round((sht.measure_humidity()), 2)))
    time.sleep(1)