Hello everyone, for my current project i'm using an Arduino uno. I'm using the gy-906 mlx90614 temperature sensor to transmit the object temperature and the current emissivity value used by the sensor to the arduino, i also use vl53l0x sensor to measure distance. All of these values are displayed on the ssd1306, and OLED display, all of these devices use i2c. The project is working fine, however, I'm also trying to use two buttons to increase or decrease the emissivity stored in the mlx90614 and it's causing some problems. i should also add that i'm using the adafruit library for the mlx90614.
So, using the code below, when i start altering the emissivity i works for a few moments but then the temperature starts getting weird until i turn the arduino off and back on again. After reading the datasheet, i discovered that when a change to the emissivity register is made, you need to turn the sensor off and back on again. However, the sensor is in the 3.3V pin so it's always on, i think this is why i need to turn off the Arduino to make it work again.
#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;
int aumentar = 4;
int diminuir = 6;
double emissividade = 1.0;
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
pinMode(aumentar, INPUT);
pinMode(diminuir, INPUT);
Serial.begin(9600);
}
void loop() {
display.clearDisplay();
Serial.println(mlx.readEmissivity());
if(digitalRead(aumentar) == HIGH && mlx.readEmissivity()<1.0 ){ //Programar os botões
emissividade = emissividade + 0.05;
mlx.writeEmissivity(emissividade);
}
if(digitalRead(diminuir) == HIGH && mlx.readEmissivity() > 0.1){
emissividade = emissividade - 0.05;
mlx.writeEmissivity(emissividade);
}
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,8);
display.println("Emissivity:");
display.setTextSize(2);
display.setCursor(65,4);
display.println(mlx.readEmissivity(),2); //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);
}
My idea is, connect the VIN pin of the mlx90614 to a digital pin instead, so when i make a change to the emissivity the digital this pin sets to LOW, turning off the sensor, and after a delay it goes back to HIGH, turning it back on. But, i read that this is not as simple with i2c devices, i'm kind of a beginner with electronics and i'm worried if this might damage the sensor. So my question is, will this work? and will it damage the sensor?