LCD displaying Serial Monitor ERROR

I’m wanting my Thermocoupler temp to show up on my LCD screen and based off the temp (IF/ELSE) a really will turn on or off. The relay is turning off and on fine, the thermocoupler reads perfect… But I can’t get the serial monitor to display on my LCD screen for anything… I can get the stuff in the void setup to show up, but the void loop displays a blank LCD screen. I’d like for the temp to display constantly and update every 1 sec or so…

disclaimer… I’ve tried about 10 different sample codes trying to fix it so what you see is probably a combination of them all… :o

Any help is greatly appreciated!

/*-----( Import needed libraries )-----*/
#include <Wire.h>  // Comes with Arduino IDE
// Get the LCD I2C Library here:
// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
// Move any other LCD libraries to another folder or delete them
// See Library "Docs" folder for possible commands etc.
#include <LiquidCrystal_I2C.h>

/*-----( Declare Constants )-----*/
/*-----( Declare objects )-----*/
// set the LCD address to 0x27 for a 16 chars 2 line display
// A FEW use address 0x3F
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

/*-----( Declare Variables )-----*/
//NONE

#include <max6675.h>


// ThermoCouple
int thermo_gnd_pin = 45;
int thermo_vcc_pin = 47;
int thermo_so_pin  = 9;
int thermo_cs_pin  = 10;
int thermo_sck_pin = 11;
int relayPin = 5;  // Pin of Relay Module

MAX6675 thermocouple(thermo_sck_pin, thermo_cs_pin, thermo_so_pin);
  
void setup() {
  Serial.begin(9600);

  pinMode(thermo_vcc_pin, OUTPUT); 
  pinMode(thermo_gnd_pin, OUTPUT); 
  digitalWrite(thermo_vcc_pin, HIGH);
  digitalWrite(thermo_gnd_pin, LOW);
pinMode(relayPin, OUTPUT);  // Set Pin connected to Relay as an OUTPUT
  digitalWrite(relayPin, LOW);  // Set Pin to LOW to turn Relay OFF

   lcd.begin(16, 2);  // initialize the lcd for 16 chars 2 lines, turn on backlight

   Serial.begin(9600);

  // ------- Quick 3 blinks of backlight  -------------
  for (int i = 0; i < 3; i++)
  {
    lcd.backlight();
    delay(250);
    lcd.noBacklight();
    delay(250);
  }
  lcd.backlight(); // finish with backlight on

   //-------- Write characters on the display ------------------
  // NOTE: Cursor Position: (CHAR, LINE) start at 0
  lcd.setCursor(0, 0); //Start at character 4 on line 0
  lcd.print("Barrel Stoker");
  delay(1000);
  lcd.setCursor(0, 1);
  lcd.print("temperature");
  delay(1000);
  lcd.clear();

  // Wait and then tell user they can start the Serial Monitor and type in characters to
  // Display. (Set Serial Monitor option to "No Line Ending")
  }

void loop() {
  Serial.print("temperature ");
  Serial.println(thermocouple.readFarenheit());
  
  delay(1000);
  
char TestData;

  TestData = Serial.read();
  
int tempsens = thermocouple.readFahrenheit();

 if(tempsens<=  75)
  {
     digitalWrite(relayPin, LOW);  // Turn Relay OFF
     
     lcd.setCursor(0, 1);
  lcd.print(TestData);
       }
  else if( tempsens > 75)
  {
    digitalWrite(relayPin, HIGH);  // Turn Relay ON
    lcd.setCursor(0, 1);
  lcd.print(TestData);
  }
}

When things aren't working, I strip the sketch down to the basics.

Write a sketch to take something from the Serial Monitor and write to the LCD.

Once you get that working, add the thermocouple.

You are not checking to see if characters are available before calling read()
read() is non blocking and returns an int.
If the value is less than zero there is no data.
If the value is >= 0 then the lower 8 bits is the read data.

If you call read() and there are no characters available, -1 is returned and if using an 8 bit variable like a chare, 0xff will be assigned.

I am assuming you only ever intend to send a single character to the LCD as you are setting the LCD cursor to the same position every time (beginning of 2nd line) just before you print a character.

As the code is now, it will write each individual character it reads from the serial port to that single position on the LCD, but also write the character 0xff to the same position whenever there is no data in the receive buffer to read.
Probably not what you were wanting.

— bill

Fixed it… I just called the data like this… thermocouple.readFarenheit()

void loop() {
Serial.print("temperature ");
Serial.println(thermocouple.readFarenheit());

delay(1000);

char TestData;

TestData = Serial.read();

int tempsens = thermocouple.readFahrenheit();

if(tempsens<= 270) //SMOKER temp lower than 270* turn on fan
{
digitalWrite(relayPin, HIGH); // Turn Relay ON

lcd.setCursor(0, 0);
lcd.print(thermocouple.readFarenheit()); //lcd screen shows temp
lcd.setCursor(0, 2);
lcd.print("Fan ON ");

}
else if( tempsens > 270) //smoker temp above 270* leave fan off
{
digitalWrite(relayPin, LOW); // Turn Relay OFF
lcd.setCursor(0, 0);
lcd.print(thermocouple.readFarenheit()); //lcd screen shows temp
lcd.setCursor(0, 2);
lcd.print("Fan OFF ");

}
}

A couple of things.
That really didn't fix the original issue as the new code still has the same issue reading the serial port.
The difference is that it doesn't use the return status from Serial.read() anymore.
That is a significant change.
Since the return value from Serial.read() isn't used anymore, why even call Serial.read() ?

Also the way the code is currently written, the temperature value you print on the Serial port and on the LCD may not the same as the value you use when doing the comparison.
You initially read and print the value of the temperature on the serial port, wait 1 second then read the temperature into a variable for comparison, but then when you print the temperature you re-read the value.
You may want to print the variable instead of re-reading the temperature to ensure that there is never a difference.

If you want to keep all the values the same, then I'd recommend that you first read temperature into the variable, then use that that for all your printing and comparisons.
This will ensure that temperature is the same for all operations.
You also may want to move the delay to the bottom of the loop to avoid a delay between printing to the serial port and the LCD.
The current delay after the serial port read could cause the latest value shown on the serial port and the LCD to be different, should the temperature change in that 1 second.

One final thing to consider is that you may not want the on and off temperature to be a rigid single temperature.
Most thermostat type controls do not work this way.
They have built in hysteresis.
This ensures that things don't turn off/on rapidly during the transition between the temperature set point.
i.e. when the temperature is right at the set point, the fan may turn on and back off again in a short period of time.
With hysteresis, a fan might come on at say 270, but then once on, not turn on off until the temperature drops down to 265.
The off to on temperature is different is than the on to off temperature.
Not sure if it matters for your application but just something to consider.

--- bill