星瞳实验室APP,快速收到回复
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 请教I2C连接无反应问题


    • Banned

      工程师您们好,我想利用openmv连接一个mlx90614红外温度传感器,连接后无应答。代码如图(错误如图)

      # This example is to get the ambient temperature and object temperature by the I2C bus
      # Hardware : MLX90614, OpenMV
      # connect I2C
      #   MLX90614  OpenMV
      #   VCC       VCC
      #   GND       GND
      #   SCL       SCL
      #   SDA       SDA
      
      from pyb import I2C
      import time
      _MLX90614_IIC_ADDR   = (0x5A)
      _MLX90614_TA         = (0x06)
      _MLX90614_TOBJ1      = (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.mem_read(3,self.addr,reg)               #Receive DATA
          result = (data[1]<<8) | data[0]
          return result
      
      i2c=I2C(2,I2C.MASTER,baudrate=100000)
      print(i2c.is_ready(_MLX90614_IIC_ADDR))
      ir=MLX90614(i2c)
      
      while True:
        time.sleep(2000)
        print("Object  %s *C"% ir.getObjCelsius())        #print celsius of Object
        print("Object  %s *F"% ir.getObjFahrenheit())     #print fahrenheit of Object
        print("Ambient %s *C"% ir.getEnvCelsius())        #print celsius of Ambient
        print("Ambient %s *F"% ir.getEnvFahrenheit())     #print fahrenheit of Ambient
        print()
      

      2_1547213087228_微信图片_20190111212430.jpg 1_1547213087227_微信图片_20190111212420.jpg 0_1547213087225_Capture.PNG



    • OpenMV需要焊接插针使用。