utouch ssd1963 5 inch problem

guix:
doesn't work as it should

This does not provide me with any information at all...

The calibration sketch have been tested on all the supported displays, but the SainSmart module will never be among them. SainSmart products are generally of so low quality that I say far away from them.

/Henning

Sainsmart, Elecfreaks, Itead... same products, different names.

Anyway, it worked well with older version of Utouch, and you can see I'm not the only one to have problems with the calibration sketch.

guix:
Sainsmart, Elecfreaks, Itead... same products, different names.

If they are really the same product, please explain this:
I checked the emails I got over a six month period, and the percentage of emails ultimately caused by hardware problems turned out like this:

  • ITead: 1.6%
  • ElecFreaks: 1.8%
  • SainSmart: 98.3%

Does not look like they are the same products to me...

/Henning

I have same problem and I opened utouch.cpp and make some change with disp_x_size and disp_y_size

void UTouch::InitTouch(byte orientation)
{
	orient					= orientation;
	_default_orientation	= CAL_S>>31;
	touch_x_left			= (CAL_X>>14) & 0x3FFF;
	touch_x_right			= CAL_X & 0x3FFF;
	touch_y_top				= (CAL_Y>>14) & 0x3FFF;
	touch_y_bottom			= CAL_Y & 0x3FFF;
	//disp_x_size				= (CAL_S>>12) & 0x0FFF;
	//disp_y_size				= CAL_S & 0x0FFF;
	disp_x_size				= 800;
	disp_y_size				= 480;
	prec					= 10;

	pinMode(T_CLK,  OUTPUT);
    pinMode(T_CS,   OUTPUT);
    pinMode(T_DIN,  OUTPUT);
    pinMode(T_DOUT, INPUT);
    pinMode(T_IRQ,  OUTPUT);

	digitalWrite(T_CS,  HIGH);
	digitalWrite(T_CLK, HIGH);
	digitalWrite(T_DIN, HIGH);
	digitalWrite(T_CLK, HIGH);
}

doc_norway:
If they are really the same product, please explain this:
I checked the emails I got over a six month period, and the percentage of emails ultimately caused by hardware problems turned out like this:

  • ITead: 1.6%
  • ElecFreaks: 1.8%
  • SainSmart: 98.3%

Does not look like they are the same products to me...

/Henning

Sorry, not trying to beat a dead horse here. But have you considered that maybe a big reason why those percentages are that way is that people only buy from SainSmart? If 1400/1500 buy from SainSmart, I would imagine you would get percentages like that.

JHawk88:
Sorry, not trying to beat a dead horse here. But have you considered that maybe a big reason why those percentages are that way is that people only buy from SainSmart? If 1400/1500 buy from SainSmart, I would imagine you would get percentages like that.

I think you have misunderstood what the percentages represents...
They represent the amount of messages I got where the root cause of the problems was a hardware fault or issue, and are a percentage of the total amount of messages regarding that particular vendor.

It has been a while since I did the count so I do not remember the exact figures any longer but the total number of messages was somewhere around 2500 and they were divided by the vendors almost equally (approx: 30% (SainSmart)/33% (ElecFreaks)/37% (ITead)).

Example: Say I got 1000 messages regarding ITead modules then 16 of those messages were about problems caused by hardware faults.

/Henning

Hello,

I solved the problem by adding some delay before SPI reading when CS is driven. According to datasheet it needs minimum 200ns when data is valid. After this mod (I used 2us delay) I'll get very steady readings.
Also I put some debounce for reading touchscreen "keys", now it works perfectly.

Can you explain what you did exactly for proper working? Have the Same Problem. I did the calibration and it is better now, but not very good precision

[EDIT] Did calibration again and in my sketch set precision to High. Now it's good for my touch application
[EDIT2] Ok for small buttons it is not good working. particularly on the borders of the screen.

I found out that if it is longer pressed it gives good coordinates out. Anyone an idea how to improve the code?

Anyone an idea how to improve the code?

What code?

Of the utouch library. Or how can I use it with bester results?

PaulS:

Anyone an idea how to improve the code?

What code?

MaikB85:
Of the utouch library. Or how can I use it with bester results?

You really need to define some concrete requirements. "Improve the code" is uselessly vague. "Speed up the recognition of a tough by 30%" is a requirement that might have a hope in hell of being implementable.

"Use it with better results" is equally useless. You have not defined what results you are getting, or what better results might be.

Well sorry for that I will try to explain the problem. I have made a pictur of my 5 inch Touch Screen from ITEAD Studio.

As you see I made 4 touches with a stylus on my screen (shown in squares) but the sketch colors also pixels outside of this area (shown in circles with the same color).

I need more precision for that because in my Sketch I want to use very small buttons.

I hope it is clearer now.

I don't know if it is a hardware problem but it really depends on the calibration how precise it is.

Slowly I am thinking about another solution for my sketch. With big buttons everything is ok.

You have the same problem I have, its the touch pad itself. If I tap the screen a few times in the same spot, it see a line like pattern go towards the top right of my screen. My guess is that the air bubble in between the two layers is not big enough, so when they touch, other places touch too. The way I solved this was to make a button function that ignores any outside spots, so it only accepts values within a certain space.

boolean TouchButton(int x1, int y1, int x2, int y2, int xc, int yc) // xc / yc = X touch coord, Y touch coord
{ 
  if (orient==LANDSCAPE) // flip touch coords depending on screen orientation LANDSCAPE / PORTRAIT
  {
    xc = xc ^ yc;
    yc = xc ^ yc;
    xc = xc ^ yc;
  }

  if (x1>x2)
  {
    x1 = x1 ^ x2;
    x2 = x1 ^ x2;
    x1 = x1 ^ x2;
  }
  if (y1>y2)
  {
    y1 = y1 ^ y2;
    y2 = y1 ^ y2;
    y1 = y1 ^ y2;
  }

  if(xc >= x1 && xc<= x2 && yc >= y1 && yc <= y2) return true;
  return false;
}

That looks good I will try it :slight_smile:

Back again still no solution to my problem but the solution is near :wink:

I contacted the support of ITEAD Studion and get a lot of help from an hardware engineer from ITEAD.
He send me a code which works much better than the UTouch library.

Her is the code I'm Using for now:

/**********************************************
Pay an attention!

This code is designed for Arduino Mega board.

**********************************************/

/**********************************************
Define zone
**********************************************/
#define RS 38
#define WR 39
#define CS 40
#define RST 41

#define T_CLK 6
#define T_CS 5
#define T_DIN 4
#define T_DOUT 3
#define T_IRQ 2

#define X_CONST 800
#define Y_CONST 480

#define PREC_TOUCH_CONST 10

#define PixSizeX	4.7
#define PixOffsX	200
#define PixSizeY	7.3
#define PixOffsY	250

/* LCD color */
#define White          0xFFFF
#define Black          0x0000
#define Blue           0x001F
#define Blue2          0x051F
#define Red            0xF800
#define Magenta        0xF81F
#define Green          0x07E0
#define Cyan           0x7FFF
#define Yellow         0xFFE0

/**********************************************
Val Zone
**********************************************/
int TP_X,TP_Y;


/**********************************************
Standard C functions zone
**********************************************/

unsigned int HDP=799;
unsigned int HT=928;
unsigned int HPS=46;
unsigned int LPS=15;
unsigned char   HPW=48;

unsigned int VDP=479;
unsigned int VT=525;
unsigned int VPS=16;
unsigned int FPS=8;
unsigned char   VPW=16;

void write_command(unsigned int c)
{
  digitalWrite(CS,LOW);
  digitalWrite(RS,LOW);
  PORTA = c >> 8;
  PORTC = c;
  digitalWrite(WR,LOW);
  digitalWrite(WR,HIGH);
  digitalWrite(CS,HIGH);
}
void write_data(unsigned int c)
{
  digitalWrite(CS,LOW);
  digitalWrite(RS,HIGH);
  PORTA = c >> 8;
  PORTC = c;
  digitalWrite(WR,LOW);
  digitalWrite(WR,HIGH);
  digitalWrite(CS,HIGH);
}
extern void write_dc(unsigned char d1,unsigned char d2)
{
  digitalWrite(CS,LOW);
  digitalWrite(RS,HIGH);
  PORTA=d1;
  PORTC=d2;
  digitalWrite(WR,LOW);
  digitalWrite(WR,HIGH);
  digitalWrite(CS,HIGH);
}

void SetXY(unsigned int X,unsigned int Y)
{
write_command(0x002A);	
write_data(X>>8);
write_data(X&0x00ff);
write_data(HDP>>8);	    
write_data(HDP&0x00ff);
write_command(0x002b);	
write_data(Y>>8);	    
write_data(Y&0x00ff);
write_data(VDP>>8);	    
write_data(VDP&0x00ff);
write_command(0x002c); 
}

void LCD_clear()
{
    unsigned int l=800,w;
	SetXY(0,0);
	while(l--)
	{
	    for(w=0;w<480;w++)
		{    
          	write_data(0x0000);
		}
	}
}

void Lcd_Init(void)
{
        
	pinMode(RS,OUTPUT);
	pinMode(WR,OUTPUT);
	//pinMode(RD,OUTPUT);
	pinMode(CS,OUTPUT);
	pinMode(RST,OUTPUT);
  
	DDRA = 0xff;
	DDRC = 0xff;
	
	digitalWrite(RST,LOW);
	delay(10);
	digitalWrite(RST,HIGH);
	delay(20);
	write_command(0x00E2);	//PLL multiplier, set PLL clock to 120M
	write_data(0x001e);	    //N=0x36 for 6.5M, 0x23 for 10M crystal
	write_data(0x0002);
	write_data(0x0004);
	write_command(0x00E0);  // PLL enable
	write_data(0x0001);
	delay(1);
	write_command(0x00E0);
	write_data(0x0003);
	delay(1);
	write_command(0x0001);  // software reset
	delay(1);
	write_command(0x00E6);	//PLL setting for PCLK, depends on resolution
	write_data(0x0003);
	write_data(0x00ff);
	write_data(0x00ff);

	write_command(0x00B0);	//LCD SPECIFICATION
	write_data(0x0027);
	write_data(0x0000);
	write_data((HDP>>8)&0X00FF);  //Set HDP
	write_data(HDP&0X00FF);
    write_data((VDP>>8)&0X00FF);  //Set VDP
	write_data(VDP&0X00FF);
    write_data(0x0000);

	write_command(0x00B4);	//HSYNC
	write_data((HT>>8)&0X00FF);  //Set HT
	write_data(HT&0X00FF);
	write_data((HPS>>8)&0X00FF);  //Set HPS
	write_data(HPS&0X00FF);
	write_data(HPW);			   //Set HPW
	write_data((LPS>>8)&0X00FF);  //Set HPS
	write_data(LPS&0X00FF);
	write_data(0x0000);

	write_command(0x00B6);	//VSYNC
	write_data((VT>>8)&0X00FF);   //Set VT
	write_data(VT&0X00FF);
	write_data((VPS>>8)&0X00FF);  //Set VPS
	write_data(VPS&0X00FF);
	write_data(VPW);			   //Set VPW
	write_data((FPS>>8)&0X00FF);  //Set FPS
	write_data(FPS&0X00FF);

	write_command(0x00BA);
	write_data(0x000F);    //GPIO[3:0] out 1

	write_command(0x00B8);
	write_data(0x0007);    //GPIO3=input, GPIO[2:0]=output
	write_data(0x0001);    //GPIO0 normal

	write_command(0x0036); //rotation
	write_data(0x0000);

	write_command(0x00F0); //pixel data interface
	write_data(0x0003);


	delay(1);

	LCD_clear();
	write_command(0x0029); //display on

	write_command(0x00BE); //set PWM for B/L
	write_data(0x0006);
	write_data(0x00f0);
	write_data(0x0001);
	write_data(0x00f0);
	write_data(0x0000);
	write_data(0x0000);

	write_command(0x00d0); 
	write_data(0x000d);	
}

void Touch_Init(void)
{
	pinMode(T_CLK,  OUTPUT);
    pinMode(T_CS,   OUTPUT);
    pinMode(T_DIN,  OUTPUT);
    pinMode(T_DOUT, INPUT);
    pinMode(T_IRQ,  INPUT);

	digitalWrite(T_CS,  HIGH);
	digitalWrite(T_CLK, HIGH);
	digitalWrite(T_DIN, HIGH);
	digitalWrite(T_CLK, HIGH);
}

void Touch_WriteData(unsigned char data)
{
	unsigned char temp;
	unsigned char nop;
	unsigned char count;

	temp=data;
	digitalWrite(T_CLK,LOW);

	for(count=0; count<8; count++)
	{
		if(temp & 0x80)
			digitalWrite(T_DIN, HIGH);
		else
			digitalWrite(T_DIN, LOW);
		temp = temp << 1; 
		digitalWrite(T_CLK, LOW);                
		nop++;
		digitalWrite(T_CLK, HIGH);
		nop++;
	}
}

unsigned int Touch_ReadData()
{
	unsigned char nop;
	unsigned int data = 0;
	unsigned char count;
	for(count=0; count<12; count++)
	{
		data <<= 1;
		digitalWrite(T_CLK, HIGH);               
		nop++;
		digitalWrite(T_CLK, LOW);
		nop++;
		if (digitalRead(T_DOUT))
			data++;
	}
	return(data);
}
void Touch_Read()
{
	unsigned long tx=0;
	unsigned long ty=0;

	digitalWrite(T_CS,LOW);                    

	for (int i=0; i<PREC_TOUCH_CONST; i++)
	{
		Touch_WriteData(0x90);        
		digitalWrite(T_CLK,HIGH);
		digitalWrite(T_CLK,LOW); 
		ty+=Touch_ReadData();

		Touch_WriteData(0xD0);      
		digitalWrite(T_CLK,HIGH);
		digitalWrite(T_CLK,LOW);
		tx+=Touch_ReadData();
	}

	digitalWrite(T_CS,HIGH);

	TP_X=tx/PREC_TOUCH_CONST;
	TP_Y=ty/PREC_TOUCH_CONST;
}

char Touch_DataAvailable()
{
  char avail;
  avail = !digitalRead(T_IRQ);
  return avail;
}

int Touch_GetX()
{
	int value;
	value =800-((TP_X-PixOffsX)/PixSizeX);
	if (value < 0)
		value = 0;

	return value;
}
int Touch_GetY()
{
	int value;
	value =((TP_Y-PixOffsY)/PixSizeY);
	if (value < 0)
		value = 0;

	return value;
}
void Pant(unsigned int c)
{
	int i,j;
	SetXY(0,0);
	for(i=0;i<Y_CONST;i++)
	{
    

    for(j=0;j<X_CONST;j++)
    {
      write_data(c);
    }
    }
}

void setup()
{
  Lcd_Init();
  Touch_Init();
  LCD_clear();
  	Pant(0xffff);
	Pant(0x0000);
 Serial.begin(115200);
}

void loop()
{
  unsigned int  i,j;
   	while(Touch_DataAvailable() == 1)
	{
		Touch_Read();
		i = Touch_GetX();
		j = Touch_GetY();
                Serial.print("X:  ");
                Serial.print(i);
                Serial.print("    ");
                Serial.print("Y:  ");
                Serial.println(j);
	}
 
}

there is only one simple problem with touching. When I start touching it gives bad coordinates for the first cycles. Until it is touched the coordinates are perfect on every point of the screen. But when touching ends there is the same problem as it is on the beginning the coordinates get bad again.
So I need to filter the first and last coordinates out. Ignoring the first coordinates is no problem. a simple delay() is enough for that but how ignore the last values? Does anyone have an idea?

Here is an example to see the problem.
Touching on three different points on the screen:

X:  661    Y:  158	//Start Touching
X:  661    Y:  158
X:  661    Y:  158
X:  662    Y:  156
X:  662    Y:  155
X:  663    Y:  154
X:  662    Y:  152
X:  662    Y:  150
X:  661    Y:  150
X:  661    Y:  149
X:  660    Y:  148
X:  658    Y:  148
X:  657    Y:  148
X:  657    Y:  149
X:  656    Y:  149
X:  655    Y:  149
X:  655    Y:  149
X:  654    Y:  150
X:  653    Y:  149
X:  653    Y:  150
X:  653    Y:  150
X:  653    Y:  150
X:  653    Y:  150
X:  655    Y:  149
X:  785    Y:  395	//End Touching

X:  184    Y:  84	//Start Touching
X:  184    Y:  84
X:  183    Y:  84
X:  183    Y:  84
X:  183    Y:  84
X:  183    Y:  84
X:  183    Y:  84
X:  183    Y:  84
X:  183    Y:  84
X:  183    Y:  84
X:  183    Y:  84
X:  184    Y:  84
X:  183    Y:  84
X:  184    Y:  84
X:  184    Y:  84
X:  294    Y:  97	//End Touching

X:  127    Y:  410	//Start Touching
X:  128    Y:  410
X:  129    Y:  409
X:  132    Y:  407
X:  134    Y:  404
X:  135    Y:  404
X:  136    Y:  403
X:  136    Y:  403
X:  136    Y:  403
X:  136    Y:  403
X:  136    Y:  403
X:  136    Y:  403
X:  136    Y:  403
X:  136    Y:  404
X:  136    Y:  404
X:  136    Y:  404
X:  594    Y:  463   	//End Touching

So I have made a function myself:

void loop()
{  
  unsigned int  i, j, xbefore, ybefore;
  unsigned int c = 0;
  int deltax = 0;
  int deltay = 0;
  xbefore = 0;
  ybefore = 0;

 while (Touch_DataAvailable() == 1)
  {
    c++; 
    delay(5);
    if (c == 5) //Ignore first 5 values 
    {
      Touch_Read();
      i = Touch_GetX();
      j = Touch_GetY();
      if (i<= 800 && j <= 480) //Screen size
      {
        touchX = i;
        touchY = j;
        xbefore = i;
        ybefore = j;
      }	
    }
    if (c > 5)
    {
      Touch_Read();
      i = Touch_GetX();
      j = Touch_GetY();
      deltax = xbefore - i;
      if (deltax < 0)
        deltax = deltax * (-1);
      deltay = ybefore - j;
      if (deltay < 0)
        deltay = deltay * (-1);
      if (i<= 800 && j <= 480 && deltax < 5 && deltay < 5) //Coordinates must be valid with screensize and 
      {                                                                                               //in an area 5 pixel arround last coordinate
        touchX = i;
        touchY = j;
        xbefore = i;
        ybefore = j;
        TFTouchEvent(); //Execute Touch function
      }	
    }
  }
}

Works very good for me. No bad coordinates anymore.

I have a 7 inches touch screen, and I had the same problem, but I've changed the library similar to the #55 message and it works fine!!!

Thanks