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);
}