I need to detect the temperature using MLX90614 sensor and LoRa esp32 (V3) and I can be able to see the temperatures on serial monitor but can’t be able to see on OLED. can someone help to resolve the issue?
#include <Wire.h>
#include “HT_SSD1306Wire.h”
#include <Adafruit_MLX90614.h> // MLX90614 library
// Initialize display and MLX90614 sensor
SSD1306Wire oledDisplay(0x3C, 400000, 21, 19, GEOMETRY_128_64, -1); // I2C address, frequency, SDA, SCL, geometry, reset pin
Adafruit_MLX90614 mlx = Adafruit_MLX90614(); // MLX90614 sensor
void setup() {
Serial.begin(115200);
Wire.begin(21, 19); // Initialize I2C with SDA, SCL pins
// I2C Scanner to detect devices on the I2C bus
Serial.println(“Scanning for I2C devices…”);
byte error, address;
int nDevices = 0;
for (address = 1; address < 127; address++) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print(“I2C device found at address 0x”);
if (address < 16) Serial.print(“0”);
Serial.println(address, HEX);
nDevices++;
}
}
if (nDevices == 0)
Serial.println(“No I2C devices found.\n”);
else
Serial.println(“I2C devices found.\n”);
// Initialize MLX90614 sensor and check if it started correctly
if (!mlx.begin()) {
Serial.println(“Error initializing MLX90614 sensor!”);
while (1); // Stop if sensor init fails
} else {
Serial.println(“MLX90614 sensor initialized successfully.”);
}
// Initialize OLED display
oledDisplay.init();
oledDisplay.flipScreenVertically(); // Rotate display if necessary
oledDisplay.setContrast(255);
oledDisplay.clear();
oledDisplay.display();
}
void loop() {
// Read temperatures
double ambientTemp = mlx.readAmbientTempC(); // Read ambient temperature in Celsius
double objectTemp = mlx.readObjectTempC(); // Read object temperature in Celsius
if (isnan(ambientTemp) || isnan(objectTemp)) {
Serial.println(“Failed to read from MLX90614 sensor!”);
} else {
// Display temperature values on Serial Monitor
Serial.print(“Ambient Temp: “);
Serial.print(ambientTemp);
Serial.print(” °C\t”);
Serial.print(“Object Temp: “);
Serial.print(objectTemp);
Serial.println(” °C”);
// Display only the object temperature on the OLED display
oledDisplay.clear();
oledDisplay.setTextAlignment(TEXT_ALIGN_CENTER);
oledDisplay.setFont(ArialMT_Plain_24);
oledDisplay.drawString(64, 22, String(objectTemp, 1)); // Show only object temperature
oledDisplay.display();
}
delay(2000);
}