赞
踩
from machine import Pin,PWM,SoftI2C,I2C i2c=SoftI2C(scl=Pin(4), sda=Pin(5), freq=400000) i2c.start() i2c.writeto_mem(0x68, 0x6B,b'0') high=i2c.readfrom_mem(0x68,0x41,1) low=i2c.readfrom_mem(0x68,0x42,1) h=high[0] l=low[0] value = (h << 8) + l if (value >= 0x8000): v = -((65535 - value) + 1) else: v = value raw_temp = (v / 340.0) + 36.53 print("温度:", raw_temp)
运行结果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。