Why Mega is Slower than UNO to handle TFT ?

Hi everyone! Hope you all doing good :slight_smile:

I wrote a simple code which displays values of seven variables on a 3.5" TFT-LCD with integrated UNO-Shield (just like a UNO-TFT by MCUFriend). Everything is working perfect.

I have just one query. The code I wrote takes 160 milli-seconds when executed by UNO, but the same code takes 360 milli-seconds when executed by Mega 2560. It's more than double! Why is it so?

Same code, same LCD, but as soon as replace UNO with Mega, printing gets SLOW.....

(deleted)

Here is the code. Library is <MCUFRIEND_kbv.h>

#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;       // hard-wired for UNO shields anyway.

#include <Fonts/Redressed_Regular_25.h>

uint16_t ID;
uint8_t Orientation = 1; // ZERO or ONE

// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define MAGENTA 0xF81F
#define WHITE   0xFFFF

int i = 0;
long oldPosition  = -999;

uint16_t required_mL = 500, oldIntVal, intInput;
int16_t temp, encReading;

float setE = 2.0, oldFloatVal, floatInput;

float setInhalationTime = 1.3; // /Keep Initial Value always at one decimal place. I mean ACTUALY keep it! NO 1.33 or 1.333 sort of stuff.

uint16_t allowablePeakPressure = 30, setBPM = 15;

float setPEEP = 5.0;

int mL=required_mL, peakFlow=23, peakPressure=allowablePeakPressure, BPM=setBPM, pwm=255;
float E=setE, inhalationTime=setInhalationTime, PEEP=setPEEP;

unsigned long t;

bool indicator;


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

    
  tft.reset();
  ID = tft.readID();
  tft.begin(ID);
  tft.setRotation(Orientation);
  tft.fillScreen(BLACK);

  delay(100);
  
  tft.setFont(&Redressed_Regular_25); 
  
  tft.setTextColor(WHITE); //(textColor, HighLightColor)
  tft.setTextSize(3);
  tft.setCursor(25, 170); //(x, y) OR (horizontal, vertical)
  tft.print("Initialization");
  
  delay(2000);

  tft.setTextColor(BLACK); //(textColor, HighLightColor)
  tft.setCursor(25, 170); //(x, y) OR (horizontal, vertical)
  tft.print("Initialization");
  
  //_____________________________________________________________________
  // ____________________________________________________ Rectangles
  tft.fillRect(0,0, 150, 95, WHITE);  //(x0, y0, width, height, color)
  tft.fillRect(0,110, 150, 95, WHITE);
  tft.fillRect(0,220, 150, 95, WHITE);
  
  tft.fillRect(165,0, 150, 95, WHITE);
  tft.fillRect(165,110, 150, 95, WHITE);
  tft.fillRect(165,220, 150, 95, WHITE);

  tft.fillRect(330,0, 150, 95, WHITE);
  tft.fillRect(330,110, 150, 95, WHITE);
  tft.fillRect(330,220, 150, 95, WHITE);

  //_____________________________________________________________________
  // ____________________________________________________ Tidal Volume
  //tft.fillRect(0,0, 150, 95, WHITE);
  tft.setTextSize(1);
  tft.setCursor(33, 27);
  tft.print("Vt(mL)");
  
  tft.setTextSize(2);
  tft.setCursor(20, 80);
  tft.print(required_mL);

  // ____________________________________________________ I:E
  //tft.fillRect(0,110, 150, 95, WHITE);
  tft.setTextSize(1);
  tft.setCursor(58, 137);
  tft.print("I:E");

  tft.setTextSize(2);
  tft.setCursor(17, 190);
  tft.print("1:"); 
  tft.setCursor(52, 190);
  tft.print(setE, 1); 
  
  // ____________________________________________________ RR
  //tft.fillRect(0,220, 150, 95, WHITE);
  tft.setTextSize(1);
  tft.setCursor(20, 247);
  tft.print("RR(BPM)");

  tft.setTextSize(2);
  tft.setCursor(47, 300);
  tft.print(setBPM);

  //_____________________________________________________________________
  // ____________________________________________________ Ppeak
  //tft.fillRect(330,0, 150, 95, WHITE);
  tft.setTextSize(1);
  tft.setCursor(332, 27);
  tft.print("PIP(cmH2O)");

  tft.setTextSize(2);
  tft.setCursor(380, 80);
  tft.print(allowablePeakPressure);
  
  // ____________________________________________________ Ti
  //tft.fillRect(330,110, 150, 95, WHITE);
  tft.setTextSize(1);
  tft.setCursor(373, 137);
  tft.print("Ti(sec)");

  tft.setTextSize(2);
  tft.setCursor(375, 190);
  tft.print(setInhalationTime, 1);

  // ____________________________________________________ PEEP
  //tft.fillRect(330,220, 150, 95, WHITE);
  tft.setTextSize(1);
  tft.setCursor(377, 247);
  tft.print("PEEP");

  tft.setTextSize(2);
  tft.setCursor(375, 300);
  tft.print(setPEEP, 1);

  //_____________________________________________________________________
  // ____________________________________________________ PIF
  //tft.fillRect(165,0, 150, 95, WHITE);
  tft.setTextSize(1);
  tft.setCursor(180, 27);
  tft.print("PIF(LPM)");

  tft.setTextSize(2);
  tft.setCursor(215, 80);
  tft.print("00");
  
  pinMode(13, INPUT_PULLUP);
}


void loop()
{
    delay(1000);
    
    t = millis();
    printTFT();
    Serial.println(millis()-t);

}

// This takes 160 MILLI-seconds on Arduino-UNO
// And takes 362 MILLI-seconds on Mega :/
// It is more than double :/
void printTFT()
{
    // ____________________________________________________ Vt
    tft.fillRect(18,40, 115, 45, MAGENTA);
    tft.setCursor(20, 80);
    tft.print(mL);

    // ____________________________________________________ I:E
    tft.fillRect(50,150, 90, 45, MAGENTA);
    tft.setCursor(52, 190);
    tft.print(E, 1); 

    // ____________________________________________________ RR
    tft.fillRect(45,260, 80, 45, MAGENTA);
    tft.setCursor(47, 300);
    tft.print(BPM);
    
    // ____________________________________________________ PIF
    tft.fillRect(213, 40, 80, 45, MAGENTA);
    tft.setCursor(215, 80);
    tft.print(peakFlow);
    
    // ____________________________________________________ PIP
    tft.fillRect(378, 40, 80, 45, MAGENTA);
    tft.setCursor(380, 80);
    tft.print(peakPressure);

    // ____________________________________________________ Ti
    tft.fillRect(373, 150, 90, 45, MAGENTA);
    tft.setCursor(375, 190);
    tft.print(inhalationTime, 1);

    // ____________________________________________________ PEEP
    tft.fillRect(373,260, 90, 45, MAGENTA);
    tft.setCursor(375, 300);
    tft.print(PEEP, 1);
}

I had the same issue and was wondering the same thing, it is just as slow on a nano as on a mega. SPI is not used by the TFT-Touch (only by the SD that is also on the shield) It must have something to do with the ports or other layout things. Have you tried using any of the first 20 EEprom addresses, something funny happened for me when i did that as well, although there seems to be no reference to the EEprom anywhere in the library.

No, I didn't try that.

Kindly let me know if you find some answer for this :slight_smile: Thanks