3.14 haas506开发教程-example-温湿度传感器(SHT30/GXHT30)
1.介绍
链接
![在这里插入图片描述](https://img-blog.csdnimg.cn/1ae09f364cf54082851e6c5c934d6c05.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5pm65LqR5pyN,size_16,color_FFFFFF,t_70,g_se,x_16#pic_center)
2.硬件接线
![在这里插入图片描述](https://img-blog.csdnimg.cn/bc29a41884474d6fb76399844deb1302.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5pm65LqR5pyN,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)
3.测试代码
import utime as time
from driver import I2C
i2c=I2C()
i2c.open('gxht30')
def write(cmd1,cmd2):
writeBuf=bytearray([cmd1,cmd2])
i2c.write(writeBuf,2)
def read(cmd,len):
readBuf=bytearray(len)
readBuf[0]=cmd
i2c.read(readBuf,6)
return readBuf
def covert_data(data):
cTemp = ((((data[0] * 256.0) + data[1]) * 175) / 65535.0) - 45
fTemp = cTemp * 1.8 + 32
humidity = 100 * (data[3] * 256 + data[4]) / 65535.0
return cTemp,fTemp,humidity
def main():
while True:
write(0x2c,0x06)
data=read(0x00,6)
cTemp,fTemp,humidity=covert_data(data)
print ("Relative Humidity : %.2f %%RH" %humidity)
print ("Temperature in Celsius : %.2f C" %cTemp)
print ("Temperature in Fahrenheit : %.2f F" %fTemp)
time.sleep(1)
print("-----------------\n")
if __name__=="__main__":
main()
{
"name": "haas506",
"version": "1.0.0",
"io": {
"ADC0": {
"type": "ADC",
"port": 0,
"sampling": 12000000
},
"ADC1": {
"type": "ADC",
"port": 1,
"sampling": 12000000
},
"OLED": {
"type": "I2C",
"port": 1,
"addrWidth": 7,
"freq": 400000,
"mode": "master",
"devAddr": 60
},
"gxht30": {
"type": "I2C",
"port": 1,
"addrWidth": 7,
"freq": 400000,
"mode": "master",
"devAddr": 68
},
"KEY1": {
"type": "GPIO",
"port": 44,
"dir": "irq",
"pull": "pullup",
"intMode": "rising"
},
"led1": {
"type": "GPIO",
"port": 7,
"dir": "output",
"pull": "pulldown"
},
"led_g": {
"type": "GPIO",
"port": 32,
"dir": "output",
"pull": "pulldown"
},
"SPI0": {
"type": "SPI",
"port": 0,
"mode": "master",
"freq": 2000000
},
"serial1": {
"type": "UART",
"port": 0,
"dataWidth": 8,
"baudRate": 115200,
"stopBits": 1,
"flowControl": "disable",
"parity": "none",
"timeout": 1000
},
"serial2": {
"type": "UART",
"port": 1,
"dataWidth": 8,
"baudRate": 9600,
"stopBits": 1,
"flowControl": "disable",
"parity": "none",
"timeout": 1000
},
"serial3": {
"type": "UART",
"port": 2,
"dataWidth": 8,
"baudRate": 115200,
"stopBits": 1,
"flowControl": "disable",
"parity": "none",
"timeout": 1000
}
},
"debugLevel": "ERROR",
"repl": "enable",
"replPort": 0
}
4.测试结果
![在这里插入图片描述](https://img-blog.csdnimg.cn/e4b8ad73107f4490918ffd050dfb6f30.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5pm65LqR5pyN,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)