MLX90614 and MPU6050 conflict on I2C bus

Hello,

On my arduino Uno R3, i am trying to make working both MLX90614 non-contact temperature sensor (at address 5A), and a MPU6050 (at address 68).

I manage to make one sensor (either MLX or MPU) working at a time, but not the 2 sensors at same time on same bus.

Either I have to merge MLX and MPU code, or create easily a 2nd I2C bus on other pins ?

Hi, welcome to the forum.

If you run the i2c_scanner, are both visible ?
Google for : arduino playground i2c_scanner

Is the problem the sketch ? Which libraries do you use ? Can you show your sketch between code tags ?

Can you give links to the sensor modules that you use ? How did you connect them to the Arduino ?
Sensor modules with voltage regulator should be powered with the Arduino 5V pin, but if the sensor module does not have a voltage regulator, the 5V will damage the sensor chips.

If I run the i2c scanner, there is only the mpu 6050 that is visible, but if I connect separately MPU or MLX, they are visible (once at a time).

I am usign adafruit MLX90614 library, and a custom code for MPU. I think that there is a double call to Wire,beginTransmission, with 2 different values (one for each sensor), causing failure to read MLX values.

#include <Wire.h>
#include <Adafruit_MLX90614.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

void setup() {
  Serial.begin(9600);

  Serial.println("Adafruit MLX90614 test");  

  mlx.begin();  
}

void loop() {
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC()); 
  Serial.print("*C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempF()); 
  Serial.print("*F\tObject = "); Serial.print(mlx.readObjectTempF()); Serial.println("*F");

  Serial.println();
  delay(500);
}
#include<Wire.h>
const int MPU=0x68;  // Adresse I2C du MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ, orient;
void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);  // registre PWR_MGMT_1
  Wire.write(0);     // mise a zero (reveile le MPU-6050)
  Wire.endTransmission(true);
  Serial.begin(9600);
}
void loop(){
  Wire.beginTransmission(MPU);
  Wire.write(0x3B);  // Demarrage avec le registre 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU,14,true);  // Demande de 14 registres
  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)    
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)

  if ((14000<AcZ) && (AcZ<18000)) Serial.println("Plat");
  else if ((-18000< AcZ) && (AcZ< -14000)) Serial.println("Retourne");
  else if ((14000<AcY) && (AcY< 18000)) Serial.println("Debout");
  else if ((-18000<AcY) && (AcY< -14000)) Serial.println("Envers");
  else if ((12000<AcX) && (AcX< 18000)) Serial.println("Cote gauche");
  else if ((-18000<AcX) && (AcX< -12000)) Serial.println("Cote droit");
 
  delay(333);
}

ebay 6DOF MPU6050
ebay MLX90614

I connect them according to tutorials on internet :
http://bildr.org/2011/02/mlx90614-arduino/
For the MPU, it is a basic i2c connection, on analog 4 and 5

If I run the i2c scanner, there is only the mpu 6050 that is visible, but if I connect separately MPU or MLX, they are visible (once at a time).

That doesn’t tell us much.

“When I connect the MPU, and run the scanner, I see that the MPU is at address 0xNN. When I connect the MLX, and run the scanner, I see that the MLX is at address 0xMM. When both connected, the scanner shows only one device, at address 0xPP.” conveys a LOT more information (where 0xNN, 0xMM, and 0xPP are replaced with the values you see, that is).

Ah, sorry :
When I connect the MPU, and run the scanner, I see that the MPU is at address 0x68. When I connect the MLX, and run the scanner, I see that the MLX is at address 0x5A. When both connected, the scanner shows only one device, at address 0x68 (it is the mpu).

That link is to a MLX90614 5V version. However, the example shows the MLX90614 at the 3.3V pin.

The MLX90614 is in 3V version (MLX90614Bxx) and 5V version (MLX90614Axx). Can you see (use a magnifier) what is printed on your MLX90614 sensor ?
The 3V version gets damaged with a voltage above 3.6V.

How did you set the MLX90614 in I2C mode ?

The MPU-6050 is a 3.3V sensor, but that module has a voltage regulator for 3.3V. So use Arduino 5V pin to MPU-6050 module VCC. It's SDA and SCL pins may not be connected to a 5V I2C bus.

You don't need extra pullup resistors. That MPU-6050 module has pullup resistors on the board. Can you check the value ? In the photo there are two pullup resistors with "222", which is 2k2.

Could you make a photo of how it is connected ?
You might need a I2C level shifter when you want to combine a 5V I2C bus with a 3.3V I2C bus.

I order my MLX90614 from here, so I think it is the 5V version.

I am currently powering my 2 sensors with 5V, and both values displayed on serial monitor seems correct (one sensor at a time).
There is indeed 222 resistors on my MPU6050 board.

I connect the 2 sensors at the same 5V and the same GND Pin.
And, in my prototyping board, I link wires from A4 and A5 to one or two sensor.

I want to be sure if you have a 3V or 5V version. Can you try to see what is written on it ?

When you connect the MPU-6050 module to the Arduino, the I2C bus is like a 3.3V I2C bus, since those 2k2 pull the signal up to 3.3V. That will work with an Arduino Uno, but not always.
You don't need the 4k7 pullup resistors. Have you accidently connected them to 5V ? Then the MPU-6050 might be damaged.

I think a 5V MLX sensor has no problem with a 3.3V I2C bus, but I could be wrong.

There is another option. A SoftwareWire library can create another I2C bus on any two pins. If those sensors really don't like each other, you might give them their own I2C bus.
I think that SoftwareWire is in the Library Manager.