3.14 haas506开发教程-example-温湿度传感器(SHT30/GXHT30)

3.14 haas506开发教程-example-温湿度传感器(SHT30/GXHT30)

1.介绍

链接

在这里插入图片描述

2.硬件接线

在这里插入图片描述

3.测试代码

  • main.py
import utime as time
from driver import I2C

#SHT30 address:0x44
#measure command:0x2c
#High repeatability measurement:0x06
#read data from :0x00
#len(data) are 6 bytes : cTemp MSB, cTemp LSB, cTemp CRC, Humididty MSB, Humidity LSB, Humidity CRC 

i2c=I2C()
i2c.open('gxht30')


# write cmd to register
def write(cmd1,cmd2):
    writeBuf=bytearray([cmd1,cmd2])
    i2c.write(writeBuf,2)

#read data from register
def read(cmd,len):
    readBuf=bytearray(len)
    readBuf[0]=cmd
    i2c.read(readBuf,6)
    return readBuf
    

# Convert the data
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

# main code
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()


  • board.json
{
    "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.测试结果

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值