another ILI9341 question: how to use touch screen ?

another ILI9341 question: how to use touch screen ?

The Display is 2.4" by 320x240pixels; Type is TJCTTM24024-SPI
I'm using mostly a DUE.

The TFT runs fine both with Adafruit_ILI9340, Adafruit_ILI9341, and ILI9341_due.
I would prefer to use the ILI9341_due because of it's amazing output speed.

I want to create simple small touch fields for sort of cursor commands (up, down, left, right, OK, ESC, DEL) of about 1cm² areas each.

There are pins for T_IRQ, T_D0, T_DIN, T_CS, T_CLK (very small letters, not clearely to decipher)

Can someone please provide me a link or give me some help how to wire the pins and implement touch-sensitive regions to react to?

Thank you in advance!

Have you looked at ILI9341_due UTouch* examples?

You wire up those pins to any digital pins and use UTouch library (need to download it separately) to get the touch coordinates. The touch controller (that bigger chip on the back) is XPT2046 which seems to be 5V compatible so you should not need to use a logic level converter on those T_* pins, just connect it directly to Arduino pins.
UTouch constructor takes in the arduino pins you used to connect to those T_* pins on TFT as parameters: UTouch myTouch(30, 28, 26, 24, 22);

You should run the uTouchCalibration first to calibrate the touch, just read the instructions that will appear on the screen.

hi,
thanks for your reply!
I'm using the DUE by 3.3V.

where is ILI9341_due Utouch? Don't find it neither in

nor by Google search!

and BTW, what do
T_IRQ,
T_D0,
T_DIN,
T_CS,
T_CLK
mean at all (ok, probably CS is chip select and clk clock),
and how (by which series) have they to be passed to UTouch myTouch(30, 28, 26, 24, 22);?
I actually supposed them to work additionally on SPI bus pins.

Only are "names", they are only digital inputs.

aha-
but in which order do they have to be wired according to the function call
myTouch(30, 28, 26, 24, 22)
?

Ya!

This is the correct order:

 myTouch(TCLK, TCS, TDIN, TDOUT, IRQ)

For example:

 UTouch  myTouch(6,5,4,3,2);

Or:

myTouch(30, 28, 26, 24, 22)


30   ---> TCLK
28   ---> TCS
26   ---> TDIN
24   ---> TDOUT
22   ---> IRQ

that's great! thank you very much!
I'll try then to figure out how to paint virtual push buttons...!
(a pictured tutorial actually would be nice :slight_smile: )

I was just browsing through the ILI9341_due utouch example:

if (myTouch.dataAvailable())
		{
			myTouch.read();
			x = myTouch.getX();
			y = myTouch.getY();

			if ((y >= 10) && (y <= 60))  // Upper row
			{
				if ((x >= 10) && (x <= 60))  // Button: 1
				{
					waitForIt(10, 10, 60, 60);
					updateStr('1');
				}
				if ((x >= 70) && (x <= 120))  // Button: 2
				{
					waitForIt(70, 10, 120, 60);
					updateStr('2');
				}
				if ((x >= 130) && (x <= 180))  // Button: 3
				{
					waitForIt(130, 10, 180, 60);
					updateStr('3');
				}
				if ((x >= 190) && (x <= 240))  // Button: 4
				{
					waitForIt(190, 10, 240, 60);
					updateStr('4');
				}
				if ((x >= 250) && (x <= 300))  // Button: 5
				{
					waitForIt(250, 10, 300, 60);
					updateStr('5');
				}
			}

			if ((y >= 70) && (y <= 120))  // Center row
			{
				if ((x >= 10) && (x <= 60))  // Button: 6
				{
					waitForIt(10, 70, 60, 120);
					updateStr('6');
				}
				if ((x >= 70) && (x <= 120))  // Button: 7
				{
					waitForIt(70, 70, 120, 120);
					updateStr('7');
				}
				if ((x >= 130) && (x <= 180))  // Button: 8
				{
					waitForIt(130, 70, 180, 120);
					updateStr('8');
				}
				if ((x >= 190) && (x <= 240))  // Button: 9
				{
					waitForIt(190, 70, 240, 120);
					updateStr('9');
				}
				if ((x >= 250) && (x <= 300))  // Button: 0
				{
					waitForIt(250, 70, 300, 120);
					updateStr('0');
				}
			}

			if ((y >= 130) && (y <= 180))  // Upper row
			{
				if ((x >= 10) && (x <= 150))  // Button: Clear
				{
					waitForIt(10, 130, 150, 180);
					stCurrent[0] = '\0';
					stCurrentLen = 0;
					tft.fillRect(0, 224, 320, 15, ILI9341_BLACK);
				}
				if ((x >= 160) && (x <= 300))  // Button: Enter
				{
					waitForIt(160, 130, 300, 180);
					if (stCurrentLen>0)
					{
						for (x = 0; x<stCurrentLen + 1; x++)
						{
							stLast[x] = stCurrent[x];
						}
						stCurrent[0] = '\0';
						stCurrentLen = 0;
						tft.fillRect(0, 208, 320, 31, ILI9341_BLACK);
						tft.setTextColor(ILI9341_LIME, ILI9341_BLACK);
						tft.printAlignedOffseted(stLast, gTextAlignTopCenter, 0, 208);
					}
					else
					{
						tft.setTextColor(ILI9341_RED, ILI9341_BLACK);
						tft.printAlignedOffseted("BUFFER EMPTY", gTextAlignTopCenter, 0, 190);
						delay(500);
						tft.printAlignedOffseted(" ", gTextAlignTopCenter, 0, 190, gTextEraseFullLine);
						delay(500);
						tft.printAlignedOffseted("BUFFER EMPTY", gTextAlignTopCenter, 0, 190);
						delay(500);
						tft.printAlignedOffseted(" ", gTextAlignTopCenter, 0, 190, gTextEraseFullLine);
					}
				}
			}
		}
	}

this is actually MUCH too much code to write.
What would be nice is to have a lib as convenient as

mytouch.btncreate(sqrbtn1, x1,y1,x2,y2, color);  // define different square btn regions
mytouch.btncreate(sqrbtn2, x1,y1,x2,y2, color);  
mytouch.btncreate(sqrbtn3, x1,y1,x2,y2, color);
mytouch.btncreate(sqrbtn4, x1,y1,x2,y2, color);

if (myTouch.dataAvailable()) {
   myTouch.read();
   x = myTouch.getX();
   y = myTouch.getY();

   if (mytouch.press(x,y, sqrbtn1)) {//do something;}  // test btn press for related region
   else
   if (mytouch.press(x,y, sqrbtn2)) {//do something;}  // test btn press for related region
   else
   if (mytouch.press(x,y, sqrbtn3)) {//do something;}  // test btn press for related region
   else
   if (mytouch.press(x,y, sqrbtn4)) {//do something;}  // test btn press for related region
   
}

is there something like that, too?

Yes! On the same site you presumably got UTouch from? HERE

Good luck,

Graham

the TFT lib I'm using is ILI9341_due -
will the UTFT-Utouch lib by Henning Karlsen work nevertheless?

In post #7 you quoted a section of code.......

if (myTouch.dataAvailable())
		{
			myTouch.read();
			x = myTouch.getX();
			y = myTouch.getY();

			if ((y >= 10) && (y <= 60))  // Upper row
			{
				if ((x >= 10) && (x <= 60))  // Button: 1
				{
					waitForIt(10, 10, 60, 60);
					updateStr('1');
				}
				if ((x >= 70) && (x <= 120))  // Button: 2
				{
					waitForIt(70, 10, 120, 60);
					updateStr('2');
				}
				if ((x >= 130) && (x <= 180))  // Button: 3
				{
					waitForIt(130, 10, 180, 60);
					updateStr('3');
				}
				if ((x >= 190) && (x <= 240))  // Button: 4
				{
					waitForIt(190, 10, 240, 60);
					updateStr('4');
				}
				if ((x >= 250) && (x <= 300))  // Button: 5
				{
					waitForIt(250, 10, 300, 60);
					updateStr('5');
				}
			}

			if ((y >= 70) && (y <= 120))  // Center row
			{
				if ((x >= 10) && (x <= 60))  // Button: 6
				{
					waitForIt(10, 70, 60, 120);
					updateStr('6');
				}
				if ((x >= 70) && (x <= 120))  // Button: 7
				{
					waitForIt(70, 70, 120, 120);
					updateStr('7');
				}
				if ((x >= 130) && (x <= 180))  // Button: 8
				{
					waitForIt(130, 70, 180, 120);
					updateStr('8');
				}
				if ((x >= 190) && (x <= 240))  // Button: 9
				{
					waitForIt(190, 70, 240, 120);
					updateStr('9');
				}
				if ((x >= 250) && (x <= 300))  // Button: 0
				{
					waitForIt(250, 70, 300, 120);
					updateStr('0');
				}
			}

			if ((y >= 130) && (y <= 180))  // Upper row
			{
				if ((x >= 10) && (x <= 150))  // Button: Clear
				{
					waitForIt(10, 130, 150, 180);
					stCurrent[0] = '\0';
					stCurrentLen = 0;
					tft.fillRect(0, 224, 320, 15, ILI9341_BLACK);
				}
				if ((x >= 160) && (x <= 300))  // Button: Enter
				{
					waitForIt(160, 130, 300, 180);
					if (stCurrentLen>0)
					{
						for (x = 0; x<stCurrentLen + 1; x++)
						{
							stLast[x] = stCurrent[x];
						}
						stCurrent[0] = '\0';
						stCurrentLen = 0;
						tft.fillRect(0, 208, 320, 31, ILI9341_BLACK);
						tft.setTextColor(ILI9341_LIME, ILI9341_BLACK);
						tft.printAlignedOffseted(stLast, gTextAlignTopCenter, 0, 208);
					}
					else
					{
						tft.setTextColor(ILI9341_RED, ILI9341_BLACK);
						tft.printAlignedOffseted("BUFFER EMPTY", gTextAlignTopCenter, 0, 190);
						delay(500);
						tft.printAlignedOffseted(" ", gTextAlignTopCenter, 0, 190, gTextEraseFullLine);
						delay(500);
						tft.printAlignedOffseted("BUFFER EMPTY", gTextAlignTopCenter, 0, 190);
						delay(500);
						tft.printAlignedOffseted(" ", gTextAlignTopCenter, 0, 190, gTextEraseFullLine);
					}
				}
			}
		}
	}

Now let's look at the GENUINE Henning version.....

if (myTouch.dataAvailable())
    {
      myTouch.read();
      x=myTouch.getX();
      y=myTouch.getY();
      
      if ((y>=10) && (y<=60))  // Upper row
      {
        if ((x>=10) && (x<=60))  // Button: 1
        {
          waitForIt(10, 10, 60, 60);
          updateStr('1');
        }
        if ((x>=70) && (x<=120))  // Button: 2
        {
          waitForIt(70, 10, 120, 60);
          updateStr('2');
        }
        if ((x>=130) && (x<=180))  // Button: 3
        {
          waitForIt(130, 10, 180, 60);
          updateStr('3');
        }
        if ((x>=190) && (x<=240))  // Button: 4
        {
          waitForIt(190, 10, 240, 60);
          updateStr('4');
        }
        if ((x>=250) && (x<=300))  // Button: 5
        {
          waitForIt(250, 10, 300, 60);
          updateStr('5');
        }
      }

      if ((y>=70) && (y<=120))  // Center row
      {
        if ((x>=10) && (x<=60))  // Button: 6
        {
          waitForIt(10, 70, 60, 120);
          updateStr('6');
        }
        if ((x>=70) && (x<=120))  // Button: 7
        {
          waitForIt(70, 70, 120, 120);
          updateStr('7');
        }
        if ((x>=130) && (x<=180))  // Button: 8
        {
          waitForIt(130, 70, 180, 120);
          updateStr('8');
        }
        if ((x>=190) && (x<=240))  // Button: 9
        {
          waitForIt(190, 70, 240, 120);
          updateStr('9');
        }
        if ((x>=250) && (x<=300))  // Button: 0
        {
          waitForIt(250, 70, 300, 120);
          updateStr('0');
        }
      }

      if ((y>=130) && (y<=180))  // Upper row
      {
        if ((x>=10) && (x<=150))  // Button: Clear
        {
          waitForIt(10, 130, 150, 180);
          stCurrent[0]='\0';
          stCurrentLen=0;
          myGLCD.setColor(0, 0, 0);
          myGLCD.fillRect(0, 224, 319, 239);
        }
        if ((x>=160) && (x<=300))  // Button: Enter
        {
          waitForIt(160, 130, 300, 180);
          if (stCurrentLen>0)
          {
            for (x=0; x<stCurrentLen+1; x++)
            {
              stLast[x]=stCurrent[x];
            }
            stCurrent[0]='\0';
            stCurrentLen=0;
            myGLCD.setColor(0, 0, 0);
            myGLCD.fillRect(0, 208, 319, 239);
            myGLCD.setColor(0, 255, 0);
            myGLCD.print(stLast, LEFT, 208);
          }
          else
          {
            myGLCD.setColor(255, 0, 0);
            myGLCD.print("BUFFER EMPTY", CENTER, 192);
            delay(500);
            myGLCD.print("            ", CENTER, 192);
            delay(500);
            myGLCD.print("BUFFER EMPTY", CENTER, 192);
            delay(500);
            myGLCD.print("            ", CENTER, 192);
            myGLCD.setColor(0, 255, 0);
          }
        }
      }
    }

If you can understand the differences between the 2 versions, the same type of changes can be made to UTFT_Buttons.

Failing that, have you tried the UTFT library with a constructor of ILI9341_S4P or ILI9341_S5P? Then nothing would need modifying.

Hope this helps..

Regards,

Graham

I'm not sure if I understand you correctly...
you are mentioning the UTFT lib by Henning Karlsen, by I don't use UTFT for my TFT because it's not hardware SPI and because it's faaaar too slow.
I'm using the ILI9341_due lib instead.
So if UTFT_Button will work for this, too, then it's fine -
but, if not: is there another high-level Button lib also for ILI9341_due?

I think you missed my point............ The code you quoted in post #7 is lifted from Henning's UTouch example...... with 'slight' modifications.......... as far as I see it, the same type of modifications could be applied to the UTFT_Buttons library? The touch library doesn't use SPI, so no problem? I don't have a serial display, but you asked if there was a better way of dealing with buttons, and I answered you.

Regards,

Graham

no, the code I posted was from ILI9341_due, not UTFT
but I can't change a whole lib actually by myself and I understand nothing about C++ OOP (just a little about ANSI C)

so there is no lib available for ILI9341_due to simply draw regions and react to a hit on them, just like by a touch / switch button?

like for touch switches:

#define btnpressed(pin) {digitalRead(pin)==HIGH}
#define touchbtn1  10

if(DigitalRead(touchbtn1 )==HIGH) {do something}
//or just
if (btnpressed(touchbtn1) ) {do something}

so now having for TFT touch regions like, e.g.

mytouch.btncreate(sqrbtn1, x1,y1,x2,y2, color); 

if (mytouch.press(x,y, sqrbtn1)) {do something;}
//or just
if (mytouch.pressed(sqrbtn1)) {do something;}
void loop()
{
  int but1, but2, but3, but4, butX, butY, pressed_button;
  boolean default_colors = true;
  
  but1 = myButtons.addButton( 10,  20, 300,  30, "Button 1");
  but2 = myButtons.addButton( 10,  60, 300,  30, "Button 2");
  but3 = myButtons.addButton( 10, 100, 300,  30, "Button 3");
  but4 = myButtons.addButton( 10, 140, 300,  30, "Button 4", BUTTON_DISABLED);
  butX = myButtons.addButton(279, 199,  40,  40, "a", BUTTON_SYMBOL);
  butY = myButtons.addButton(  0, 199, 100,  40, "I", BUTTON_SYMBOL | BUTTON_SYMBOL_REP_3X);
  myButtons.drawButtons();

 
  while(1) 
  {
    if (myTouch.dataAvailable() == true)
    {
      pressed_button = myButtons.checkButtons();

      if (pressed_button==butX)
      {
        if (myButtons.buttonEnabled(but4))
          myButtons.disableButton(but4, true);
        else
          myButtons.enableButton(but4, true);
      }
      else if (pressed_button==butY)
      {
        if (default_colors)
        {
          myButtons.setButtonColors(VGA_YELLOW, VGA_RED, VGA_YELLOW, VGA_BLUE, VGA_GRAY);
          myButtons.relabelButton(butY, "_");
          myButtons.drawButtons();
          default_colors=false;
        }
        else
        {
          myButtons.setButtonColors(VGA_WHITE, VGA_GRAY, VGA_WHITE, VGA_RED, VGA_BLUE);
          myButtons.relabelButton(butY, "I");
          myButtons.drawButtons();
          default_colors=true;
        }
      }
      if (pressed_button==but1)
        // do stuff for but1
      if (pressed_button==but2)
        // do stuff for but2
      if (pressed_button==but3)
        // do stuff for but3
      if (pressed_button==but4)
        // do stuff for but4
      if (pressed_button==-1)
        // do stuff for nothing pressed
    }
  }
}

You mean like that? It is called UTFT_Buttons.

Like I said previously, I shouldn't think it would be too hard to make work with your display driver.

Regards,

Graham

yes, where to get it?

If you say "I shouldn't think it would be too hard to make work with your display driver", so it shouldn't be too hard to make work with my display driver.
So who will do it?
I personally can't, as I am a simple Arduino end user, no programming education, no idea about C++ libs, just little knowlege about ANSI C.

Arthur, I am not trying to be awkward, I am trying to be helpful!!

I don't have one of your displays, and I don't use the Adafruit (or derivative) libraries you are using, but what I am saying is, the bulk of the code, should be 'transplantable', if I had one of those displays I would do it for you no problem, but since I don't it makes it a little more difficult.

I gave you the link earlier.....

Provide me with 'your' version of UTouch......... I will look through it and see what changes have been made from the original Henning version. Maybe I can deduce the necessary changes that will be needed to UTFT_Buttons to work for you, but since you already have UTouch working, and UTFT_Buttons only sits on top of UTouch, I can't see it being that difficult, but I need a start point.

It may be a slow process, but I don't like things to beat me you know?

I too am only a lowly Arduino end user as you put it..... But 4 years later I have also learnt C so I can do what I want to do with my Arduino, copying other peoples ideas and code only goes so far.....

Regards,

Graham

Sorry, Graham, I didn't want to appear to be rude or to beat on anyone -
I just need a solution, ready-to-use.
As English is not my native language, I'm writing straight ahead, with help of Google Translate, so the words are just plain words without an intention to argue.

The ILI9341_due lib is this one, containing several subdirectories (I actually assumed you to know it in detail):

(BTW, I have just 1 year experience using Arduino in a little spare time, mostly on weekends, and I never used OOP like C++ or Java or C# before)

Ok, thank you for that, no I am actually not at all familiar with anything other than the real UTFT libraries by Henning Karlsen and again for emphasis, all available here :- Rinky-Dink Electronics.

I won't be going much further with this tonight, but one quick question......... From looking at the uTouchButtonTest.ino example, I can see on lines 6 and 7

#include <UTFT.h>
#include <UTouch.h>

So is it fair to assume you do actually have the genuine versions of those libraries installed?

Regards,

Graham