Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Community Manager
2,251 Views

Periodic Timer and Touchscreen clashing?

Hi,

My project uses a 2.8" TFT display from Adafruit (https://www.adafruit.com/products/1651 # 1651), and is installed with the ILI9341 and SMTPE610 libraries from over https://github.com/wallacezq/Adafruit_ILI9341 here. They are initialized to use the standard pins - that is: 9, 10 for the display and 8 for the touchscreen.

Recently, I placed a periodic timer:

void InitTimer() {

struct itimerval timer={0};

timer.it_value.tv_sec = 10; // Initial timeout value

timer.it_interval.tv_sec = 10; // We want a repetitive timer

signal(SIGALRM, &ClockHandler); // Register Signal handler

setitimer(ITIMER_REAL, &timer, NULL); // And register for periodic timer

}

The Clockhandler routine just displays the local time, in this case, every 10 seconds.

void ClockHandler(int signum)

{

time_t t = time(NULL);

tft.print(asctime(localtime(&t)));

}

In my main loop, I handle touchscreen taps like so:

void loop(void) {

uint16_t x, y;

if (touch.touched()) {

while (! touch.bufferEmpty()) {

TS_Point p = touch.getPoint();

x = //do some mapping from device to screen coordinates

y = //do some mapping from device to screen coordinates

Serial.print(x); Serial.print(", "); Serial.println(y);

}

}

Now here is the weird thing... with the addition of the periodic timer, my touchscreen x and y values appear to change randomly... like the hardware is being affected by the timer in some way. (Perhaps I could also say this in another way - it's like the bus data for the touchscreen is corrupted for some reason). Once I comment out the call to InitTimer, thereby inhibiting the periodic timer, the problem goes away and the touchscreen works as per normal.

Does anybody have any idea as to how I should solve this problem - simultaneously allowing the touchscreen to work as well as incorporating a clock on the display without the touchscreen coordinates going all wonky on me.

Regards,

Gavin

0 Kudos
7 Replies
Highlighted
Community Manager
9 Views

Hi all,

I thought I found the answer, that I just needed to take care of debouncing (as documented over https://forums.adafruit.com/viewtopic.php?f=22&t=62452# p391143 here).

But, nope... I was wrong. The problem still occurs intermittently. I have even tried increasing the delay to 70, but to no avail.

Help!

void loop(void) {

uint16_t x, y;

if (touch.touched()) {

while (! touch.bufferEmpty()) {

TS_Point p = touch.getPoint();

x = //do some mapping from device to screen coordinates

y = //do some mapping from device to screen coordinates

Serial.print(x); Serial.print(", "); Serial.println(y);

delay(35); //>> Added this line to take care of debouncing

}

}

Regards,

Gavin

Highlighted
Community Manager
9 Views

Here's my sample output when just tapping on one spot without moving or releasing my finger. The data returned appears random, with an occasional nonsense value (> screen height and width) interspersed in between. What could be causing the data to fluctuate like so?

207, 128

208, 153

25, 194

2, 145

25, 152

116, 213

139, 180

184, 170

230, 163

137, 159

251, 87

46, 80

160, 81

229, 81

65514, 84

65514, 46

297, 65526

23, 70

46, 71

23, 70

65514, 65

297, 63

0 Kudos
Highlighted
Community Manager
9 Views

Hello gavinkoh70,

 

 

I don't have access to this display in order to test the library, so my suggestion is that you contact the original author of the library, he might be able to get you a more accurate answer regarding the library's functionalities.

 

 

Another option would be for you to use UPM, this library has a working example using the ILI9341, it might be of help for you. You can find the example in https://github.com/intel-iot-devkit/upm/blob/master/examples/c%2B%2B/ili9341.cxx

 

 

-Peter.
0 Kudos
Highlighted
Community Manager
9 Views

Personally, I was asking this question here as I thought this was more an Intel Edison hardware problem than a software one.

Well, I have been working exclusively with an Arduino Sketch and am not sure if I could switch just like that to a Cxx environment with not too much work. But let me see what I can do to find the root cause of this intermittent hardware conflict.

Highlighted
Community Manager
9 Views

Hi gavinkoh70,

 

 

Let us know if you are able to find something or if changing to UPM is able to help you. If the issues persist we would be more than happy to help in any way we can.

 

 

-Peter.
0 Kudos
Highlighted
Community Manager
9 Views

Hi,

Never did try out UPM. The solution is debouncing related, plus needing to clear all "touch" interrupts (essentially emptying the buffer) and using readData instead of using TS_Point.

Here it is:

void loop(void) {

uint16_t x, y, px, py;

uint8_t pz, button;

if (touch.touched()) {

while (! touch.bufferEmpty() || touch.touched()) {

touch.readData(&px, &py, &pz);

x = TFT_WIDTH - map(py, TS_MINX, TS_MAXX, 0, TFT_WIDTH);

y = map(px, TS_MINY, TS_MAXY, 0, TFT_HEIGHT);

Serial.print(x); Serial.print(", "); Serial.println(y);

delay(70); // This is for handling debouncing of the touchscreen - original 35

}

touch.writeRegister8(STMPE_INT_STA, 0xFF); // Clears all "touch" interrupts

// Do touch screen detection stuff

}

delay(10); // This is new

}

Hope this helps.

0 Kudos
Highlighted
Community Manager
9 Views

After much monitoring... I think this time the problem is solved

First, here's a proper description of my problem:

I have a menu displayed. At the bottom, is a line of text that tells me the date and time: "21 Jul 2016 14:27:30". This line is refreshed every 10 seconds. If I press the touch screen after at least a minute of inactivity, the touch coordinates returned is garbage (see earlier reply in this thread). So, in a way, I have a dreaded intermittent problem whereby debugging cannot pinpoint the true problem.

Deductive Reasoning:

Apparently the ILI9341 and STMPE610 cannot share the SPI bus simultaneously. Whenever you are displaying something, perhaps the STMPE610 touch controller gets overwhelmed somehow.

Solution:

Whenever I display something, I turn off the touch controller. I do this with a

touch.writeRegister8(STMPE_SYS_CTRL2, 0x3); // turn off clocks!

and once I finish pushing pixels out, I reenable the touch controller via

touch.writeRegister8(STMPE_SYS_CTRL2, 0x0); // turn on clocks!

And problem goes away for good.

0 Kudos