2.4 TFT LCD MCUfriend characters at same place mixed(overlap)

Hello guys and girls.

Based on my experience, I have a little problem with 2.4inch MCUfriend shield sticked in Arduino Mega 2560.
All dynamic values (e.g.analog read, or time from PCF8563 and other) are displayed over previous value - mixed pixels with previous.

I don’t know, what is the problem …
I have used last Adafruit_GFX library (but previous version was the same).
Also I have used Adafruit TFTLCD library (same as previous)
Both from github.

Here is a code :

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
#include <SD.h>
#include <SPI.h>
#include <Rtc_Pcf8563.h>
#include <Wire.h>

#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
#define SD_CS 53 // Card select for shield use


#define YP A1  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 7   // can be a digital pin
#define XP 6   // can be a digital pin

#define   BLACK   0x0000
#define   BLUE    0x001F
#define   RED     0xF800
#define   GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define GREY    0x7BEF

#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
uint8_t spi_save;

Rtc_Pcf8563 rtc;

void setup() {
  Serial.begin(9600);
  uint16_t identifier = tft.readID();
  identifier = 0x9341;
  tft.begin(identifier);
  tft.setRotation(3);
 
tft.fillScreen(BLACK);
tft.drawRect(2, 2, 310, 230, WHITE); 
  tft.setCursor(35, 10);
  tft.setTextColor(YELLOW);  tft.setTextSize(2);
  tft.println("ClimaTech air system");
 tft.drawLine(2, 35, 310, 35, WHITE);
tft.setCursor(15, 75);
  tft.println("Act.temp :");
  tft.setCursor(250, 65);
  tft.println(".");
  tft.setCursor(260, 75);
  tft.println("C");
  tft.setCursor(15, 95);
  tft.println("Set.temp :");
  tft.setCursor(190, 95);
  tft.println("");
  tft.setCursor(250, 85);
  tft.println(".");
tft.setCursor(260, 95);
  tft.println("C");
    tft.setCursor(15, 115);
  tft.println("Out.temp :");
  tft.setCursor(250, 105);
  tft.println(".");
tft.setCursor(260, 115);
  tft.println("C");
  tft.setCursor(15, 135);
  tft.println("Out.humidity :");
tft.setCursor(260, 135);
  tft.println("%");
}// setup

void loop() {
 
 
   tft.setCursor(15, 45);
  tft.setTextColor(WHITE); tft.setTextSize(2);
  tft.println(rtc.formatTime(RTCC_TIME_HMS));
  tft.setCursor(180,45);
   tft.println(rtc.formatDate(RTCC_DATE_WORLD));

 
}//loop

Thanks for all helping. Bobo

It looks as if you are drawing white text on a black screen. A bit of a waste of the 65536 colours at your disposal !

In loop() you should call tft.fillRect() with black to clear the specific area that you are writing the new text to.

I note that you are ignoring the result of tft.readID(). I can only assume that it actually does report 0x9341. Otherwise your display would never work at all.

David.

p.s. where did you buy your 2.4" display with ILI9341 controller? I would like to buy one with this particular chip.

Hi David

I bought it on DealExtreme page. Here you have some others to order.

Thanks a lot for your idea with FillRect. But I have little bit complicated script and after I have added it, the time from PCF board is now blinking.

I must review whole script to modifying it.

Bobo

Press ctrl-T. This will indent your code nicely.

Your program stucture looks fine to me. Ok, I am a little happier with printf() style formatting, but you can write a helper function that takes x, y, msg, value. This makes a program easier to write and maintain.

Of course it upsets C++ purists. But hey-ho, there is a good argument for using whatever keeps you comfortable.

I have ordered a "shield + Uno" from DX. I will keep my fingers crossed that it comes with the ILI9341. The individual shields look as if they use different controllers (from the photos of the pcb).

David.

Try this example:

#include <Adafruit_GFX.h> 
#include <Adafruit_TFTLCD.h>

#define LCD_CS A3 
#define LCD_CD A2 
#define LCD_WR A1 
#define LCD_RD A0 
#define LCD_RESET A4 

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

char TX[50];  

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

#ifdef USE_ADAFRUIT_SHIELD_PINOUT
  Serial.println(F("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
#else
  Serial.println(F("Using Adafruit 2.8\" TFT Breakout Board Pinout"));
#endif

  Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());
  tft.reset();
  uint16_t identifier = tft.readID();

  if(identifier == 0x9325) {
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if(identifier == 0x9328) {
    Serial.println(F("Found ILI9328 LCD driver"));
  } else if(identifier == 0x7575) {
    Serial.println(F("Found HX8347G LCD driver"));
  } else if(identifier == 0x9341) {
    Serial.println(F("Found ILI9341 LCD driver"));
  } else if(identifier == 0x8357) {
    Serial.println(F("Found HX8357D LCD driver"));
  } else {
    Serial.print(F("Unknown LCD driver chip: "));
    Serial.println(identifier, HEX);
    Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
    Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
    Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
    Serial.println(F("Also if using the breakout, double-check that all wiring"));
    Serial.println(F("matches the tutorial."));
    return;
  }

  tft.begin(identifier);
  tft.setRotation(3);
  tft.fillScreen(BLACK);

  tft.setCursor(0, 0);
  tft.setTextColor(WHITE, BLACK);  tft.setTextSize(4);
  tft.println("Hello World!");

  Serial.println(F("Done!"));
  Temp();
}


void Temp()
{
 do    
  {    
     int T = random(90,110);
     sprintf(TX,"%3d", T);

     tft.setCursor(100, 50); 
     tft.setTextColor(YELLOW, BLACK);  tft.setTextSize(3);
     tft.println(TX);     
     delay(500);
  }
 while(1);     
}  

void loop(){}

This lines are “the core-lines”:

char TX[50];
sprintf(TX,"%3d", T);

     tft.setCursor(85, 50); 
     tft.setTextColor(YELLOW, BLACK);  tft.setTextSize(3);
     tft.println(TX);

The full structure of the instruction is:

tft.setTextColor(text color, Background text color);

Another example, if you want to draw numbers like XXX.XX; study this function:

void Temp3()
{
 do    
  {    
     int T = random(90,110);
     sprintf(TX,"%3d C", T);
     tft.setCursor(137, 50); 
     tft.setTextColor(YELLOW, BLACK);  tft.setTextSize(3);
     tft.println(TX);   
   
   
     int TDInt = random(95,115);
     int fracc = random (0,99);
     sprintf(TX,"%3d.%02d C", TDInt, fracc);
     tft.setCursor(85, 100); 
     tft.setTextColor(YELLOW, BLACK);  tft.setTextSize(3);
     tft.println(TX);           
     
     delay(500);
  }
 while(1);   
}

Code in action

Code

Enjoy it!