Button_simple not working on 3.5" TFT (MEGA)

Hi everyone,
This is my first post on an Arduino forum, so if my post isn’t at the right spot just let me know :slight_smile: I’m currently working on a oxygen concentrator program. I’m now on the stage of building and programming the TFT interface. I’m using a 3.5in TFT touchscreen with a Arduino Mega 2650. The button simple (MCUFRIEND.kbv) program is not working. It is dispaying the buttons. But nothing happens when i click on them. I tried to find online for hours and all i could find either wasn’t what i wanted to do or didn’t work… If anybody would be so kind to help me, it would be awesome!

Post a link to the actual Shield that you bought.
Install MCUFRIEND_kbv via IDE Library Manager

Run all the example sketches.
Make notes of any problem(s)

Then quote which example sketch(es) by name.

Copy-paste the output from the Serial Terminal in TouchScreen_Calibr_native.ino


I'm a PLC programmer and I've never used an Arduino before so please bear with me.

  1. Link to the shield I bought-

  2. I already installed MCUFRIEND.kbv

  3. Warnings by running button_simple.

C:\Users\Admin\Documents\Arduino\libraries\MCUFRIEND_kbv-2.9.8\examples\button_simple\button_simple.ino: In function 'void setup()':
C:\Users\Admin\Documents\Arduino\libraries\MCUFRIEND_kbv-2.9.8\examples\button_simple\button_simple.ino:55:75: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
on_btn.initButton(&tft, 60, 200, 100, 40, WHITE, CYAN, BLACK, "ON", 2);
C:\Users\Admin\Documents\Arduino\libraries\MCUFRIEND_kbv-2.9.8\examples\button_simple\button_simple.ino:56:77: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
off_btn.initButton(&tft, 180, 200, 100, 40, WHITE, CYAN, BLACK, "OFF", 2);
Sketch uses 22152 bytes (8%) of program storage space. Maximum is 253952 bytes.
Global variables use 536 bytes (6%) of dynamic memory, leaving 7656 bytes for local variables. Maximum is 8192 bytes.

  1. Output after calibration TouchScreen_Calibr_native.ino

MCUFRIEND_kbv ID=0x9486 320 x 480

x = map(p.x, LEFT=751, RT=748, 0, 320)
y = map(p.y, TOP=394, BOT=389,0 480)

Touch Pin Wiring XP=8 XM=A2 YP=A3 YM=9

x = map(p.y, LEFT=394, RT=389, 0, 480)
y = map(p.y, TOP=748, BOT=751,0 320)

Thank you for swift reply.

Your duplicate post has been deleted

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a timeout from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Please install / upgrade MCUFRIEND_kbv via IDE Library Manager

Your "Serial Terminal output" does not look like the current library version.

Regarding duplicate posts. Sometimes you make a mistake.
Edit the "wrong" post to give a link to the "correct Forum post"


Updated MCUFRIEND_kbv

OUTPUT after Calibration

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) = 23
Testing : (A3, D9) = 33
Diagnosing as:-
XM,XP: (A2, D8) = 23
YP,YM: (A3, D9) = 33
ID = 0x9486

cx=508 cy=940 cz=283 LEFT, TOP, Pressure
cx=871 cy=937 cz=410 LEFT, MIDH, Pressure
cx=871 cy=527 cz=518 LEFT, BOT, Pressure
cx=871 cy=123 cz=648 MIDW, TOP, Pressure
cx=507 cy=114 cz=576 MIDW, BOT, Pressure
cx=139 cy=112 cz=588 RT, TOP, Pressure
cx=134 cy=529 cz=384 RT, MIDH, Pressure
cx=138 cy=841 cz=162 RT, BOT, Pressure
MCUFRIEND_kbv ID=0x9486 320 x 480

const int XP=8,XM=A2,YP=A3,YM=9; //320x480 ID=0x9486
const int TS_LEFT=770,TS_RT=116,TS_TOP=388,TS_BOT=496;
x = map(p.x, LEFT=770, RT=116, 0, 320)
y = map(p.y, TOP=388, BOT=496, 0, 480)
Touch Pin Wiring XP=8 XM=A2 YP=A3 YM=9
x = map(p.y, LEFT=388, RT=496, 0, 480)
y = map(p.x, TOP=116, BOT=770, 0, 320)

OUTPUT after button_Simple: I copy-pasted this
"const int XP=8,XM=A2,YP=A3,YM=9; //320x480 ID=0x9486
const int TS_LEFT=770,TS_RT=116,TS_TOP=388,TS_BOT=496;"

TFT ID = 0x9486
Calibrate for your Touch Panel


Jolly good.

But the touch still doesn't work. ON/OFF buttons don't work. The block color doesn't change to green.

Serial terminal output:

TFT ID = 0x9486
Calibrate for your Touch Panel

why does it say Calibrate for your Touch Panel?
What should i do?
Do i have to calibrate the screen again?

From #5, you have already calibrated the screen:

const int XP=8,XM=A2,YP=A3,YM=9; //320x480 ID=0x9486
const int TS_LEFT=770,TS_RT=116,TS_TOP=388,TS_BOT=496;

Copy-paste those two lines into your Button_simple.ino sketch

Just like you did in the TouchShield example.
Or any other sketch that uses my “const int XP” style.


I did copy the two lines and pasted in the code. Finally the touch is working. But the button and touch pixels are not alligned. I've to press below the button. Location is different.

It worked. Thanks David.

Oops. I blindly copied your "const int" lines without actually reading them.

The values are rubbish. I would expect pairs like 100, 900 i.e. differ by about 800
Your TOP,BOT are only 110 and LEFT,RT are 650

You did not press the highlighted cross-hairs.

Please run the Calibration sketch again.
I think that the current Calibration sketch gives a Warning if you get "unlikely" values.


Yeah Yeah.. I was pressing random Crosshairs. My bad. But thanks.
Btw suppose i want to it in landscape mode. What all changes will i have to do?
First thing would be- tft.setRotation(1);

Look in the TouchShield example. You can edit it to change the rotation. The program should work in all 4 rotations.

Now look at the example code. You see that it uses the fixed physical Portrait calibration but maps x, y according to your logical rotation.


Could you tell me how to exit void loop()

I added ANOTHER BUTTON in the button_simple code:

if (start.justPressed()) {

But when the screen turns black, the ON and OFF button can be pressed if i click on that part of the screen. After Start button pressed, previous buttons should stop working. Like i want a new screen to work with.

Please sit down with a nice cup of tea.

Then follow my suggestion in #14.
i.e. run TouchShield in all 4 rotations.

Study the code.
Quote any sections that you don't understand in your message.

Have another cup of tea. Re-read your message before posting.