MaixPy K210使用I2C的问题(已解决)
2021-03-316867
AI 快速预览详细
本文讨论了在使用MaixPy K210进行体温测量和人脸识别时遇到的I2C设备地址无法获取的问题。具体表现为使用i2c.scan()方法无法获取到mlx90614的地址,而其他I2C设备地址都能正常获取。文章提供了详细的故障排查步骤和解决方案,最终通过调整I2C初始化参数成功解决了问题。这对于初学者来说是一个实用的指南,能够帮助他们快速解决类似问题,节省排查时间。
|
想在K210上用mlx90614做测量体温和人脸识别,但是用i2c.scan()获取不到地址,其他i2c设备地址都能得到,是怎么回事 |
-
QQ图片20210331220021.png (209.33 KB, 下载次数: 5456)





MLX90614_TOBJI = const(0x07)
请问这两个地址是怎么来的呀?我是否可以改用scl = 9, sda =10呀
第一,检查接线
第二,软硬I2C换着测
话说怎么就解决了!!!!!
测试读取温度无误。
[code]import time
from machine import I2C
i2c = I2C(I2C.I2C0, freq=100000, scl=24, sda=25)
time.sleep_ms(100)
MLX90614_IIC_ADDR = const(0x5A)
MLX90614_TA = const(0x06)
MLX90614_TOBJ1 = const(0x07)
class MLX90614:
def __init__(self,i2c,addr=MLX90614_IIC_ADDR):
self.addr=addr
self.i2c=i2c
def getObjCelsius(self):
return self.getTemp(MLX90614_TOBJ1) #Get celsius temperature of the object
def getEnvCelsius(self):
return self.getTemp(MLX90614_TA) #Get celsius temperature of the ambient
def getObjFahrenheit(self):
return (self.getTemp(MLX90614_TOBJ1) * 9 / 5) + 32 #Get fahrenheit temperature of the object
def getEnvFahrenheit(self):
return (self.getTemp(MLX90614_TA) * 9 / 5) + 32 #Get fahrenheit temperature of the ambient
def getTemp(self,reg):
temp = self.getReg(reg)*0.02-273.15 #Temperature conversion
return temp
def getReg(self,reg):
data = self.i2c.readfrom_mem(self.addr,reg,3) #Receive DATA
result = (data[1]<<8) | data[0]
return result
ir =MLX90614(i2c)
while True:
print(ir.getObjCelsius())
[/code]repl输入如下:[code]MicroPython v0.6.2-15-g0118a9a77 on 2021-01-12; Sipeed_M1 with kendryte-k210
Type "help()" for more information.
>>> []
MicroPython v0.6.2-15-g0118a9a77 on 2021-01-12; Sipeed_M1 with kendryte-k210
Type "help()" for more information.
>>> 22.75
22.75[/code]