si7021.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:OpenAg-MVP 作者: webbhm 项目源码 文件源码
def getTempC():
# SI7021 address, 0x40(64)
#       0xF3(243)   Select temperature NO HOLD master mode
    bus = smbus.SMBus(1)
    bus.write_byte(0x40, 0xF3)

    time.sleep(0.3)

# SI7021 address, 0x40(64)
# Read data back, 2 bytes, Temperature MSB first
    data0 = bus.read_byte(0x40)
    data1 = bus.read_byte(0x40)

# Convert the data
    cTemp = ((data0 * 256 + data1) * 175.72 / 65536.0) - 46.85
    #fTemp = cTemp * 1.8 + 32
    print ("Temperature in Celsius is : %.2f C" %cTemp)
    #print ("Temperature in Fahrenheit is : %.2f F" %fTemp)
    return cTemp
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号