Offline
Newbie
Karma: 0
Posts: 8
|
 |
« on: August 31, 2012, 11:29:14 pm » |
Okay so i have managed to get get the screen to work and that is fine. However i cannot get the touch to work at all. I have all the libraries installed and even the example from the ITDB02_touch library compiles and loads fine. I am using an Arduino Mega 2560. However the example for touch screen calibration works but some of the graphics get screwed up. What could I be doing wrong? Any help would be greatly appreciated. Here is some of my code. #include <UTFT.h> #include <ITDB02_Touch.h>
//Declare font types extern uint8_t BigFont[];
//Gets the screen and touch sensor ready UTFT myGLCD(ITDB32S,38,39,40,41); ITDB02_Touch myTouch(6,5,4,3,2);
//Declare functions void read_ts();
//Define my variables float x = 0, y = 0; int run = 0;
int temp; bool error = true; bool changed = true;
void setup() { //Setup the Screen myGLCD.InitLCD(); myTouch.InitTouch(); myTouch.setPrecision(PREC_MEDIUM); myGLCD.clrScr(); }
void loop() { //reads x and y values of touch sensor read_ts(); //prints these values to the screen myGLCD.printNumF(x,3,50,150); myGLCD.printNumF(y,3,50,175); myGLCD.setFont(BigFont); myGLCD.setColor(255, 0, 255); myGLCD.print("It got this far.", CENTER, 200); myGLCD.printNumF(run,2,50,75); //prints how many times it has run onto the screen run++; }
void read_ts() { x = myTouch.getX(); y = myTouch.getY(); }
I've also attached a picture of the screen. Peter
|
|
|
|
|
Logged
|
Arduino Mega 2560 Arduino Uno R3 Sainsmart 3.2" TFT LCD
|
|
|
|
SE USA
Offline
Faraday Member
Karma: 33
Posts: 3621
@ssh0le
|
 |
« Reply #1 on: August 31, 2012, 11:36:49 pm » |
are they both using interrupts?
|
|
|
|
|
Logged
|
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #2 on: August 31, 2012, 11:42:05 pm » |
I'm sorry, i'm not sure what you mean by "interrupts"?
|
|
|
|
|
Logged
|
Arduino Mega 2560 Arduino Uno R3 Sainsmart 3.2" TFT LCD
|
|
|
|
SE USA
Offline
Faraday Member
Karma: 33
Posts: 3621
@ssh0le
|
 |
« Reply #3 on: September 01, 2012, 10:43:18 pm » |
interrupts are a fundamental part of computer processors, they say that if something occurs stop everything, run this part of the code, and then return back to what you were doing
imagine that your working on a report in the office and the phone rings from the bosses extension, that's an interrupt.
AVR microcontrollers can accept many different interrupts from different locations, internal timers, or external influence. the bad thing is AVR micro's are pretty stupid and cant really tell what caused the interrupt, it just knows that something happened, so if you have 2 items using interrupts, it kindly runs them both.
For example the TV out library uses timer interrupts so it can make the video timing signals, add the PS/2 keyboard library which uses external interrupts to note when the keyboard has data to send and the screen gets all goofy.
|
|
|
|
|
Logged
|
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #4 on: September 02, 2012, 10:47:24 pm » |
Hey thanks for the reply Osgeld. So are you saying that the touch sensor acts as an interrupt which stops the code? I understand what you are saying, but how would i fix this? Do I have to tell the AVR what to do if it receives an interrupt or tell it to continue running the code even if it receives an interrupt signal?
Peter
|
|
|
|
« Last Edit: September 02, 2012, 10:50:29 pm by Peter_F »
|
Logged
|
Arduino Mega 2560 Arduino Uno R3 Sainsmart 3.2" TFT LCD
|
|
|
|
SE USA
Offline
Faraday Member
Karma: 33
Posts: 3621
@ssh0le
|
 |
« Reply #5 on: September 02, 2012, 11:36:51 pm » |
that I dont know, attach the libraries you are using for the screen and touch
|
|
|
|
|
Logged
|
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #6 on: September 02, 2012, 11:48:19 pm » |
|
|
|
|
|
Logged
|
Arduino Mega 2560 Arduino Uno R3 Sainsmart 3.2" TFT LCD
|
|
|
|
Western New York, USA
Offline
Faraday Member
Karma: 17
Posts: 3465
|
 |
« Reply #7 on: September 03, 2012, 09:28:31 am » |
I've also attached a picture of the screen. What did you expect to see?Don
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #8 on: September 03, 2012, 11:26:51 am » |
Well quite frankly, that was what i expected to see. the 298 Number is a loop counter so i know its running. 27000 is the x coordinate and the 32656 is the y coordinate for the touch sensor. However, these numbers appear the same every time it runs, even before the screen is touched.
|
|
|
|
|
Logged
|
Arduino Mega 2560 Arduino Uno R3 Sainsmart 3.2" TFT LCD
|
|
|
|
Western New York, USA
Offline
Faraday Member
Karma: 17
Posts: 3465
|
 |
« Reply #9 on: September 03, 2012, 12:09:51 pm » |
How often do you think you should read the touchscreen?
Do you think it is necessary to rewrite the x and y coordinate data if it doesn't change?
What's this: run++; ?
Don
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #10 on: September 03, 2012, 12:28:18 pm » |
Well the run++ was just to keep track of the number of times the loop ran. I can probably get rid of that. Also I see what you mean that i should only readthe touch screen if the data changes, I know how to do that, but I cannot get accurate touch data at all, so that is my first priority.
|
|
|
|
|
Logged
|
Arduino Mega 2560 Arduino Uno R3 Sainsmart 3.2" TFT LCD
|
|
|
|
Western New York, USA
Offline
Faraday Member
Karma: 17
Posts: 3465
|
 |
« Reply #11 on: September 03, 2012, 02:38:24 pm » |
Also I see what you mean that i should only readthe touch screen if the data changes, Well you have to read the touch screen first in order to determine if the data changes - but you shouldn't have to redisplay the data if it hasn't changed.I know how to do that, but I cannot get accurate touch data at all, ... What are the timing constraints concerning how often you can access the touch data? Are you observing those constraints?Don
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 5
Posts: 469
what?
|
 |
« Reply #12 on: September 03, 2012, 04:27:06 pm » |
For the calibration sketch to work you neet to init the screen and touch in portrait orientation as per your code this defaults to landscape mode myGLCD.InitLCD(); myTouch.InitTouch(); you need to change it to this myGLCD.InitLCD(PORTRAIT); myTouch.InitTouch(PORTRAIT); once the calibration is done you can go back to landscape if you want Start simple, have you tried the quickdraw example? #include <UTFT.h> #include <ITDB02_Touch.h>
UTFT myGLCD(ITDB32S,38,39,40,41); ITDB02_Touch myTouch(6,5,4,3,2);
void setup() { myGLCD.InitLCD(PORTRAIT); myGLCD.clrScr();
myTouch.InitTouch(PORTRAIT); myTouch.setPrecision(PREC_MEDIUM); }
void loop() { while (myTouch.dataAvailable() == true) { myTouch.read(); myGLCD.drawPixel (myTouch.getX(), myTouch.getY()); } }
|
|
|
|
« Last Edit: September 03, 2012, 04:45:48 pm by P18F4550 »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #13 on: September 03, 2012, 08:56:50 pm » |
Okay thanks to all your efforts, the touch sensor is now working and i can read the X and Y values However even after calibration, the readings are not consistent varying by as much as 30 pixels. I am using extreme precision and was using the tip of a pencil and it still wasn't that accurate. Any ideas?
Peter
|
|
|
|
|
Logged
|
Arduino Mega 2560 Arduino Uno R3 Sainsmart 3.2" TFT LCD
|
|
|
|
North Queensland, Australia
Offline
Edison Member
Karma: 31
Posts: 1182
|
 |
« Reply #14 on: September 03, 2012, 10:11:12 pm » |
Check out the data sheet for the touch interface, it may have a trouble shooting section or tips on how to get best performance. Maybe the touch interface needs debouncing. I have a touch TFT I want to use so it'll be good to see if you can get nice and accurate readings.
|
|
|
|
|
Logged
|
|
|
|
|
|