QUESTION ABOUT I2C CONNECTION

Discussion related to "under the hood" OpenMV topics.
Raul_
Posts: 7
Joined: Fri Jan 11, 2019 8:19 am

QUESTION ABOUT I2C CONNECTION

Postby Raul_ » Fri Jan 11, 2019 8:41 am

HI, engineers from OPENMV!

I am a newcomer and I just met some problems when connecting my openmv to a mlx90614 temperature sensor. i guess it is the connection problem since I have try to `i2c.scan()` and no valid address returned.

this is my code and how i connect the wires.

Code: Select all

# 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()
Attachments
微信图片_20190111212430.jpg
微信图片_20190111212420.jpg
Capture.PNG
Capture.PNG (8.74 KiB) Viewed 1469 times
User avatar
kwagyeman
Posts: 2895
Joined: Sun May 24, 2015 2:10 pm

Re: QUESTION ABOUT I2C CONNECTION

Postby kwagyeman » Fri Jan 11, 2019 12:09 pm

Hi, you need pull up resistors on the I2C lines. The OpenMV Cam doesn't pull the lines up by default. I2C Scan should work once you do that.
Nyamekye,
Raul_
Posts: 7
Joined: Fri Jan 11, 2019 8:19 am

Re: QUESTION ABOUT I2C CONNECTION

Postby Raul_ » Fri Jan 11, 2019 8:54 pm

kwagyeman wrote:
Fri Jan 11, 2019 12:09 pm
Hi, you need pull up resistors on the I2C lines. The OpenMV Cam doesn't pull the lines up by default. I2C Scan should work once you do that.
Thank you very much for your reply. I check my sensor and it is integrated with pull up resistors.

QAQ
Attachments
微信图片_20190112100011.jpg
User avatar
iabdalkader
Posts: 732
Joined: Sun May 24, 2015 3:53 pm

Re: QUESTION ABOUT I2C CONNECTION

Postby iabdalkader » Fri Jan 11, 2019 9:31 pm

I think you're connecting VIN to VIN, that's the power input pin on the OpenMV cam. You should connect the sensor's VIN to 3.3/vout.
Raul_
Posts: 7
Joined: Fri Jan 11, 2019 8:19 am

Re: QUESTION ABOUT I2C CONNECTION

Postby Raul_ » Fri Jan 18, 2019 4:33 am

iabdalkader wrote:
Fri Jan 11, 2019 9:31 pm
I think you're connecting VIN to VIN, that's the power input pin on the OpenMV cam. You should connect the sensor's VIN to 3.3/vout.
Thank you very much!!!! It really fixes my problem!! OpenMV is really a easy-to-use product!

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 3 guests