3.5" TFT LCD shield and MCUFRIEND_kbv

I have a new 3.5" TFT LCD shield plugged into a Mega 2560. I am using the MCUFRIEND_kbv library and have a problem with calibrating the LCD. The problem is one of the corners of the LCD is not sensitive to touch within the square with the crosshair so the calibration cannot proceed normally.

I tried cheating the sketch and touched outside the square for the problem corner. All other squares worked as expected and the calibration completed.

I tried loading .bmp files from an SD card and the button_simple example and they worked just fine.

I then created a 4-button sketch (much like the button_simple example) with 4 large buttons that fill the screen. Here is where I ran into problems. For some reason all of the buttons sometimes report a touch of the button that is at the problem corner of the LCD, even though that button was not touched.

Do I just have a bad LCD shield or is there something else I should be looking at?

Please post a link to the actual Shield you have bought.

Yes, some Touch panels don't work in one corner. It is not much good to anyone if we don't know which Shield or which corner. Or what size area is missing. e.g. from Paint section of TouchShield example.

You can always paste the Serial output from the Calibration sketch.

David.

Hi David. Thanks for replying.

Here is the shield that I bought: 3.5" TFT LCD Touch Screen Module for Arduino in Canada Robotix

The corner with the problem is at the top left, near the barrel jack connector on the Mega. It's the location of the first crosshair in the calibration sketch.

The size of the area is difficult to show with the paint sketch as the canvas resets when trying to color in that corner. I would say the problem area is slightly larger than the size of the square in the calibration sketch.

Here is the Serial output from the calibrations sketch:

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 : (A2, D8) = 22
Testing : (A3, D9) = 33
ID = 0x9486

cx=167 cy=899 cz=208 X, Y, Pressure
cx=146 cy=523 cz=389 X, Y, Pressure
cx=139 cy=111 cz=550 X, Y, Pressure
cx=515 cy=941 cz=283 X, Y, Pressure
cx=514 cy=111 cz=544 X, Y, Pressure
cx=904 cy=949 cz=413 X, Y, Pressure
cx=891 cy=528 cz=470 X, Y, Pressure
cx=900 cy=109 cz=618 X, Y, Pressure

*** COPY-PASTE from Serial Terminal:
const int XP=8,XM=A2,YP=A3,YM=9; //320x480 ID=0x9486
const int TS_LEFT=125,TS_RT=922,TS_TOP=946,TS_BOT=92;

PORTRAIT CALIBRATION 320 x 480
x = map(p.x, LEFT=125, RT=922, 0, 320)
y = map(p.y, TOP=946, BOT=92, 0, 480)

LANDSCAPE CALIBRATION 480 x 320
x = map(p.y, LEFT=946, RT=92, 0, 480)
y = map(p.x, TOP=922, BOT=125, 0, 320)

I have a similar Blue Shield but it has a ST7796 controller instead of your ILI9486 controller.
When I run the Calibration sketch it is the bottom-right cross-hair that is difficult.
The stylus does not respond on the actual cross-hair. It does work on the top-left corner of the bottom-right box.
In other words if you have a "missing" corner just move your stylus slightly away from the cross-hair.

This is my calibration. Note that my pins are the same as yours. The Touch values are similar but "backwards". i.e. my Touch panel is wired 180 degrees compared to yours.

*** COPY-PASTE from Serial Terminal:
const int XP=8,XM=A2,YP=A3,YM=9; //320x480 ID=0x7796
const int TS_LEFT=920,TS_RT=120,TS_TOP=62,TS_BOT=938;

If I run the Calibration in Landscape mode the difficult corner is (logical) top-right. But I still get the "same" Calibration

const int TS_LEFT=914,TS_RT=123,TS_TOP=64,TS_BOT=937;

I ran the Calibration on an old Red ILI9488 Shield: No blind corners at all.

const int XP=6,XM=A2,YP=A1,YM=7; //320x480 ID=0x9488
const int TS_LEFT=881,TS_RT=179,TS_TOP=945,TS_BOT=209;

Note that Touch panels vary greatly, i.e. pin wiring and left-right values.

Your description of your blind spot seems to be 10mm x 10mm on the (physical) top left. i.e. the RED box in the Paint section. I would expect the spot to follow your stylus everywhere.

The obvious advice is : do not put small buttons in that 10mm x 10mm corner.
But a 20mm x 20 mm button would "work" because it covers a larger area.

The other solution is to use PORTRAIT_REV rotation (2). Then your logical button is drawn in a different physical position.

I don't own a Blue ILI9486 Shield. Do other readers have the same "blind corner" ?

David.

Thanks David.

That's what I did initially, I just moved the stylus until it registered a touch and proceeded with the calibration. When I ran into trouble with the button sketch later on I assumed it had something to do with the calibration problems.

I modified your button_simple example to create 4 buttons on the display. Button 1 is near the corner with the problem but is quite large so it does work normally. The problem is that buttons 2, 3, and 4 only work about 80% of the time. The other 20% of the time they register a touch on button 1. I also get the same result when I try this with the button_list example. Here is the code:

#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
#define MINPRESSURE 200
#define MAXPRESSURE 1000

// ALL Touch panels and wiring is DIFFERENT
// copy-paste results from TouchScreen_Calibr_native.ino
const int XP=8,XM=A2,YP=A3,YM=9; //320x480 ID=0x9486
const int TS_LEFT=125,TS_RT=922,TS_TOP=946,TS_BOT=92;

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

Adafruit_GFX_Button btn1, btn2, btn3, btn4;

int pixel_x, pixel_y;     //Touch_getXY() updates global vars
bool Touch_getXY(void)
{
    TSPoint p = ts.getPoint();
    pinMode(YP, OUTPUT);      //restore shared pins
    pinMode(XM, OUTPUT);
    digitalWrite(YP, HIGH);   //because TFT control pins
    digitalWrite(XM, HIGH);
    bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
    if (pressed) {
        pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); //.kbv makes sense to me
        pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
    }
    return pressed;
}

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

void setup(void)
{
    Serial.begin(9600);
    uint16_t ID = tft.readID();
    Serial.print("TFT ID = 0x");
    Serial.println(ID, HEX);
    Serial.println("Calibrate for your Touch Panel");
    if (ID == 0xD3D3) ID = 0x9486; // write-only shield
    tft.begin(ID);
    tft.setRotation(0);            //PORTRAIT
    tft.fillScreen(BLACK);
    btn1.initButton(&tft, 80, 120, 140, 220, WHITE, WHITE, BLACK, "1", 2);
    btn2.initButton(&tft, 80, 360, 140, 220, WHITE, WHITE, BLACK, "2", 2);
    btn3.initButton(&tft, 240, 120, 140, 220, WHITE, WHITE, BLACK, "3", 2);
    btn4.initButton(&tft, 240, 360, 140, 220, WHITE, WHITE, BLACK, "4", 2);
    btn1.drawButton(false);
    btn2.drawButton(false);
    btn3.drawButton(false);
    btn4.drawButton(false);
}

void loop(void)
{
    bool down = Touch_getXY();
    btn1.press(down && btn1.contains(pixel_x, pixel_y));
    btn2.press(down && btn2.contains(pixel_x, pixel_y));
    btn3.press(down && btn3.contains(pixel_x, pixel_y));
    btn4.press(down && btn4.contains(pixel_x, pixel_y));
    if (btn1.justReleased())
        btn1.drawButton();
    if (btn2.justReleased())
        btn2.drawButton();
    if (btn3.justReleased())
        btn3.drawButton();
    if (btn4.justReleased())
        btn4.drawButton();
    if (btn1.justPressed()) {
        btn1.drawButton(true);
        Serial.println("1");
    }
    if (btn2.justPressed()) {
        btn2.drawButton(true);
        Serial.println("2");
    }
    if (btn3.justPressed()) {
        btn3.drawButton(true);
        Serial.println("3");
    }
    if (btn4.justPressed()) {
        btn4.drawButton(true);
        Serial.println("4");
    }
   
}

your buttons overlap.
e.g. btn1 top left corner is 10,10 and bottom rt is 150, 330
e.g. btn2 top left corner is 10,250 and bottom rt is 150, 470

Look at Adafruit_GFX.h. Regular buttons are located by the centre.
There is a different init() for buttons located by their top-left.

But surely you see the buttons when they are drawn on te screen.

David.

I think you added some extra pixels - btn1 bottom right is at 150, 230. The top right of btn2 is at 150, 250.
I think a picture will help clear it up!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.