Problem making the VL53l0x work with mlx90614 infrared thermometer

Hello everyone!

I'm trying to make a project using an Arduino UNO, i want to display the current object temperature and emissivity of the mlx90614 and also the distance obtained by the VL53l0x on the 128x64 ssd1306 OLED display, using I2C. All these components run well seperately using the adafruit example codes, i can also run the mlx90614 with the OLED display correctly using this code

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

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET    -1 // Reset pin # (or -1 if sharing Arduino reset pin)

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); //Declaring the display name (display)
Adafruit_MLX90614 mlx = Adafruit_MLX90614();

void setup() {  
  mlx.begin(); 
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //Start the OLED display
  display.clearDisplay();
  display.display();

}

void loop() {
  display.clearDisplay();
  
  display.setTextSize(1);                    
  display.setTextColor(WHITE);             
  display.setCursor(0,4);                
  display.println("Emissivity:"); 
  
  display.setTextSize(2);
  display.setCursor(65,0);
  display.println(mlx.readEmissivity(),1);
 
  
  
  display.setTextSize(1);                    
  display.setTextColor(WHITE);             
  display.setCursor(0,20);                
  display.println("Objeto: "); 
  
  display.setTextSize(2);
  display.setCursor(50,17);
  display.println(mlx.readObjectTempC(),1);
  
  display.setCursor(100,17);
  display.println("C");
  
  display.display();
  
  delay(1000);

}

The vl53l0x also works well with the display using the adafruit example code that display the range on the OLED.
However, when i try to use all the 3 components together nothing works, The OLED just doesn't turn on. they are all connected to 3.3V and on the same i2c line. Also when try to run the first code again with the same connections (that is, the vl53l0x still connected to the i2c) it runs with no problem.
This is the code not working:

#include <Adafruit_VL53L0X.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include <Adafruit_MLX90614.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET    -1 // Reset pin # (or -1 if sharing Arduino reset pin)

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); //Declaring the display name (display)
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
Adafruit_VL53L0X lox = Adafruit_VL53L0X();

void setup() {  
  mlx.begin();
  lox.begin();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //Start the OLED display
  display.clearDisplay();
  display.display();

}

void loop() {
  VL53L0X_RangingMeasurementData_t measure;
  display.clearDisplay();

  lox.rangingTest(&measure, false);
  
  display.setTextSize(1);                    
  display.setTextColor(WHITE);             
  display.setCursor(0,4);                
  display.println("Emissivity:"); 
  
  display.setTextSize(2);
  display.setCursor(65,0);
  display.println(mlx.readEmissivity(),1);
 
  
  
  display.setTextSize(1);                    
  display.setTextColor(WHITE);             
  display.setCursor(0,20);                
  display.println("Objeto: "); 
  
  display.setTextSize(2);
  display.setCursor(50,17);
  display.println(mlx.readObjectTempC(),1);
  display.setCursor(100,17);
  display.println("C");

  
  display.setTextSize(1);
  display.print("Distancia: ");
  if (measure.RangeStatus != 4) {
    display.setTextSize(2);
    display.print(measure.RangeMilliMeter);
    display.print("mm");
  }
  else{
    display.setTextSize(1);
    display.print("Fora de alcance");
  }
  
  display.display();
  
  delay(1000);

}

I'd start by using an I2C sniffer to verify all devices are visible on the network. I'm pretty sure the hd44780 library by Bill Perry, in the Arduino IDE library collection, has one.

So i actually managed to fix the code by using the Pololu library for the VL53I0X instead of the Adafruit one. I do not know what was the problem but now everything works as intended. Here is the code in case other people run into the same problem:

#include <VL53L0X.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include <Adafruit_MLX90614.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET    -1 // Reset pin # (or -1 if sharing Arduino reset pin)

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); //Declaring the display name (display)
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
VL53L0X sensor;

void setup() {  
  mlx.begin(); 
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //Start the OLED display
  display.clearDisplay();
  display.display();
  if (!sensor.init())
  {
    while (1) {}
  }
  sensor.startContinuous();         //Inicializar medição de distancia
}

void loop() {
  display.clearDisplay();
  
  display.setTextSize(1);                    
  display.setTextColor(WHITE);             
  display.setCursor(0,8);                
  display.println("Emissivity:"); 
  
  display.setTextSize(2);
  display.setCursor(65,4);
  display.println(mlx.readEmissivity(),1);  //display emissivity
  
  display.setTextSize(1);                    
  display.setTextColor(WHITE);             
  display.setCursor(0,28);                
  display.println("Objeto: "); 
  
  display.setTextSize(2);
  display.setCursor(52,25);
  display.println(mlx.readObjectTempC(),1); //display current object temperature
  
  display.setCursor(100,25);
  display.println("C");
  // Display distance

  display.setTextSize(1);
  display.setCursor(0,50);
  display.println("Distancia: ");
  display.setTextSize(2);
  display.setCursor(65,50);
  if(sensor.readRangeContinuousMillimeters()>=8190){
    display.setTextSize(1);
    display.print("ALCANCE");
  }
  else if(!sensor.timeoutOccurred()){
  display.print(sensor.readRangeContinuousMillimeters());
  display.print("mm");
  }
  else if(sensor.timeoutOccurred()){
    display.print("ERRO");
  }

  display.display();
  
  delay(500);

}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.