1

I have bought a MLX90615 IR Thermal sensor with my Arduino UNO. After consulting Google and Github data, I have code similar to this:

   #include "LiquidCrystal.h"
 unsigned char Re_buf[11],counter=0;
 char sign=0;
float TO=0,TA=0;
void serialEvent();




// initialize the library by providing the nuber of pins to it
LiquidCrystal lcd(8,9,4,5,6,7);



void setup() {

lcd.begin(16,2);

// set cursor position to start of first line on the LCD
lcd.setCursor(0,0);
//text to print
lcd.print("   16x2 LCD");
// set cusor position to start of next line
lcd.setCursor(0,1);
lcd.print("   DISPLAY");
   Serial1.begin(115200);
   Serial.begin(115200);
  delay(1);
  Serial1.write(0XA5);
  Serial1.write(0X45);
  Serial1.write(0XEA);
}

void loop() {




   char i=0,sum=0;
 serialEvent();
  if(sign)
  {
     sign=0;
     for(i=0;i<8;i++)
      sum+=Re_buf[i];
     if(sum==Re_buf[i] )
     {
           TO=(float)(Re_buf[4]<<8|Re_buf[5])/100;
           Serial.print("TO:");
           Serial.println(TO);
           TA=(float)(Re_buf[6]<<8|Re_buf[7])/100;
           Serial.print("TA:");
           Serial.println(TA);
   }
  }

}
void serialEvent(){ 
  while (Serial1.available()) {
    Re_buf[counter]=(unsigned char)Serial1.read();
    if(counter==0&&Re_buf[0]!=0x5A) return;
    counter++;
    if(counter==9)
    {
       counter=0;
       sign=1;
    }
  }
}

With this code, the temperature is updating every 0.5 seconds, but then I changed that code and added a TFT 2"4 LCD TOUCH SCREEN code, so the the main code changed to this:

void loop() {

//
//
//  
   char cc,i=0,sum=0;

   //  digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint();     // Read touchscreen
//  digitalWrite(13, LOW);

  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);

//   score=1;
//   while(score==1){
for(i=0;i<8;i++){
  i=1;
 serialEvent();
  if(sign)
  {
     sign=0;
     for(i=0;i<8;i++)
      sum+=Re_buf[i];
     if(sum==Re_buf[i] )
     {
           TO=(float)(Re_buf[4]<<8|Re_buf[5])/100;
//           Serial.print("TO:");
//           Serial.println(TO);
//           TA=(float)(Re_buf[6]<<8|Re_buf[7])/100;
//           Serial.print("TA:");
//           Serial.println(TA);

             tft.fillScreen(BLACK);
             tft.setTextColor(WHITE);
             tft.setTextSize(3);
             Serial.print("TO:");
             Serial.println(TO);

            tft.setCursor(10, 15);
            tft.print("Temprature :");
            tft.setCursor(10, 50);
            tft.print(TO);
            tft.setCursor(100, 30);tft.print("C");
             TA=(float)(Re_buf[6]<<8|Re_buf[7])/100;
             Serial.print("TA:");
             Serial.println(TA);
             delay(100);
   }
  }

 }

That code can be seen here:

http://www.rapidshare.com.cn/yrKagCf

or

mega

The connections are here:

Arduino connections

The problem is that new codes stop working and update the temperature for some times. It take some seconds for updating the temperature. We need to update the temperature every second, but that new code sometimes works and some times not.I guess it must be losing the usart connection sometimes.

migrated from electronics.stackexchange.com May 20 '18 at 17:24

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy