Forum Software Ferduino code Touch problem

Touch problem  [SOLVED]


Post Number:#1 Post Wed Aug 20, 2014 5:50 pm
Posts: 10
Topics: 1
Solve rating: 0
Joined: Mon Aug 18, 2014 5:47 pm
Topics: 1
Age: 44
Gender: None specified
National Flag:
Spain
Good.
After doing a thousand tests I can not calibrate the screen. I've gotten codes calibration and the display of the numbers there is no way that works. I've gotten your codes and go but nothing better. I got in touch with those of itead and i was doing some tests and nothing. Finally they sent me a new screen and I still have the same calibration problem.
I'm starting to be desperate as they are not where the problem is, if the shield or arduino. I put the tube with itead conversation to see if you can help me. This is the response I got:

Hi Piruman75,

Thank for your email.

Did you use UTFT and Utouch library? It has a demo code for calibration.

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

After you calibrate the screen, you can enter the data in the below link for verification.

http://henningkarlsen.com/electronics/t_cal_verify.php

If your data is not correct, you can try the below data.

#define CAL_X 0x00430ED8UL
#define CAL_Y 0x002A0EECUL
#define CAL_S 0x000EF18FUL


If it still can't work, try the attachment test code.

I got the codes and go better than giving me to calibrate the screen but it is not calibrated. I made the small town on page enclosing me and the result was this:

Good Morning.
I used the library and UTFT uTouch. After calibrating the screen I went to the uTouch Calibration Data Verification and gave me these errors:

Displaytype : ITead Studio - ITDB02-3.2WD
Your CAL_X : 0x16F6D814UL
Your CAL_Y : 0x419D43FCUL
Your CAL_S : 0x000EF18FUL
Results:
• Orientation is correct...
• Display size parameters are correct...
• CAL_X data sequence is not correct...
• CAL_Y data sequence is not correct...
Suggestions:
• Your CAL_X data seems to have switched left and right. This should not happen on a supported display module. Are you sure you are using a display module on the list of supported modules (See the "UTouch_Supported_display_modules.pdf" document supplied with UTouch)? You can try running the calibration again but I do not think it will help.
• Your CAL_Y data seems to have switched top and bottom. This should not happen on a supported display module. Are you sure you are using a display module on the list of supported modules (See the "UTouch_Supported_display_modules.pdf" document supplied with UTouch)? You can try running the calibration again but I do not think it will help.


I entered the following, I do not work:

#define CAL_X 0x00430ED8UL
#define CAL_Y 0x002A0EECUL
#define CAL_S 0x000EF18FUL


After that they gave me a code to test it on my mega introdujese to audition and dashed lines on the screen and do him a video to see the results. I leave the video to what you may see. When making strokes clear that it is wrong, up is left, down is right, left is up, right is down.

Watch on youtube.com


After that I did modify the code and that they were to make a video with the result, I leave the answer and then the video with the result:
Hi Piruman75,

Maybe you can try to modify these lines in the 3_2WD_test_code.pde.

void loop()
{
    unsigned int i,j;
    while(Touch_DataAvailable() == 1)
 {
  Touch_Read();
  i = Touch_GetX();
  j = Touch_GetY();
  if(i>239) i = 239;
  if(j>399) j = 399; 
        Serial.print(i);
        Serial.print(" ");
        Serial.println(j);
  //SetXY(i,j,i,j);     //old setting
  SetXY(j,i,j,i);
  Write_Data(0xFFFF);
 }
}


Here I leave the result after modifying the code, down is up, up is down, right is left, left is right :

Watch on youtube.com


After they answered this:

Hi Piruman75,

No, it's just calibration problem.

Could you use the below code? Then open the serial monitor and tell me what is the coordinate of four corner on the screen.

void loop()
{
    unsigned int i,j;
    while(Touch_DataAvailable() == 1)
 {
  Touch_Read();
  i = Touch_GetX();
  j = Touch_GetY();
  if(i>239) i = 239;
  if(j>399) j = 399; 
        Serial.print("x: ");
        Serial.print(TP_X);
        Serial.print("    ");
        Serial.print("y: ");
        Serial.println(TP_Y);

  //SetXY(i,j,i,j);     //old setting
  SetXY(j,i,j,i);
  Write_Data(0xFFFF);
 }
}



And my answer was this:

Pressing the corner out many coordinates, the first pressing are these:
Top left: x: 208 y: 3796
Lower left corner: x: 192 y: 276
Top right corner: x: 3901 y: 3729
Lower right corner: x:3875 y: 282

After I returned to spend grinding code and that would make another video with the result that this was

Watch on youtube.com


Then they said they send me a new screen. I have received the screen, I calibrate again and it happens exactly the same with the new screen'm desperate since there is where the problem is.

Sorry about my English, because I have no idea
Last edited by Fernando Garcia on Wed Aug 20, 2014 6:51 pm, edited 1 time in total.
Reason: Formatting fixed.

Post Number:#2 Post Wed Aug 20, 2014 6:03 pm
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

Hi!

Welcome Raul.

Firstly check this topic please.

viewtopic.php?f=8&t=32

Thanks.
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Post Number:#3 Post Wed Aug 20, 2014 6:22 pm
Posts: 10
Topics: 1
Solve rating: 0
Joined: Mon Aug 18, 2014 5:47 pm
Topics: 1
Age: 44
Gender: None specified
National Flag:
Spain
Hi fernando, nice to meet you.
No what you mean with the link you put me

-------------------------------- Last edited Wed Aug 20, 2014 6:28 pm --------------------------------

// UTouch_Calibration (C)2012 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// This program can be used to calibrate the touchscreen
// of the display modules.
// This program requires the UTFT library and a touch
// screen module that is compatible with UTFT.
//
// 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.
//
// Instructions will be given on the display.
//

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

// Define the orientation of the touch screen. Further
// information can be found in the instructions.
#define TOUCH_ORIENTATION  PORTRAIT

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

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

// Uncomment the next two lines for the Arduino Mega
UTFT        myGLCD(ITDB32S,38,39,40,41);   // Remember to change the model parameter to suit your display module!
UTouch      myTouch(6,5,4,3,2);

uint32_t cx, cy;
uint32_t rx[10], ry[10];
uint32_t clx, crx, cty, cby;
float px, py;
int dispx, dispy, text_y_center;
uint32_t calx, caly, cals;
char buf[13];

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

  myTouch.InitTouch(TOUCH_ORIENTATION);
  myTouch.setPrecision(PREC_LOW);
  dispx=myGLCD.getDisplayXSize();
  dispy=myGLCD.getDisplayYSize();
  text_y_center=(dispy/2)-6;
}

void drawCrossHair(int x, int y)
{
  myGLCD.drawRect(x-10, y-10, x+10, y+10);
  myGLCD.drawLine(x-5, y, x+5, y);
  myGLCD.drawLine(x, y-5, x, y+5);
}

void readCoordinates()
{
  int iter = 2000;
  int cnt = 0;
  uint32_t tx=0;
  uint32_t ty=0;
  boolean OK = false;
 
  while (OK == false)
  {
    myGLCD.setColor(255, 255, 255);
    myGLCD.print("*  PRESS  *", CENTER, text_y_center);
    while (myTouch.dataAvailable() == false) {}
    myGLCD.print("*  HOLD!  *", CENTER, text_y_center);
    while ((myTouch.dataAvailable() == true) && (cnt<iter))
    {
      myTouch.read();
      tx += myTouch.TP_X;
      ty += myTouch.TP_Y;
      cnt++;
    }
    if (cnt>=iter)
    {
      OK = true;
    }
    else
    {
      tx = 0;
      ty = 0;
      cnt = 0;
    }
  }

  cx = tx / iter;
  cy = ty / iter;

}

void calibrate(int x, int y, int i)
{
  myGLCD.setColor(255, 255, 255);
  drawCrossHair(x,y);
  myGLCD.setBackColor(255, 0, 0);
  readCoordinates();
  myGLCD.setColor(255, 255, 255);
  myGLCD.print("* RELEASE *", CENTER, text_y_center);
  myGLCD.setColor(80, 80, 80);
  drawCrossHair(x,y);
  rx[i]=cx;
  ry[i]=cy;
  while (myTouch.dataAvailable() == true)
  {
    myTouch.read();
  }
}

void waitForTouch()
{
  while (myTouch.dataAvailable() == true)
  {
    myTouch.read();
  }
  while (myTouch.dataAvailable() == false) {}
  while (myTouch.dataAvailable() == true)
  {
    myTouch.read();
  }
}

void toHex(uint32_t num)
{
  buf[0] = '0';
  buf[1] = 'x';
  buf[10] = 'U';
  buf[11] = 'L';
  buf[12] = 0;
  for (int zz=9; zz>1; zz--)
  {
    if ((num & 0xF) > 9)
      buf[zz] = (num & 0xF) + 55;
    else
      buf[zz] = (num & 0xF) + 48;
    num=num>>4;
  }
}

void startup()
{
  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRect(0, 0, dispx-1, 13);
  myGLCD.setColor(255, 255, 255);
  myGLCD.setBackColor(255, 0, 0);
  myGLCD.drawLine(0, 14, dispx-1, 14);
  myGLCD.print("UTouch Calibration", CENTER, 1);
  myGLCD.setBackColor(0, 0, 0);

  if (dispx==220)
  { 
    myGLCD.print("Use a stylus or something", LEFT, 30);
    myGLCD.print("similar to touch as close", LEFT, 42);
    myGLCD.print("to the center of the", LEFT, 54);
    myGLCD.print("highlighted crosshair as", LEFT, 66);
    myGLCD.print("possible. Keep as still as", LEFT, 78);
    myGLCD.print("possible and keep holding", LEFT, 90);
    myGLCD.print("until the highlight is", LEFT, 102);
    myGLCD.print("removed. Repeat for all", LEFT, 114);
    myGLCD.print("crosshairs in sequence.", LEFT, 126);
    myGLCD.print("Touch screen to continue", CENTER, 162);
  }
  else
  {
    myGLCD.print("INSTRUCTIONS", CENTER, 30);
    myGLCD.print("Use a stylus or something similar to", LEFT, 50);
    myGLCD.print("touch as close to the center of the", LEFT, 62);
    myGLCD.print("highlighted crosshair as possible. Keep", LEFT, 74);
    myGLCD.print("as still as possible and keep holding", LEFT, 86);
    myGLCD.print("until the highlight is removed. Repeat", LEFT, 98);
    myGLCD.print("for all crosshairs in sequence.", LEFT, 110);

    myGLCD.print("Further instructions will be displayed", LEFT, 134);
    myGLCD.print("when the calibration is complete.", LEFT, 146);

    myGLCD.print("Do NOT use your finger as a calibration", LEFT, 170);
    myGLCD.print("stylus or the result WILL BE imprecise.", LEFT, 182);

    myGLCD.print("Touch screen to continue", CENTER, 226);
  }

  waitForTouch();
  myGLCD.clrScr();
}

void done()
{
  myGLCD.clrScr();
  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRect(0, 0, dispx-1, 13);
  myGLCD.setColor(255, 255, 255);
  myGLCD.setBackColor(255, 0, 0);
  myGLCD.drawLine(0, 14, dispx-1, 14);
  myGLCD.print("UTouch Calibration", CENTER, 1);
  myGLCD.setBackColor(0, 0, 0);
 
  if (dispx==220)
  { 
    myGLCD.print("To use the new calibration", LEFT, 30);
    myGLCD.print("settings you must edit the", LEFT, 42);
    myGLCD.setColor(160, 160, 255);
    myGLCD.print("UTouchCD.h", LEFT, 54);
    myGLCD.setColor(255, 255, 255);
    myGLCD.print("file and change", 88, 54);
    myGLCD.print("the following values. The", LEFT, 66);
    myGLCD.print("values are located right", LEFT, 78);
    myGLCD.print("below the opening comment.", LEFT, 90);
    myGLCD.print("CAL_X", LEFT, 110);
    myGLCD.print("CAL_Y", LEFT, 122);
    myGLCD.print("CAL_S", LEFT, 134);
    toHex(calx);
    myGLCD.print(buf, 75, 110);
    toHex(caly);
    myGLCD.print(buf, 75, 122);
    toHex(cals);
    myGLCD.print(buf, 75, 134);
  }
  else
  { 
    myGLCD.print("CALIBRATION COMPLETE", CENTER, 30);
    myGLCD.print("To use the new calibration", LEFT, 50);
    myGLCD.print("settings you must edit the", LEFT, 62);
    myGLCD.setColor(160, 160, 255);
    myGLCD.print("UTouchCD.h", LEFT, 74);
    myGLCD.setColor(255, 255, 255);
    myGLCD.print("file and change", 88, 74);
    myGLCD.print("the following values.", LEFT, 86);
    myGLCD.print("The values are located right", LEFT, 98);
    myGLCD.print("below the opening comment in", LEFT, 110);
    myGLCD.print("the file.", LEFT, 122);
    myGLCD.print("CAL_X", LEFT, 150);
    myGLCD.print("CAL_Y", LEFT, 162);
    myGLCD.print("CAL_S", LEFT, 174);

    toHex(calx);
    myGLCD.print(buf, 75, 150);
    toHex(caly);
    myGLCD.print(buf, 75, 162);
    toHex(cals);
    myGLCD.print(buf, 75, 174);
  }
 
}

void loop()
{
  startup();
 
  myGLCD.setColor(80, 80, 80);
  drawCrossHair(dispx-11, 10);
  drawCrossHair(dispx/2, 10);
  drawCrossHair(10, 10);
  drawCrossHair(dispx-11, dispy/2);
  drawCrossHair(10, dispy/2);
  drawCrossHair(dispx-11, dispy-11);
  drawCrossHair(dispx/2, dispy-11);
  drawCrossHair(10, dispy-11);
  myGLCD.setColor(255, 255, 255);
  myGLCD.setBackColor(255, 0, 0);
  myGLCD.print("***********", CENTER, text_y_center-12);
  myGLCD.print("***********", CENTER, text_y_center+12);

  calibrate(10, 10, 0);
  calibrate(10, dispy/2, 1);
  calibrate(10, dispy-11, 2);
  calibrate(dispx/2, 10, 3);
  calibrate(dispx/2, dispy-11, 4);
  calibrate(dispx-11, 10, 5);
  calibrate(dispx-11, dispy/2, 6);
  calibrate(dispx-11, dispy-11, 7);
 
  if (TOUCH_ORIENTATION == LANDSCAPE)
    cals=(long(dispx-1)<<12)+(dispy-1);
  else
    cals=(long(dispy-1)<<12)+(dispx-1);

  if (TOUCH_ORIENTATION == PORTRAIT)
    px = abs(((float(rx[2]+rx[4]+rx[7])/3)-(float(rx[0]+rx[3]+rx[5])/3))/(dispy-20));  // PORTRAIT
  else
    px = abs(((float(rx[5]+rx[6]+rx[7])/3)-(float(rx[0]+rx[1]+rx[2])/3))/(dispy-20));  // LANDSCAPE

  if (TOUCH_ORIENTATION == PORTRAIT)
  {
    clx = (((rx[0]+rx[3]+rx[5])/3));  // PORTRAIT
    crx = (((rx[2]+rx[4]+rx[7])/3));  // PORTRAIT
  }
  else
  {
    clx = (((rx[0]+rx[1]+rx[2])/3));  // LANDSCAPE
    crx = (((rx[5]+rx[6]+rx[7])/3));  // LANDSCAPE
  }
  if (clx<crx)
  {
    clx = clx - (px*10);
    crx = crx + (px*10);
  }
  else
  {
    clx = clx + (px*10);
    crx = crx - (px*10);
  }
 
  if (TOUCH_ORIENTATION == PORTRAIT)
    py = abs(((float(ry[5]+ry[6]+ry[7])/3)-(float(ry[0]+ry[1]+ry[2])/3))/(dispx-20));  // PORTRAIT
  else
    py = abs(((float(ry[0]+ry[3]+ry[5])/3)-(float(ry[2]+ry[4]+ry[7])/3))/(dispx-20));  // LANDSCAPE

  if (TOUCH_ORIENTATION == PORTRAIT)
  {
    cty = (((ry[5]+ry[6]+ry[7])/3));  // PORTRAIT
    cby = (((ry[0]+ry[1]+ry[2])/3));  // PORTRAIT
  }
  else
  {
    cty = (((ry[0]+ry[3]+ry[5])/3));  // LANDSCAPE
    cby = (((ry[2]+ry[4]+ry[7])/3));  // LANDSCAPE
  }
  if (cty<cby)
  {
    cty = cty - (py*10);
    cby = cby + (py*10);
  }
  else
  {
    cty = cty + (py*10);
    cby = cby - (py*10);
  }
 
  calx = (long(clx)<<14) + long(crx);
  caly = (long(cty)<<14) + long(cby);
  if (TOUCH_ORIENTATION == LANDSCAPE)
    cals = cals + (1L<<31);

  done();
  while(true) {}
}

Post Number:#4 Post Wed Aug 20, 2014 7:42 pm
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

I was talking about the formatting of your first post.

Try this coordinates:

#define CAL_X 0x03AF40FEUL
#define CAL_Y 0x03E10068UL
#define CAL_S 0x000EF18FUL


#define CAL_X 0x004F0ED2UL
#define CAL_Y 0x0037CEBAUL
#define CAL_S 0x000EF18FUL
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Post Number:#5 Post Thu Aug 21, 2014 4:53 pm
Posts: 10
Topics: 1
Solve rating: 0
Joined: Mon Aug 18, 2014 5:47 pm
Topics: 1
Age: 44
Gender: None specified
National Flag:
Spain
Hi Fernando.
I have tried both codes. Neither gives me good result. The second press but some numbers do not match.
No where can be the problem

Post Number:#6 Post Thu Aug 21, 2014 4:59 pm
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

Hi!

Try change:

#define TOUCH_ORIENTATION  PORTRAIT


to:

#define TOUCH_ORIENTATION  LANDSCAPE


Best regards.
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Post Number:#7 Post Thu Aug 21, 2014 5:01 pm
Posts: 10
Topics: 1
Solve rating: 0
Joined: Mon Aug 18, 2014 5:47 pm
Topics: 1
Age: 44
Gender: None specified
National Flag:
Spain
I already tried and did not work me too. You have to change it in the code calibration, right?

Post Number:#8 Post Thu Aug 21, 2014 5:06 pm
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

Yes, try place the pen perpendicular to TFT during the calibration.

You have sure that's using the IDE and libraries right?

How many IDE's you have on PC?
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Post Number:#9 Post Thu Aug 21, 2014 5:51 pm
Posts: 10
Topics: 1
Solve rating: 0
Joined: Mon Aug 18, 2014 5:47 pm
Topics: 1
Age: 44
Gender: None specified
National Flag:
Spain
If I switch to LANDCAPE these coordinates are

#define CAL_X 0x0052CB12UL
#define CAL_Y 0x180F9809UL
#define CAL_S 0x8018F0EFUL

I copied the libraries as seen in a video demonstration of the installation. In UtouchCD change codes that gives me the calibration and no buttons pressed me bin. Also put the codes you have given me and will do better but not quite.

-------------------------------- Last edited Thu Aug 21, 2014 6:31 pm --------------------------------

Arduino-1.0.5-r2

Post Number:#10 Post Thu Aug 21, 2014 6:36 pm
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

I don't know what you can do, anyway try this coordinates:

#define CAL_X  0x0063D27FUL
#define CAL_Y  0x00181617UL
#define CAL_S  0x000EF18FUL


#define CAL_X 0x0075D1BEUL
#define CAL_Y 0x005091BFUL
#define CAL_S 0x000EF18FUL


#define CAL_X 0x00449085UL
#define CAL_Y 0x001B5449UL
#define CAL_S 0x000EF18FUL


#define CAL_X 0x00330FEAUL
#define CAL_Y 0x00201154UL
#define CAL_S 0x000EF18FUL


#define CAL_X 0x005B4F2BUL
#define CAL_Y 0x00211040UL
#define CAL_S 0x000EF18FUL
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Post Number:#11 Post Thu Aug 21, 2014 7:02 pm
Posts: 10
Topics: 1
Solve rating: 0
Joined: Mon Aug 18, 2014 5:47 pm
Topics: 1
Age: 44
Gender: None specified
National Flag:
Spain
None is going well.
Can it be that the shield is wrong?

Post Number:#12 Post Thu Aug 21, 2014 7:30 pm
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

Maybe, the TFT is with cable or directly over the shield?
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Post Number:#13 Post Sun Aug 24, 2014 11:08 am
Posts: 4
Topics: 1
Solve rating: 0
Joined: Sat Aug 09, 2014 12:17 pm
Topics: 1
Age: 41
Gender: None specified
National Flag:
Spain
It happens exactly the same, my touch fundiona backwards, have tried in portrait and landscape without any positive result.

It is hardware error or library?

thank you very much

Post Number:#14 Post Mon Aug 25, 2014 3:52 pm
Posts: 10
Topics: 1
Solve rating: 0
Joined: Mon Aug 18, 2014 5:47 pm
Topics: 1
Age: 44
Gender: None specified
National Flag:
Spain
The TFT is no cable, directly to the shield.

I tried with another shield and it happens exactly the same. I've also tried with another arduino if mine were broken and the same thing happens to me.

It may be some error in the library?

Post Number:#15 Post Mon Aug 25, 2014 6:09 pm
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

Hi!

Plese check this video to see how install libraries.

How to install Ferduino code

Best regards.
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Post Number:#16 Post Tue Aug 26, 2014 6:26 pm
Posts: 10
Topics: 1
Solve rating: 0
Joined: Mon Aug 18, 2014 5:47 pm
Topics: 1
Age: 44
Gender: None specified
National Flag:
Spain
Hi Fernando.
All the times I've tried have been as you do in your video.

I went to a friend's house who has the ferduino installed, I tried my screen on it and the same problem happens. I tried the screen of my friend in my arduino and works perfectly.
That means that the two screens are Itead sent me defective or have changed somewhat from previous screens.

The new screens do not work with these libraries. Now do not know how to explain it Itead

Post Number:#17 Post Wed Sep 03, 2014 6:15 pm
Posts: 10
Topics: 1
Solve rating: 0
Joined: Mon Aug 18, 2014 5:47 pm
Topics: 1
Age: 44
Gender: None specified
National Flag:
Spain
Write only in english, please!

Finalmente cambié unos parametros en el codigo que me dió Itead (3_2WD_test_code) y ahora los trazos que hago me van perfectos.
Lo que no se es que tengo que cambiar en las librerias para que el ejemplo UTouch_buttontest me salga bien o que el ejemplo UTouch_calibration me salga bien.
Os dejo el codigo 3_2WD_test_code para que lo veais a ver si me podeis ayudar:
/**********************************************
Pay an attention!

This code is designed for Arduino 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 240
#define Y_CONST 400

#define PREC_TOUCH_CONST 10

#define PixSizeX   15
#define PixOffsX   200

#define PixSizeY   9
#define PixOffsY   200

/* 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
**********************************************/

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);
}

void Write_Command_Data(unsigned int cmd,unsigned int dat)
{   
   Write_Command(cmd);
   Write_Data(dat);
}

void Lcd_Init()
{
   pinMode(RS,OUTPUT);
   pinMode(WR,OUTPUT);
   pinMode(CS,OUTPUT);
   pinMode(RST,OUTPUT);
   
   DDRA = 0xff;
   DDRC = 0xff;
 
   digitalWrite(RST,HIGH);
      delay(1);   
   digitalWrite(RST,LOW);
   delay(1);
   
   digitalWrite(RST,HIGH);
   digitalWrite(CS,HIGH);
   digitalWrite(WR,HIGH);
   delay(20);

   Write_Command(0x83);           
   Write_Data(0x02);  //TESTM=1
             
   Write_Command(0x85); 
   Write_Data(0x03);  //VDC_SEL=011
   Write_Command(0x8B); 
   Write_Data(0x01);
   Write_Command(0x8C); 
   Write_Data(0x93); //STBA[7]=1,STBA[5:4]=01,STBA[1:0]=11
       
   Write_Command(0x91); 
   Write_Data(0x01); //DCDC_SYNC=1
       
   Write_Command(0x83); 
   Write_Data(0x00); //TESTM=0
   //Gamma Setting

   Write_Command(0x3E); 
   Write_Data(0xB0);
   Write_Command(0x3F); 
   Write_Data(0x03);
   Write_Command(0x40); 
   Write_Data(0x10);
   Write_Command(0x41); 
   Write_Data(0x56);
   Write_Command(0x42); 
   Write_Data(0x13);
   Write_Command(0x43); 
   Write_Data(0x46);
   Write_Command(0x44); 
   Write_Data(0x23);
   Write_Command(0x45); 
   Write_Data(0x76);
   Write_Command(0x46); 
   Write_Data(0x00);
   Write_Command(0x47); 
   Write_Data(0x5E);
   Write_Command(0x48); 
   Write_Data(0x4F);
   Write_Command(0x49); 
   Write_Data(0x40);   
   //**********Power On sequence************
       
   Write_Command(0x17); 
   Write_Data(0x91);
       
   Write_Command(0x2B); 
   Write_Data(0xF9);
   delay(10);
       
   Write_Command(0x1B); 
   Write_Data(0x14);
       
   Write_Command(0x1A); 
   Write_Data(0x11);
             
   Write_Command(0x1C); 
   Write_Data(0x06);
       
   Write_Command(0x1F); 
   Write_Data(0x42);
   delay(20);
       
   Write_Command(0x19); 
   Write_Data(0x0A);
     
   Write_Command(0x19); 
   Write_Data(0x1A);
   delay(40);
       
       
   Write_Command(0x19); 
   Write_Data(0x12);
   delay(40);
       
   Write_Command(0x1E); 
   Write_Data(0x27);
   delay(100);      
       
       
   //**********DISPLAY ON SETTING***********
       
   Write_Command(0x24); 
   Write_Data(0x60);
       
   Write_Command(0x3D); 
   Write_Data(0x40);
       
   Write_Command(0x34); 
   Write_Data(0x38);
       
   Write_Command(0x35); 
   Write_Data(0x38);
       
   Write_Command(0x24); 
   Write_Data(0x38);
   delay(40);
       
   Write_Command(0x24); 
   Write_Data(0x3C);
       
   Write_Command(0x16); 
   Write_Data(0x1C);
       
   Write_Command(0x01); 
   Write_Data(0x06);
       
   Write_Command(0x55); 
   Write_Data(0x00);

   Write_Command(0x02);           
   Write_Data(0x00);
   Write_Command(0x03);           
   Write_Data(0x00);
   Write_Command(0x04);           
   Write_Data(0x00);
   Write_Command(0x05);           
   Write_Data(0xef);
       
   Write_Command(0x06);           
   Write_Data(0x00);
   Write_Command(0x07);           
   Write_Data(0x00);
   Write_Command(0x08);           
   Write_Data(0x01);
   Write_Command(0x09);           
   Write_Data(0x8f);

   Write_Command(0x22);
   
}
void SetXY(unsigned int x0,unsigned int y0,unsigned int x1,unsigned int y1)
{
    Write_Command_Data(0x0003,x0);
   Write_Command_Data(0x0006,y0>>8);
   Write_Command_Data(0x0007,y0);   
   Write_Command_Data(0x0005,x1);
   Write_Command_Data(0x0008,y1>>8);
        Write_Command_Data(0x0009,y1);

   Write_Command (0x0022);//LCD_WriteCMD(GRAMWR);
}
void Pant(unsigned int color)
{
   int i,j;
   SetXY(0,0,239,399);

    for(i=0;i<400;i++)
    {
     for (j=0;j<240;j++)
         {
         Write_Data(color);
       }

     }      
}
void LCD_clear()
{
    unsigned int i,j;
   SetXY(0,0,239,399);
   for(i=0;i<400;i++)
   {
       for(j=0;j<240;j++)
      {   
             Write_Data(0x0000);
      }
   }
}

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 = ((TP_X-PixOffsX)/PixSizeX);
   value = 240-((TP_X-PixOffsX)/PixSizeX); //uncomment this line when x axis is inverted
   if (value < 0)
      value = 0;
   return value;
}
int Touch_GetY()
{
   int value;
   //value = ((TP_Y-PixOffsY)/PixSizeY);
   value = 400-((TP_Y-PixOffsY)/PixSizeY); //uncomment this line when y axis is inverted
   if (value < 0)
      value = 0;
   return value;
}
/**********************************************
Arduino functions zone
**********************************************/
void setup()
{
  Serial.begin(9600);
  Lcd_Init();

 
  Touch_Init();
  LCD_clear();
   //Pant(0xf800);
   //Pant(0x07e0);
   //Pant(0x001f);
   Pant(0xffff);
   Pant(0x0000);
}

void loop()
{
    unsigned int  i,j;
      while(Touch_DataAvailable() == 1)
   {
      Touch_Read();
      i = Touch_GetX();
      j = Touch_GetY();
      if(i>239) i = 239;
      if(j>399) j = 399;      
        Serial.print("x: ");
        Serial.print(TP_X);
        Serial.print("    ");
        Serial.print("y: ");
        Serial.println(TP_Y);
      SetXY(i,j,i,j);
      Write_Data(0xFFFF);
   }
 
 
}


This is the result to get this code:
Watch on youtube.com


What I have to change in the libraries for me to go though the calibration?

Post Number:#18 Post Wed Sep 03, 2014 7:20 pm
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

Try this library.

On file called "ITDB02_Touch.cpp" change the coordinates.

Something like this:

#define PixSizeX   -14.58
#define PixOffsX   276
#define PixSizeY   -8.94
#define PixOffsY   175


Have two examples, one to calibrate and another to test.
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Post Number:#19 Post Wed Sep 10, 2014 5:49 am
Posts: 6
Solve rating: 1
Joined: Sat Aug 23, 2014 8:47 am
Age: 47
Gender: None specified
National Flag:
Poland
I have the same problem with the touch. Has anyone found a solution to this problem. LCD bought from the manufacturer on the website so should begin with to be efficient.

Post Number:#20 Post Wed Sep 10, 2014 11:06 am
Posts: 27
Images: 1
Solve rating: 1
Joined: Wed May 07, 2014 3:20 pm
Age: 47
Gender: None specified
National Flag:
Italy
Same problem for me with one of my three tft...

-------------------------------- Last edited Wed Sep 10, 2014 4:06 pm --------------------------------

Same problem for me with one of my three tft...

Next



Return to Ferduino code





Who is online

Users viewing this topic: No registered users and 2 guests

cron