Problema TFT Touch ITDB 2.8

Olá a todos, este forum tem sido bastante positivo no que diz respeito a resolução de problemas e tenho encontrado muitas soluções para as dúvidas que tenho encontrado nos outros tópicos, mas ainda não encontrei nada sobre o meu problema!!!

Tenho um Arduino Uno R3 com TFT Touch ITDB 2.8 e a libraria que tirei do seguinte site:

http://www.henningkarlsen.com/electronics/library.php?id=55
e
http://www.henningkarlsen.com/electronics/library.php?id=51

Foi o que me indicaram para poder colocar á prova o TFT :slight_smile:

Tive então de mudar apenas um parametro no código e ele carregou direito e aparece os botões no ecrã para eu tocar mas nada feito!!! já li e re-li mesmo o um ficheiro que vem com o codigo e não tenho por onde lhe pegar!!!

Segue abaixo o código:

// UTouch_ButtonTest (C)2010-2012 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// This program is a quick demo of how create and use buttons.
//
// This program requires the UTFT library.
//
// It is assumed that the display module is connected to an
// appropriate shield or that you know how to change the pin 
// numbers in the setup.
//

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

// Declare which fonts we will be using
extern uint8_t BigFont[];

// Uncomment the next two lines for the Arduino 2009/UNO
UTFT        myGLCD(ITDB28,19,18,17,16);   // Remember to change the model parameter to suit your display module!
UTouch      myTouch(15,10,14,9,8);

int x, y;
char stCurrent[20]="";
int stCurrentLen=0;
char stLast[20]="";

/*************************
**   Custom functions   **
*************************/

void drawButtons()
{
// Draw the upper row of buttons
  for (x=0; x<5; x++)
  {
    myGLCD.setColor(0, 0, 255);
    myGLCD.fillRoundRect (10+(x*60), 10, 60+(x*60), 60);
    myGLCD.setColor(255, 255, 255);
    myGLCD.drawRoundRect (10+(x*60), 10, 60+(x*60), 60);
    myGLCD.printNumI(x+1, 27+(x*60), 27);
  }
// Draw the center row of buttons
  for (x=0; x<5; x++)
  {
    myGLCD.setColor(0, 0, 255);
    myGLCD.fillRoundRect (10+(x*60), 70, 60+(x*60), 120);
    myGLCD.setColor(255, 255, 255);
    myGLCD.drawRoundRect (10+(x*60), 70, 60+(x*60), 120);
    if (x<4)
      myGLCD.printNumI(x+6, 27+(x*60), 87);
  }
  myGLCD.print("0", 267, 87);
// Draw the lower row of buttons
  myGLCD.setColor(0, 0, 255);
  myGLCD.fillRoundRect (10, 130, 150, 180);
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (10, 130, 150, 180);
  myGLCD.print("Clear", 40, 147);
  myGLCD.setColor(0, 0, 255);
  myGLCD.fillRoundRect (160, 130, 300, 180);
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (160, 130, 300, 180);
  myGLCD.print("Enter", 190, 147);
  myGLCD.setBackColor (0, 0, 0);
}

void updateStr(int val)
{
  if (stCurrentLen<20)
  {
    stCurrent[stCurrentLen]=val;
    stCurrent[stCurrentLen+1]='\0';
    stCurrentLen++;
    myGLCD.setColor(0, 255, 0);
    myGLCD.print(stCurrent, LEFT, 224);
  }
  else
  {
    myGLCD.setColor(255, 0, 0);
    myGLCD.print("BUFFER FULL!", CENTER, 192);
    delay(500);
    myGLCD.print("            ", CENTER, 192);
    delay(500);
    myGLCD.print("BUFFER FULL!", CENTER, 192);
    delay(500);
    myGLCD.print("            ", CENTER, 192);
    myGLCD.setColor(0, 255, 0);
  }
}

// Draw a red frame while a button is touched
void waitForIt(int x1, int y1, int x2, int y2)
{
  myGLCD.setColor(255, 0, 0);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
  while (myTouch.dataAvailable())
    myTouch.read();
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
}

/*************************
**  Required functions  **
*************************/

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

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

  myGLCD.setFont(BigFont);
  myGLCD.setBackColor(0, 0, 255);
  drawButtons();  
}

void loop()
{
  while (true)
  {
    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);
          }
        }
      }
    }
  }
}

Agradeço toda a ajuda :wink:

Tive então de mudar apenas um parametro no código e ele carregou direito e aparece os botões no ecrã para eu tocar mas nada feito!!! já li e re-li mesmo o um ficheiro que vem com o codigo e não tenho por onde lhe pegar!!!

O que é o nada feito?
Vez a imagem ou o touch nao funciona apenas?
Olhando ao teu codigo chamou me a atençao isto:

void loop()
{
  while (true)
  {

Certamente isto nada tem a ver com a solução para o teu problema mas porque é que tens um infinite loop dentro de outro?
O void loop() por si só já é um ciclo infinito.
Tens o datasheet do tft
Como é ligado o touch ao arduino?

O nada feito é mesmo em relação á parte Touch!
O código carrega e no TFT aparecem os botões bem posicionados mas quando carrego neles não obtenho resposta.

O TFT já vem com os pinos prontos a encaixar nos pinos do arduino.
Segue abaixo imagens e datasheet do TFT:

http://www.goshield.es/es/pantallas/60-28-tft-lcd-touch-shield-.html

while (true)
  {

Já removi mas não tem influência alguma.

Eu como sei que podia tocar na usb se o liga-se directo, coloquei-o num shield de parafusos para lhe dar altura e não tocar na usb e assim tambem tenho acesso aos pinos normalmente.

Shield :
http://www.botnroll.com/product.php?id_product=677

Por via das dúvidas corri o código com e sem o shield (por mais louca que pudesse ser a ideia do shield ter algum problema) mas o resultado é o mesmo! Tenho botões no tft mas se tocar neles nada acontece!

Aqui segue outro link do mesmo TFT:

ok, se no teu loop fizeres isto:

while (true)
  {
    if (myTouch.dataAvailable())
    {
     Serial.println("Detectei algo na tela");
   }

Isto é executado?
Se for optimo quer dizer que o touch esta a falar contigo e estas a receber dados.

Mas eu tenho isso definido mas de outra forma:

{
  myGLCD.setColor(255, 0, 0);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
  while (myTouch.dataAvailable())
    myTouch.read();
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
}

Não vai dar ao mesmo?
Mesmo assim nada acontece ao toque.

while (myTouch.dataAvailable())
myTouch.read();

Se efetivamente tiveres dados para ler aqui estas apenas a lê-los mas isso não te causa nada visual e ficas a saber o mesmo já que tudo é transparente pra ti, agora se fizeres um serial.print quando la tocares com o dedo deves visualizar na porta Serie "Detectei algo na tela" o que te da a certeza que o teu touch esta a detectar os toques na tela.
Relembro te que se o teu objectivo a quando a tela for primida for colocar todas as cores a 255 o codigo tem de ficar assim

{
  myGLCD.setColor(255, 0, 0);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
  while (myTouch.dataAvailable())
{
  myTouch.read();
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
}
}

Agradeço a dica e vou testar!
Depois digo como correu :wink:

Coloquei a função que me foi enviada:

while (true)
  {
    if (myTouch.dataAvailable())
    {
     Serial.println("Detectei algo na tela");
   }

Teria de aparecer "Detectei algo na tela" se apenas toca-se no tft
Mas esta sempre a dar "Detectei algo na tela"!!!! sem tocar no tft

Tive o mesmo problema do Touch.
Na Biblioteca UTouch existe o exemplo UTouch_QuickDraw, nele você consegue "escrever" na tela.
Nela percebi que as cordenadas estavam erradas, então abri o arquivo UTouch.cpp que fica na pasta libraries/UTouch e alterei a seguinte parte:

int16_t UTouch::getY()
{
	int c;

	if ((TP_X==-1) or (TP_Y==-1))
		return -1;
	if (orient == _default_orientation)
	{
		c = long(long(TP_Y - touch_y_top) * (disp_y_size)) / long(touch_y_bottom - touch_y_top);
		if (c<0)
			c = 0;
		if (c>disp_y_size)
			c = disp_y_size;
	}
	else
	{
		//Parte da função GetY que não funciona...
                /*if (_default_orientation == PORTRAIT)
			c = long(long(TP_Y - touch_x_left) * (disp_x_size)) / long(touch_x_right - touch_x_left);
		else*/
			c = long(long(TP_Y - touch_x_left) * (-disp_x_size)) / long(touch_x_right - touch_x_left) + long(disp_x_size);
		if (c<0)
			c = 0;
		if (c>disp_x_size)
			c = disp_x_size;
	}
	return c;
}

dai passou a funcionar o Touch normalmente.
Espero ter ajudado