SHT30
1)查找SHT30芯片资料
https://www.szlcsc.com
2)根据芯片资料,查得
地址为 0x44 或 0x45
选 Measurement Commands for Single Shot Data Acquisition Mode, 命令为 0x2c10
3)连线
SHT30 ESP32
D1(SCL) 4
D2(SDA) 5
G GND
3V3 3V3
3)编代码
查看micropython官方文档esp32部分。
https://docs.micropython.org/en/latest/esp32/quickref.html
EPS32 的代码
from machine import Pin, I2C import time SHT30 = 0x45 # IIC通信地址 cmd = bytearray(2)# 放命令 data = bytearray(6)# 放数据 i2c = I2C(0, scl=Pin(4), sda=Pin(5), freq=400000) # 初始化硬件IIC0 print(i2c.scan()) # 打印出i2c总线上的全部设备地址 cmd[0] = 0x2c # Measurement Commands for Single Shot Data Acquisition Mode cmd[1] = 0x10 i2c.writeto(0x45, cmd) # write the given buffer to the peripheral #MEASURE_CMD = b'\x2C\x10' #i2c.writeto(0x45, MEASURE_CMD) # write the given buffer to the peripheral time.sleep_us(1000) # sleep for 1000 microseconds data = i2c.readfrom(0x45, 6)# read 6 bytes from device with address 0x45 temperature = 175*(data[0]*256+data[1])/(65536-1) -45 #计算温度 humidity = 100*(data[3]*256+data[4])/(65536-1) #计算湿度 print(temperature) print(humidity)
标签:micropython,SHT30,温湿度,ESP32,cmd,0x45,i2c,data From: https://www.cnblogs.com/excellentHellen/p/18439610