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.
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.
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.
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.
#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 .