Need Help Adding 16x2 LCD function to Dual IR Temp sensors

#include <Wire.h>
#include <Adafruit_MLX90614.h>
#define IR1 0x5A
#define IR2 0x5B
Adafruit_MLX90614 mlx;

void setup() {
  Serial.begin(9600);
  

  Serial.println("Adafruit MLX90614 test");  

  mlx.begin(); 
  
  
}

void loop() {
  
  mlx.AddrSet(IR1); 
  Serial.print("IR1: "); 
  Serial.print("*F\tObject = "); Serial.print(mlx.readObjectTempF()); Serial.println("*F");
  mlx.temp1 = mlx.readObjectTempF();
  delay(250);
  mlx.AddrSet(IR2); 
  Serial.print("IR2: "); 
  Serial.print("*F\tObject = "); Serial.print(mlx.readObjectTempF()); Serial.println("*F");
  mlx.temp2 = mlx.readObjectTempF();
  delay(250);
  delay(250);
  Serial.println();
  delay(1000);
}

Hello all, i have a slight issue, i need to add the Liquid Crystal functions and code in order for my dual IR temp sensors to display on a 16x2 LCD. I want it to read object temp 1 on line one and object temp 2 on line 2.

What is your "slight issue"? Have you looked at LiquidCrystal examples to understand how it works?

i'm a novice at Arduino coding, mostly all i've done is small copy and paste style editing, from other's codes. I have looked at the examples and tried copy and pasting a few lines in but have yet to be able to get it to display on the LCD. This is a work project and my goals do not yet extend anywhere but IR temp sensors and the 16x02 LCD screen.

I have another code (taken from robojax) that will work properly for (1) IR Temp sensor with 1602 LCD to diplay object and ambient temp. I look back to that one to figure out what i need to do for this current one, but no luck yet. Again im a newb.

i don't truly know where to begin in order to get it to display Object1 and Object2 temps, but the initial code i attached works on the serial monitor how it is suppose to. So just need to get it onto the LCD.

Thank you for your response and help though.

What exact LCD display do you have?

What interface does the display have (I2C, SPI, serial, 4-bit, 8-bit, ... )?

LCD 1602 with I2C (4 Wire connection)

Is the I2C device found by the i2c_scanner?
To find that, look in Examples|Wire
C

yes its found by the scanner. 0x3F is the address.

Have you looked at the LCD examples yet?

Sounds like your company should be offering to pay for this work. There is a forum section where you can offer payment for writing code.

you got paypal? lol We're semi do it yourselfers. I've figured out what i could in just a couple of weeks.

Shouldn't it be finding 2 devices?

the scanner finds 3 devices the (2) IR sensors and the LCD

1 Like

I wasn't offering to do the work for you, I'm not in a position to do that. But I can move this topic to the appropriate forum section if you want.

I am attempting to add the hd44780 library to your code but I am getting a compile error (class Adafruit_MLX90614' has no member named 'AddrSet). Where did you get that Adafruit_MLX90614 library?

The hd44780 library is the best available for I2C LCDs. The library is available in the Library Manager. Have a look at the examples to see how to use the library.

i'd like to be able to figure it out myself.....whats the going rate for something like this?

for the single IR sensor and LCD setup i use the liquid crystal library.

I also got that error i think i had to install a modified MLX90614 library.

See below all these files came from the web where i found this initial code.

SparkFun_MLX90614_Arduino_Library-master.zip (1.1 MB)
Adafruit_MLX90614_Library.zip (3.9 KB)
Multiple-IR-Temperature-Sensors.pdf (281.3 KB)

MULTI IR CODE.zip (1.2 MB)
Original ^^^^ file

There are several libraries named LiquidCrystal_I2C. It is much less confusing if we use the one and only hd44780 library. Plus the hd44780 library is a much better library.

I am not going to download and unzip a bunch of zip files from an un-trusted source, sorry. Post the code here and links to the libraries, please.

Still unanswered. LCD is pretty basic, and this forum is a lot more helpful to those who at least play along.
C

i'm not familiar with the HD44780 library i figured the liquid crystal would work, the same as it did for the single IR setup i've done.

this is where i started with the multiple IR setup.

#include <Wire.h>
#include <Adafruit_MLX90614.h>
char *typeName[]={"Object:","Ambient:"};

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

#include <LiquidCrystal_I2C.h>
const uint8_t I2C_ADDRESS =0x3f;
const uint8_t LCD_CHAR= 16;
const uint8_t LCD_ROW= 2;
LiquidCrystal_I2C lcd(I2C_ADDRESS, LCD_CHAR,LCD_ROW);


void setup() {
//Robojax Step by Step Course http://robojax.com/L/?id=338    
  Serial.begin(9600);

  Serial.println("Robojax MLX90614 test");  

   if (!mlx.begin()) //Begin returns 0 on a good init
  {
      lcd.print("MLX90614 Failed");
      lcd.setCursor(0,1);
      lcd.print("check wiring!");      
    while (1)
      ;
  }  
  Wire.begin();
  lcd.begin();
  lcd.backlight();  
  
  
}//setup() end

void loop() {
  //Robojax Example for MLX90614 with LCD
//Robojax Step by Step Course http://robojax.com/L/?id=338    
  printTemp('F');//object temperature in F
  
  printTemp('G');//ambient temperature in F
  delay(2000);
//    
//  printTemp('F'); //object temperature in F
//  delay(2000);
//     
//  printTemp('G'); //ambient temperature in F
//  delay(2000);  
//  if( getTemp('C')>40)
//  {
//    //do something here
//  }
//  
//  printTemp('K'); //object temperature in K
//  delay(2000);    
//  printTemp('L');//ambient temperature in K  
//  delay(2000);   


  //Robojax Example for MLX90614
}

/*
 * @brief returns temperature or relative humidity
 * @param "type" is character
 *     C = Object Celsius
 *     D = Ambient Celsius
 *     
 *     K = Object Keliven
 *     L = Ambient in Keilven
 *     
 *     F = Object Fahrenheit
 *     G = Ambient in Fahrenheit

 * @return returns one of the values above
 * Usage: to get Fahrenheit type: getTemp('F')
 * to print it on serial monitor Serial.println(getTemp('F'));
 * Written by Ahmad Shamshiri on Mar 30, 2020. 
 * in Ajax, Ontario, Canada
 * www.Robojax.com 
 */
float getTemp(char type)
{
  //Robojax Step by Step Course http://robojax.com/L/?id=338  
   // Robojax.com MLX90614 Code
  float value;
    float tempObjec = mlx.readObjectTempC();//in C object
    float tempAmbient = mlx.readAmbientTempC();
   if(type =='F')
   {
    value = mlx.readObjectTempF(); //Fah. Object
   }else if(type =='G')
   {
    value = mlx.readAmbientTempF();//Fah Ambient
   }else if(type =='K')
   {
    value = tempObjec + 273.15;// Object Kelvin
   }else if(type =='L')
   {
    value = tempAmbient + 273.15;//Ambient Kelvin
   }else if(type =='C')
   {
    value = tempObjec;
   }else if(type =='D')
   {
    value = tempAmbient;
   }
   return value;
    // Robojax.com MLX90614 Code
}//getTemp

/*
 * @brief nothing
 * @param "type" is character
 *     C = Object Celsius
 *     D = Ambient Celsius
 *     
 *     K = Object Keliven
 *     L = Ambient in Keilven
 *     
 *     F = Object Fahrenheit
 *     G = Ambient in Fahrenheit

 * @return prints temperature value in serial monitor
 * Usage: to get Fahrenheit type: getTemp('F')
 * to print it on serial monitor Serial.println(getTemp('F'));
 * Written by Ahmad Shamshiri on Mar 30, 2020 at 21:51
 * in Ajax, Ontario, Canada
 * www.Robojax.com 
 */
void printTemp(char type)
{  
  float tmp =getTemp(type);
      lcd.setCursor(0,0);
      
  if(type =='C')
  {

      lcd.print(typeName[0]);  
      lcd.print(" ");
      lcd.print(tmp);        
      lcd.print((char)223);// 
      lcd.print("C");      
              

  }else if(type =='D')
  {
      lcd.print(typeName[1]); 
      lcd.print(" ");
      lcd.print(tmp);        
      lcd.print((char)223);// 
      lcd.print("C");        
  }else if(type =='F')
  {
      lcd.setCursor(0,0);
      lcd.print(typeName[0]); 
      lcd.print(" ");
      lcd.print(tmp);        
      lcd.print((char)223);// 
      lcd.print("F");        
  }else if(type =='G')
  {
      lcd.setCursor(0,1);
      lcd.print(typeName[1]);
      lcd.print(" ");
      lcd.print(tmp);        
      lcd.print((char)223);// 
      lcd.print("F");       
  }

  else if(type =='K')
  {
      lcd.print(typeName[0]); 
      lcd.print(" ");
      lcd.print(tmp);        
      lcd.print((char)223);// 
      lcd.print("K");        
  }  
  else if(type =='L')
  {
      lcd.print(typeName[1]);
      lcd.print(" ");
      lcd.print(tmp);        
      lcd.print((char)223);// 
      lcd.print("K");        

  }

// Robojax.com MLX90614 Code
}//printTemp(char type)


/*
   clearCharacters(uint8_t row,uint8_t start, uint8_t stop)
 * @brief clears a line of display (erases all characters)
 * @param none
 * @return does not return anything
 * Written by Ahmad Shamshiri
 * www.Robojax.com code May 28, 2020 at 16:21 in Ajax, Ontario, Canada
 */
void clearCharacters(uint8_t row,uint8_t start, uint8_t stop )
{
    for (int i=start; i<=stop; i++)
    {
    lcd.setCursor (i,row); //  
    lcd.write(254);
    } 

}//clearCharacters

Code i got from robojax for the single IR set up, alot of it might be unnecessary because im only reading in Fareheit and its been modified somewhat to get it where i wanted it to do that. It shows object and ambient temp of (1) IR sensor in Farenheit. Now i'm trying to get (2) IR sensors to display object only temp in F for IR1 and IR2 .