Hi!
I think this is good topic for my problem. I have successesfuly calibrated my screen on TFT LCD Shield v1.0 screen is tft_320qvt, but I have some problems sometimes when I upload programme touch is not always calibrated in that case I have to upload it again an it works, sometime I have to uploade it for 5 times for touch to be calibrated, but my biggest problem is if I unplug arduino from power source and plug it in again there is no way that touch will be calibrated I have try this for many time with no luck, only reuploading program solve the problem. So do anyone know why this is happening? Beacuse when arduino wll be in use if electrical power go off, I will always have to reupload programme.
Sorry for my poor knowledge of englis.
frIXy, Slovenia
Where is your code? If this is a programming issue, you need to post code.
If it isn't a programming issue, you are in the wrong place.
I acually do not know if this is progamming isiuee or not.
my code
#include <UTouch.h>
#include <UTFT.h>
extern uint8_t SevenSegNumFont[]; //Višina pisave 16pix
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
UTFT LCD(ITDB32S,38,39,40,41);
UTouch Touch(6,5,4,3,2);
int x,y;
void pritisnjen(int x1,int y1,int x2,int y2)
{
LCD.setColor(VGA_YELLOW);
LCD.fillRect(x1,y1,x2,y2);
}
void nepritisnjen(int x1,int y1,int x2,int y2)
{
LCD.setColor(VGA_BLACK);
LCD.fillRect(x1,y1,x2,y2);
}
void setup()
{
LCD.InitLCD(); //Priprava LCD-ja
LCD.clrScr(); //Priprava LCD-ja
//LCD.setColor(VGA_TRANSPARENT); //Barva ozadja
//LCD.fillRect(0,0,319,239); //Ozadje
//LCD.setColor(255,255,255); //Ozadje
Touch.InitTouch();
Touch.setPrecision(PREC_MEDIUM);
LCD.setColor(VGA_RED);
LCD.fillRect(100,150,200,200); //Pomen (Za?etek po x, za?etek po y, velikost po x, velikost po y)
}
void loop()
{
//while(true)
//{
if (Touch.dataAvailable())
{
Touch.read();
x=Touch.getX();
y=Touch.getY();
}
else
{
x=0;
y=0;
}
LCD.setFont(BigFont);
LCD.setColor(VGA_WHITE);
LCD.print("X=",0,60);
LCD.print("Y=",0,80);
LCD.print(" ",40,60);
LCD.printNumF(x,0,40,60); //Pomen (St. decimalnih mest,Postavitev po dolžini ekrana,Postavitev po višini ekrana)
LCD.print(" ",40,80);
LCD.printNumF(y,0,40,80);
LCD.setColor(VGA_RED);
LCD.fillRoundRect(100,150,200,200); //Pomen (Za?etek po dolžini, za?etek po višini, velikost po dolžini, velikost po višini)
if ((y>=150) && (y<=200))
{
if((x>=100) && (x<=200))
{
pritisnjen (0,0,50,50);
}
}
else
{
nepritisnjen (0,0,50,50);
}
// }
}
my code
Which has no debug output. Why not?
WHat do you mean with output debug?
WHat do you mean with output debug?
Stuff like:
Serial.println("I got here");
Serial.print("myVariable = ");
Serial.println(myVariable);
Where in my code should I use debug output?
frIXy:
Where in my code should I use debug output?
sometimes when I upload programme touch is not always calibrated
So, add something in the calibration code. Does it get called? What calibration does it perform? What are the calibration values that are important? Print them. Do they have reasonable values?
if I unplug arduino from power source and plug it in again there is no way that touch will be calibrated
Why not? Is the calibration function called, or not? Quit guessing. Find out.
I use UTouch librarie in wich is program to calibrate touch screen when calibratet I have to enter some values in UTouchCD.h file these are the values
#define CAL_X 0x00470F30UL
#define CAL_Y 0x03D3C11CUL
#define CAL_S 0x000EF13FUL
So I think that this file is called by UTouch.h in programme itself. I do not know why but if I change programme let say instead of drawing a circle on screen it draws rectangle when i presse on screen. On bottom of the screen I have displayed X and Y coordinates that touch recognized. When I upload programme on cihip coordinates are displayed (x=0, y=0) wich are good beacuse I have not press on touch jet. But when I press it sometimes coordinates are (x=higher then 320 or lower then 0, y= higher then 240 or lower then 0) wich is not good. So I have to reupload same programme serveral times until coordinates are properly displayed. Then program workrs fine, but if I disconect chip from power supply and connect it again coordinates are messed up again, I can disconnect and reconnect chip for 10 times and coordinates are always wrong. So we are back to reuploading programme for serveral times.
Lp, Simon.
So I have to reupload same programme serveral times until coordinates are properly displayed.
Bullshit. Uploading the same code over and over does NOT affect how that program operates. Clearly (to me, at least) what is happening is that you are failing to initialize some variables, and, therefore, printing garbage.
Use the tools at your disposal to determine where you are failing to initialize variables correctly.
If you say so. Is maybe there any chance that this can be hardware problem?
Is maybe there any chance that this can be hardware problem?
Why is it so hard to get you to add a Serial.print() statement or two and find out for yourself?
I am a little bit new in programming. What should I do with serial print?
I have some good updates! I realized when calibration is not sucessesful I just need to connect reset pin with GND pind for a while and then calibration is always sucessesful. Is there maybe any solution in sketch that will do the reset trick in program? once chip powres up does a reset and then continiue to do his work?
@PaulS, with those type of LCD displays, you can't use the serial monitor. This is because the pins 1 and 0 are used as the data buses. So his only means of debugging is the screen itself. And he does in fact have a debug screen.
if (Touch.dataAvailable())
{
Touch.read();
x=Touch.getX();
y=Touch.getY();
}
else
{
x=0;
y=0;
}LCD.setFont(BigFont);
LCD.setColor(VGA_WHITE);
LCD.print("X=",0,60);
** LCD.print("Y=",0,80);**
** LCD.print(" ",40,60);**
** LCD.printNumF(x,0,40,60); //Pomen (St. decimalnih mest,Postavitev po dolžini ekrana,Postavitev po višini ekrana)**
** LCD.print(" ",40,80);**
** LCD.printNumF(y,0,40,80);**
LCD.setColor(VGA_RED);
LCD.fillRoundRect(100,150,200,200); //Pomen (Za?etek po dolžini, za?etek po višini, velikost po dolžini, velikost po višini)if ((y>=150) && (y<=200))
{
if((x>=100) && (x<=200))
{
pritisnjen (0,0,50,50);
}}
else
{
nepritisnjen (0,0,50,50);
}
Is there maybe any solution in sketch that will do the reset trick in program? once chip powres up does a reset and then continiue to do his work?
Connect the reset pin to a digital pin. Set the pin LOW. Wait a while. Set the pin HIGH. Reset accomplished.
Hi,
maybe you can solve this with adding some delay to HW_AVR.inc
word UTouch::touch_ReadData()
{
word data = 0;for(byte count=0; count<12; count++)
{
data <<= 1;
sbi(P_CLK, B_CLK);
cbi(P_CLK, B_CLK);
delayMicroseconds(1); //// added to get more stable readings?
if (rbi(P_DOUT, B_DOUT))
data++;
}
return(data);
}
It works like a charm!