2.4 "TFT LCD Display. Errors in touch reading of display ID: 0x9797 / 0x1289.

Hi David! I recently purchased a 2.4 "TFT LCD Display from those who have a driver that returns a reading of ID = 0x9797 and that only works by setting the ID to 0x1289 (of the type that turns the entire screen green by running the standard version of the MCUFRIEND_kbv library). But thanks to its edited version of the MCUFRIEND_kbv library I was able to make it work correctly with all colors! I am now having trouble running the “button_simple” sample from the MCUFRIEND_kbv library (the touch is detected outside of the buttons!). I am asking you to correct these errors of touch reading would it be necessary to modify the MCUFRIEND_kbv library itself?

You have a Solomon SSD1297 controller.

My calibration results are:

const int XP=7,XM=A1,YP=A2,YM=6; //240x320 ID=0x9797
const int TS_LEFT=893,TS_RT=182,TS_TOP=858,TS_BOT=210;

So it looks like a very normal Mcufriend Shield.

I suggest that you run your own Calibration sketch. But if you are too idle, just copy-paste my calibration lines.


Thank you David! But the “button_simple” still did not work. I pasted the two lines that you sent and the result was what appears in the attached video (Touch.zip). I first touched the “touchScreen_Calibr_native” by changing only the ID to 0x1289 and the result was that of the “Calib_A” image. I ran “touchScreen_Calibr_native” a second time by changing the ID to 0x1289 and the line of variables XP, XM, YP and YM for “XP = 7, XM = A1, YP = A2, YM = 6” and the result was that of the image “Calib_B”. The “button_simple” did not work with any of the calibrations! What could be happening?

Touch.zip (806 KB)

Please do not post JPG of the screen.
Run the Calibration sketch with the Serial Terminal.

Copy-paste from the Serial Terminal directly to your message.

Your calibration results are wrong. If you post the Serial text, I can see what is going wrong.


Hello! I performed the calibration only by setting the ID to 0x1289 and the result shown on the serial monitor was this:

TouchScreen.h GFX Calibration
Making all control and bus pins INPUT_PULLUP
Typical 30k Analog pullup with corresponding pin
would read low when digital is written LOW
e.g. reads ~25 for 300R X direction
e.g. reads ~30 for 500R Y direction
Testing : (A1, D7) = 34
Testing : (A2, D6) = 28
Diagnosing as:-
YP,YM: (A1, D7) = 34
XM,XP: (A2, D6) = 28
ID = 0x9797
cx=437 cy=775 cz=177 LEFT, TOP, Pressure
cx=432 cy=681 cz=184 LEFT, MIDH, Pressure
cx=350 cy=458 cz=175 LEFT, BOT, Pressure
cx=541 cy=852 cz=175 MIDW, TOP, Pressure
cx=527 cy=451 cz=175 MIDW, BOT, Pressure
cx=708 cy=827 cz=178 RT, TOP, Pressure
cx=727 cy=637 cz=184 RT, MIDH, Pressure
cx=669 cy=513 cz=177 RT, BOT, Pressure
MCUFRIEND_kbv ID=0x9797 240 x 320
const int XP=6,XM=A2,YP=A1,YM=7; //240x320 ID=0x9797
const int TS_LEFT=392,TS_RT=714,TS_TOP=829,TS_BOT=462;
x = map(p.x, LEFT=392, RT=714, 0, 240)
y = map(p.y, TOP=829, BOT=462, 0, 320)
Touch Pin Wiring XP=6 XM=A2 YP=A1 YM=7
x = map(p.y, LEFT=829, RT=462, 0, 320)
y = map(p.x, TOP=714, BOT=392, 0, 240)

Interesting that I pasted the two lines that you sent me (const int XP = 7, XM = A1, YP = A2, YM = 6; // 240x320 ID = 0x9797 — const int TS_LEFT = 893, TS_RT = 182, TS_TOP = 858, TS_BOT = 210;) in the program code below and the touch worked perfectly (only with the “tft.setRotation ()” in “3” … in “1” showed error in the reading of the rings!). Strange the calibration example is reading erroneous values and the example of the “button_simple” does not work nor with the lines of code that you provided me …

#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
#include <TouchScreen.h>

#define SENHAVALIDA “01234”
#define MINPRESSURE 10
#define MAXPRESSURE 1000
#define PRETO 0x0000
#define VERMELHO 0xF800
#define VERDE 0x07E0
#define BRANCO 0xFFFF
//const int XP=7,XM=A1,YP=A2,YM=6; //240x320 ID=0x9797
//const int TS_LEFT=893,TS_RT=182,TS_TOP=858,TS_BOT=210;
#define XP 7
#define XM A1
#define YP A2
#define YM 6

#define TS_LEFT 893
#define TS_RT 182
#define TS_TOP 858
#define TS_BOT 210

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
Adafruit_GFX_Button botoes[12];
MCUFRIEND_kbv tft;

bool pressionado = false;
int posX;
int posY;
String senha = “”;

bool obterToque(void){

  • TSPoint p = ts.getPoint();*
  • pinMode(YP, OUTPUT); *
  • pinMode(XM, OUTPUT);*
  • digitalWrite(YP, HIGH); *
  • digitalWrite(XM, HIGH);*
  • bool pressed = (p.z > MINPRESSURE);*
  • if (pressed) {*
  • posX = map(p.x, TS_LEFT, TS_RT, 0, 320);*
  • posY = map(p.y, TS_TOP, TS_BOT , 0, 240);*
  • return true;*
  • }*
  • return false;*

void setup() {

  • //uint16_t ID = tft.readID();*
  • //tft.begin(ID);*
  • tft.begin(0x1289);*
  • tft.setRotation(3);*
  • telaInicial();*

void telaInicial(){

  • senha = “”;*

  • tft.fillScreen(PRETO);*

  • botoes[0].initButton(&tft, 60, 100, 30, 40, BRANCO, VERDE, PRETO, “1”, 2);*

  • botoes[1].initButton(&tft, 110, 100, 30, 40, BRANCO, VERDE, PRETO, “2”, 2);*

  • botoes[2].initButton(&tft, 160, 100, 30, 40, BRANCO, VERDE, PRETO, “3”, 2);*

  • botoes[3].initButton(&tft, 210, 100, 30, 40, BRANCO, VERDE, PRETO, “4”, 2);*

  • botoes[4].initButton(&tft, 260, 100, 30, 40, BRANCO, VERDE, PRETO, “5”, 2);*

  • botoes[5].initButton(&tft, 60, 150, 30, 40, BRANCO, VERDE, PRETO, “6”, 2);*

  • botoes[6].initButton(&tft, 110, 150, 30, 40, BRANCO, VERDE, PRETO, “7”, 2);*

  • botoes[7].initButton(&tft, 160, 150, 30, 40, BRANCO, VERDE, PRETO, “8”, 2);*

  • botoes[8].initButton(&tft, 210, 150, 30, 40, BRANCO, VERDE, PRETO, “9”, 2);*

  • botoes[9].initButton(&tft, 260, 150, 30, 40, BRANCO, VERDE, PRETO, “0”, 2);*

  • botoes[10].initButton(&tft, 85, 200, 80, 40, BRANCO, VERDE, PRETO, “Acesso”, 2);*

  • botoes[11].initButton(&tft, 235, 200, 80, 40, BRANCO, VERDE, PRETO, “Apagar”, 2);*

  • for (int i=0; i<12; i++){*
    _ botoes*.drawButton(false);_


void TeclaPressionada(bool teclaTocada){
* for (int i=0; i<12; i++){*
botoes_.press(teclaTocada && botoes*.contains(posX,posY));


void checkPressedButton(){
* for (int i=0; i<12; i++){*
_ if (botoes*.justPressed()){

void esperaSoltar(){
* while (obterToque()){*
* delayMicroseconds(50);*
* }*


void escreveSenha(){
* tft.fillRect(70, 30, 190, 30, BRANCO);*
* tft.setCursor(74,35);*
* tft.setTextColor(PRETO);*
* tft.setTextSize(3);*
* tft.print(senha+"");*

void apagarUltimocaractere(){
* if (senha.length()>0){*
* senha.remove (senha.length () - 1);*
* }*
void checkPressed(int button){
* botoes[button].drawButton(true);*
* esperaSoltar();*
* botoes[button].drawButton();*
* if(senha.length()<TAMANHOMAXSENHA || button == 10 || button == 11){*
* switch (button){*
* case 0:*
* senha = senha + “1”;*
* break;*
* case 1:*
* senha = senha + “2”;*
* break;*
* case 2:*
* senha = senha + “3”;*
* break;*
* case 3:*
* senha = senha + “4”; *
* break;*
* case 4:*
* senha = senha + “5”;*
* break;*
* case 5:*
* senha = senha + “6”;*
* break;*
* case 6:*
* senha = senha + “7”;*
* break;*
* case 7:*
* senha = senha + “8”;*
* break;*
* case 8:*
* senha = senha + “9”;*
* break;*
* case 9:*
* senha = senha + “0”;*
* break;*
* case 10:*
* validarAcesso();*
* break;*
* case 11:*
* apagarUltimocaractere();*
* break; *
* }*
* escreveSenha();*
* }*

void validarAcesso(){

* if (senha == SENHAVALIDA){*
* tft.fillScreen(PRETO);*
* tft.setCursor(10,100);*
* tft.setTextColor(VERDE);*
* tft.setTextSize(3);*
* tft.print(“Acesso Autorizado”);*
* delay(3000);*
* telaInicial();*
* }*
* else{ // Caso contrário*
* tft.fillScreen(PRETO);*
* tft.setCursor(40,100);*
* tft.setTextColor(VERMELHO);*
* tft.setTextSize(3);*
* tft.print(“Acesso Negado”);*
* delay(3000);*
* telaInicial();*
* }*


void loop() {
* bool toque = obterToque();*
* TeclaPressionada(toque);*

Please read the How to Use the Forum advice. It shows you how to post code in a “Code Window”.

I presume that you are using the current Beta library from GitHub. Enable #define SUPPORT_1289

This recognises both 0x1289 and 0x9797 with ID = tft.readID(); and tft.begin(ID);

Your Calibration results are just WRONG. I suggest that you copy-paste my Calibration to the Touch_shield_new.ino example.

Press the stylus at different points on the screen e.g. at left, right, top, bottom. Observe the values reported.

Then press the stylus in the middle i.e. EXIT button.

Then draw the stylus on the screen. The coloured spot should follow perfectly.
If it does not follow the stylus your screen is unreliable for Touch programs. Buy a replacement screen.

Now edit the value of “Orientation”. Run the sketch in LANDSCAPE, PORTRAIT_REV, LANDSCAPE_REV mode. You will see that the Touch always returns the PORTRAIT values. i.e. TOP is edge near the push-button.

Study the code in Touch_shield_new.ino e.g.

    if (tp.z > MINPRESSURE && tp.z < MAXPRESSURE) {
        // most mcufriend have touch (with icons) that extends below the TFT
        // screens without icons need to reserve a space for "erase"
        // scale the ADC values from ts.getPoint() to screen values e.g. 0-239
        // Calibration is true for PORTRAIT. tp.y is always long dimension 
        // map to your current pixel orientation
        switch (Orientation) {
            case 0:
                xpos = map(tp.x, TS_LEFT, TS_RT, 0, tft.width());
                ypos = map(tp.y, TS_TOP, TS_BOT, 0, tft.height());
            case 1:
                xpos = map(tp.y, TS_TOP, TS_BOT, 0, tft.width());
                ypos = map(tp.x, TS_RT, TS_LEFT, 0, tft.height());
            case 2:
                xpos = map(tp.x, TS_RT, TS_LEFT, 0, tft.width());
                ypos = map(tp.y, TS_BOT, TS_TOP, 0, tft.height());
            case 3:
                xpos = map(tp.y, TS_BOT, TS_TOP, 0, tft.width());
                ypos = map(tp.y, TS_LEFT, TS_RT, 0, tft.height());

Oops. I have just noticed an error in the LANDSCAPE_REV case. It should be:

          case 3:
                xpos = map(tp.y, TS_BOT, TS_TOP, 0, tft.width());
                ypos = map(tp.x, TS_LEFT, TS_RT, 0, tft.height());   //corrected tp.x

Please ask if you do not understand something.


Hi David! I’ve done all the tests you suggested to me. I downloaded version 2.9.8 of the library MCUFRIEND_kbv (IDE Library’s Manager) and the display turned green. So I downloaded here from a forum post a version edited by you (attached) and the colors worked correctly. I’ve enabled #define SUPPORT_1289 and none of the examples worked (screen is only dark). The programs are only working by forcing “tft.begin (0x1289)” and with the library downloaded here from the forum! I pasted his calibration suggestion in the “Touch_shield_new.ino” example and he behaved very strangely when I drew with the pen on the screen (see attached video!). All the files I’ve used are attached.

This is the information displayed in the Serial Monitor for the “Touch_shield_new_edited.ino” (version of “Touch_shield_new.ino” with the changes I mentioned).

Most Touch Screens use pins 6, 7, A1, A2
But they can be in ANY order
e.g. right to left or bottom to top
or wrong direction
Edit name and calibration statements

Please Calibrate.
Screen is 240x320
Calibration is: 
LEFT = 893 RT  = 182
TOP  = 858 BOT = 210
Wiring is always PORTRAIT
YP=16 XM=15
YM=6 XP=7

MCUFRIEND_kbv.cpp (120 KB)

MCUFRIEND_kbv.h (3.67 KB)

Touch_shield_new_edited.ino (7.79 KB)

New_Test_mpg.mpg (1.68 MB)

I write a long reply. Send it. And the Forum asks me to "sign in". Losing my reply. Grrr.

Thanks for the MPG file. It shows that your Touch is "working" but your X, Y pins are different to my shield.

My Calibration is:

const int XP=7,XM=A1,YP=A2,YM=6; //240x320 ID=0x9797
const int TS_LEFT=893,TS_RT=182,TS_TOP=858,TS_BOT=210;

Please try changing the X, Y pins:

const int XP=6,XM=A2,YP=A1,YM=7; //240x320 ID=0x9797
const int TS_LEFT=893,TS_RT=182,TS_TOP=858,TS_BOT=210;

Move the stylus horizontally. If backwards, swap TS_LEFT, TS_RT
Move the stylus vertically. If backwards, swap TS_TOP, TS_BOT

Normally the Calibration sketch would diagnose X, Y correctly. And calculate LEFT, RT correctly.

I presume that you downloaded the Beta from GitHub as a ZIP. Then "Installed from ZIP"
This probably placed the library in a directory called Mcufriend_kbv-master
The Library Manager installs a Release in a directory called Mcufriend_kbv

Make sure that you only have a single directory.

You only need to edit one line i.e.
Remove the // from the //#define SUPPORT_1289 line in the CPP file.

If you have made any "extra" changes, please say so. I do not want to search your attached files. Especially if there are no extra changes.


Hi David!

First of all I want to inform you that after your last suggestions I was able to make “Touch_shild_new.ino” work perfectly and also make the MCUFRIEND_kbv library automatically identify my controller (just enable the “# define SUPPORT_1289” line without having to manually set the ID to 0x1289)!

The example “Touch_shild_new.ino” worked with the parameters below and changing “TS_LEFT” to “TS_RT”!

const int XP=6,XM=A2,YP=A1,YM=7; //240x320 ID=0x9797
const int TS_LEFT=182,TS_RT=893,TS_TOP=858,TS_BOT=210;

The driver identification problem was solved by downloading the “MCUFRIEND_kbv-master” library directly from GitHub.

Previously I was using outdated versions of “MCUFRIEND_kbv” obtained directly from the “IDE Arduino 1.8.8” library manager (does not identify ID and screen turns green / see attached image) and the link “https://github.com/prenticedavid/MCUFRIEND_kbv/files/2511227/ MCUFRIEND_kbv.zip” (it does not identify the ID, but the colors work).

Thank you very much for your endeavor to help solve the problems of my TFT LCD! I learned a lot from your suggestions!