LCD Displays weird characters (Using Mega + many SPI slave devices + LCD 16*2)

Hello everybody;
I'm using Arduino MEGA ( Chinese clone ) with two K-Type Thermocouples via MAX6675, to measure high temperature (+400° C), everything works fine, the only problem is after some time (between 5 to more than 10 minutes ) the LCD displays weird characters!
My questions are:

1- Is it because The MEGA is Chinese cheap clone?
2-Is using many SPI slave devices affect the Arduino timers in any way?
3-I'm using the latest LiquidCrystal library? I just found this in the LiquidCrystal.cpp

void LiquidCrystal::spiSendOut() //SPI #############################
{
  //just in case you are using SPI for more then one device
  //set bitOrder, clockDivider and dataMode each time
  SPI.setClockDivider(_clockDivider); 
  SPI.setBitOrder(_bitOrder);
  SPI.setDataMode(_dataMode); 
  
  digitalWrite(_latchPin, LOW);
  SPI.transfer(_bitString);
  digitalWrite(_latchPin, HIGH); 
}

How can I implement this ?!

Schematics: Sorry I don't have the tools to draw the circuit now but this is how I wire it:

LCD to mega:

RS--->8
E--->9
D4--->4
D5--->5
D6--->6
D7--->7

The Clock(Sck) and Serial output (So) are common for all slave devices

Sck--->52
So--->50

Thermocouple1
Cs1--->53

Thermocouple2
Cs1--->45

I'm using External Power (9v 2A), I checked the +5v Arduino with a multimeter, It gives 4.94v

My Code:

// Sample Arduino MAX6675 Arduino Sketch
#include <LiquidCrystal.h>
#include "max6675.h"

//LCD
const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

//Time
unsigned long start = 0;

//ThermoCouple 1
int ktcSO = 50;
int ktcCS1 = 53;
int ktcCLK = 52;

MAX6675 thermocouple1(ktcCLK, ktcCS1, ktcSO);

//ThermoCouple 2
//int ktcSO2 = 47;
int ktcCS2 = 45;
//int ktcCLK2 = 44;

MAX6675 thermocouple2(ktcCLK, ktcCS2, ktcSO);

void setup()
{
  lcd.begin(16, 2);
  delay(1000);
}

void loop()
{
  if (millis() - start >= 500)
  {
    start = millis();
    lcd.clear();
    lcd.print("T1 Air= ");
    lcd.print(thermocouple1.readCelsius());
    lcd.setCursor(0, 1);
    lcd.print("T2 Air= ");
    lcd.print(thermocouple2.readCelsius());
  }

}

Thank you :)))

A bare 16x2 LCD does not have an SPI interface. But you can give it one using a 74hc595 shift register. Fewer Arduino pins will be needed (not a big deal with a Mega) but it may simplify the wiring for you if you put the 74hc595 on a small board near to the LCD, because only 3 wires + 5V + GND will need to go back to the Mega.

You can buy pre-made "backpacks" for LCD modules, but most of these use the i2c bus, not the SPI bus. If that is not a problem, you could consider one of those backpacks.

As for your wierd characters, it sounds like interference is being picked up and corrupting the data between the LCD and the Mega. How long are the wires between them? What sources of interference could be around? Any device which can reach 400 degrees will probably have high power heating elements switched by a relay. That could be a source of interference when switching occurrs.

B1ng05:
1- Is it because The MEGA is Chinese cheap clone?

No. Why would it be? Almost all of the parts of any Arduino are made in China like any other piece of consumer equipment, only the assembly may vary.

B1ng05:
2-Is using many SPI slave devices affect the Arduino timers in any way?

Can't see why.

B1ng05:
3-I'm using the latest LiquidCrystal library? I just found this in the LiquidCrystal.cpp

void LiquidCrystal::spiSendOut() //SPI #############################

{
 //just in case you are using SPI for more then one device
 //set bitOrder, clockDivider and dataMode each time
 SPI.setClockDivider(_clockDivider);
 SPI.setBitOrder(_bitOrder);
 SPI.setDataMode(_dataMode);
 
 digitalWrite(_latchPin, LOW);
 SPI.transfer(_bitString);
 digitalWrite(_latchPin, HIGH);
}



How can I implement this ?!

I don't know. You seem to be connecting the LCD directly to the Arduino, so I don't see what SPI has to do with the LCD.

B1ng05:
I'm using External Power (9v 2A), I checked the +5v Arduino with a multimeter, It gives 4.94v

So just what are you using the (9v 2A) "External Power" for exactly? How are you powering all the 5 V devices? They will no doubt require more than the 100 mA or so that the regulator in the Mega can handle so you will need some way to provide reliable 5 V, and when you have a proper 5 V supply, it makes sense to use that to power the Mega as well via its 5 V pin.


Put a capacitor - 100 µF or so - directly between pins 1 and 2 of the LCD. By the way - and not related to your problem - a useful hint. You haven't mentioned pin 3 of the LCD and its potentiometer. Do not connect the 10k contrast potentiometer to 5 V - just leave that end unconnected (or tie it to the wiper).

This is a silly mistake that has become ingrained in hobby (and no doubt, some professional) designs since the "early days". Not connecting it makes contrast setting twice as easy! Using a 1k pot makes it even easier.

PaulRB: Thank you so much , I moved this problem to a new post , you can see the circuit and everything ! I changed the k thermocouple + max6675 (spi) to a simple thermistor :)))

https://forum.arduino.cc/index.php?topic=587410.new#new

Paul__B:
I tried the capacitor - 100 µF - the LCD failed to start only backlight is on , I took of the 10k Pot , the backlight was so bad , so I'm following what the datasheet says , and it's kinda working , I think it's because something else , anyways I create a new post with this problem included thx :))

https://forum.arduino.cc/index.php?topic=587410.new#new

I used 9v 2A , because that's all have now and I wanted to use Vin !