TFT_320QDT_9341 Touchscreen Y-Axis inverted

Hello,

I am using the TFT_320QDT-9341 on a Arduino mega with a board inbetween. im using the library’s: UTFT, URTouch and UTFT_Buttons.

The problem I’m having is that the Y-axis of my touchscreen is inverted, meaning that when I click on the low side of the screen, the board thinks that I have pressed on the top side of the screen. i have tried a pre-programmed code, and ofcourse my own, and it always happens.

Does anyone have a fix for this problem?

Thanks,

sketch_jun19b.ino (1.33 KB)

Can You try and attach the code the way being told in the first topics like "How to use forum" etc?
Helpers using tablets or smartphones can not read Your .ino file. You cut off a large amount of helpers this way.

Ah yes,
Sorry i forgot to do it that way, here it is;

#include <UTFT.h>
#include <URTouch.h>
#include <UTFT_Buttons.h>
UTFT    myGLCD(ILI9341_16, 38, 39, 40, 41);
URTouch  myTouch( 6, 5, 4, 3, 2);
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t Dingbats1_XL[];

UTFT_Buttons  myButtons(&myGLCD, &myTouch);


void setup() {
  myGLCD.InitLCD();
  myGLCD.clrScr();

  myTouch.InitTouch();
  myTouch.setPrecision(PREC_MEDIUM);

  myGLCD.setFont(BigFont);
  myGLCD.setBackColor(0, 0, 0);

  myButtons.setTextFont(BigFont);
  Serial.begin(9600);
}

void loop() {

  int pressed_button, but1, but2, but3, but_led, but_led1, but_led2, but_led3, but_led4;
  but1 = myButtons.addButton(20, 20, 110, 60, "Bureau");
  but2 = myButtons.addButton(20, 90, 110, 60, "MAKS");
  but3 = myButtons.addButton(20, 160, 110, 60, "Main");
  but_led = myButtons.addButton(140, 20, 160, 60, "LedStrip");
  but_led1 = myButtons.addButton(140, 90, 75, 60, "1");
  but_led2 = myButtons.addButton(140, 160, 75, 60, "3");
  but_led3 = myButtons.addButton(225, 90, 75, 60, "2");
  but_led4 = myButtons.addButton(225, 160, 75, 60, "4");

  myButtons.drawButtons();

  while(1)
  {
    if (myTouch.dataAvailable() == true)
    { 
      pressed_button = myButtons.checkButtons();
      Serial.println(pressed_button);
      if (pressed_button == but1)
      { 
      }
    }
  }
}

Is the printing on the display also up side down or is it only the touch recognition bein wrong?

Are you aware that with most screens, y increases downward?

You forgot to post useful details of the problem, but if there actually is one, it might be solved by a transformation as simple as

y_touch = ymax - y_touch;

Railroader:
Is the printing on the display also up side down or is it only the touch recognition bein wrong?

Nope, its only the touching itself. the screen is just normal.

Okey. @jremington just mad a reply. Tested it?

jremington:
Are you aware that with most screens, y increases downward?

You forgot to post useful details of the problem, but if there actually is one, it might be solved by a transformation as simple as

y_touch = ymax - y_touch;

I don't know if this would work. because atm im using straight up buttons, and the finding out where you press is programmed in the library itself. Or am I wrong? if so could you please try to program it inside my code. So I understand your idea better?

And which details are you missing?

thanks.

Railroader:
Okey. @jremington just mad a reply. Tested it?

Yes, but i can't find an Y-axis variable which I can change. because i don't know how the library decides which button is pressed if you get what i mean.

i can't find an Y-axis variable which I can change

That is easily remedied by studying the documentation and examples that come with the touch screen library.

Please explain how you determined that the touch coordinates are reported "incorrectly". You have given us no reason to believe you.

Also, please answer this question:

Are you aware that with most screens, y increases downward?

jremington:
That is easily remedied by studying the documentation and examples that come with the touch screen library.

Please explain how you determined that the touch coordinates are reported "incorrectly". You have given us no reason to believe you.

Also, please answer this question:

I am aware, but i will explain it asif its 0 in the middle and higher to the top and lower to the bottem, asif you'd use a coordinate system. also I think i can better explain it with a drawing of the layout of my screen (which i have attached), so basicaly if i press MAKS, 1 or 2 the correct one is being triggerd, but if i press Main, Bureau is triggerd, and vice versa. so if you press on the top side, the one on the bottem is being triggerd. say the coördinate of the Bureau button is (0,1) and i press that button it thinks i pressed (0,-1) so the y-axis is inverted.

I am going to try somithing which i have seen in a different exemple from the library which will maybe work, but i'll come back on this. anyway i'd thank you in advance.

as if you'd use a coordinate system.

The screen HAS a coordinate system. I don't know of any exception to the rule that y=0 is the top, and increases downwards.

Perhaps the dimensions of the screen are specified incorrectly.

jremington:
The screen HAS a coordinate system. I don't know of any exception to the rule that y=0 is the top, and increases downwards.

Perhaps the dimensions of the screen are specified incorrectly.

that's not exactly what i meant, but it doesn't really matter, i've tried calibrating the screen, but using the 3 code's from that calibration the touchscreen doesn't work anymore, so i've tried changing only the CAL_Y which also didn't work. so the best codes are the originals but those have the problem of inverting the Y-axis, do you maybe have the correct calibration codes?

Otherwise I am going to have to ditch the buttons altogether and program it so that i check where is being pressed, so that i can reverse the y-axis myself. the only problem with this is that it wil take some more time and be a bit harder to program but I don't think there is another way tbh.

so i'd have to design the buttons, and then program it so that if you click in a certain area (this area is the area of the button) a code will take place and something would happen.

Buttons are easy to draw with a few lines of code. Then you know exactly what is going on.

Here is an example: https://codebender.cc/example/UTouch/Arduino:UTouch_ButtonTest#UTouch_ButtonTest.ino

Its working, but i have one problem. when using

myGLCD.print("bureau",20,20)

there is a black box around the word. but I have no clue how to remove it?

Set the print background to be the same as the button color.

setBackColor()