0

2.8" Capacitive Touch Screen with Interrupts?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

2.8" Capacitive Touch Screen with Interrupts?

by RH3 on Tue Jan 13, 2015 3:29 am

Has anyone tried running the Capacitive touch controller using the IRQ to trigger an interrupt on the Arduino and then read the data direct through 'ctp.getPoint() or read the XY registers directly?

I've tried, I can get the Interrupt to trigger and run my Interrupt handler but as soon as you try and query the FT6206 controller through ctp.getPoint() or reading the registers directly the Arduino Uno and Mega just lock-up.

Using:
Code: Select all | TOGGLE FULL SIZE
void touchInt()
{
// Interrupt handler for FT6206
   Serial.println("Touch sensed: ");
   p = ctp.getPoint();                           // Get current touch position
   px = SCREEN_WIDTH - p.y;              // Map touch to screen rotation
   py = p.x;
   
  return;
}


I thought it may be a Stack size restriction but even with an absolute minimal application the lock-up still happens. I've also tried instantiating the FT6206 in the Interrupt handler but still no go.

Note: I'm running the FT6206 in Interrupt Polling mode so only one interrupt is created by touch rather than the default that creates interrupts as long as the screen in being touched.

RH3
 
Posts: 34
Joined: Sun Aug 03, 2014 4:22 am

Re: 2.8" Capacitive Touch Screen with Interrupts?

by adafruit_support_rick on Wed Jan 14, 2015 2:42 pm

You can't call Serial.println from within an interrupt service routine. You probably can't call ctp.getPoint from an ISR, either, since that's on the I2C driver, which is interrupt-driven. What you probably have to do is set a flag inside the ISR, and then poll the flag in your main loop.

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: 2.8" Capacitive Touch Screen with Interrupts?

by RH3 on Wed Jan 14, 2015 7:47 pm

Hi Rick,

Looks like the IRQ option on the display isn't of much use then in my case. I needed to use the interrupt to speed touch sensing for an on-screen menu as the loop processing time is too slow to respond quickly. I guess my only real option is to write my own driver or move to the Arduino Due for a faster CPU.

Many Thanks,

Richard.

RH3
 
Posts: 34
Joined: Sun Aug 03, 2014 4:22 am

Re: 2.8" Capacitive Touch Screen with Interrupts?

by aprescott on Sun Sep 13, 2015 8:36 pm

Hi guys, in particular Rick,

Did you manage to get an implementation using IRQs for this touch screen controller - I am in your position - unsure how I can get a suitable speed using while/if statements to drive my touchscreen interface?

Hoping someone can help.

I am using a galileo gen 2, have the screen performing very well speed-wise, i2c working nicely - just want to use interrupts to make it classy - simplify my code.

Anthony

aprescott
 
Posts: 1
Joined: Sun Sep 13, 2015 7:53 pm

Re: 2.8" Capacitive Touch Screen with Interrupts?

by adafruit_support_rick on Mon Sep 14, 2015 10:06 am

The problem is that you can't read the touch point at interrupt level. So about all you can do is to set a flag in the ISR, and poll the flag in loop().

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: 2.8" Capacitive Touch Screen with Interrupts?

by mathotp on Tue Oct 20, 2015 5:15 am

Hi Rick,

I'm also facing this issue right now, and find it useless to put an interrupt pin on the TFT if you can use it to it's full potential :(
would there be any library update to have this working ?

Thanks
Phil

mathotp
 
Posts: 3
Joined: Tue Oct 20, 2015 5:13 am

Re: 2.8" Capacitive Touch Screen with Interrupts?

by adafruit_support_rick on Tue Oct 20, 2015 5:49 am

It's not a library limitation. It's more a limitation of the Arduino platform. The problem is that you can't do an I2C read from interrupt level using the Arduino I2C library. Theoretically, you could write your own I2C driver, but you'd have to do a busy-wait for the touch data, and that's not a good idea at interrupt level.

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: 2.8" Capacitive Touch Screen with Interrupts?

by JeffMD on Wed Jul 18, 2018 10:56 pm

I read through this thread hoping to find a clue to resolve an interrupt issue on a rotary encoder and the Adafruit FT6205 library. The code I wrote runs on a MEGA 2560 and uses an interrupt on pin 21 when the encoder 'button' is pressed. All works well as long as I don't make a CTP related function call. Adding a call like 'ctp.touched()' immediately locks the processor up.

From the tread, I understand there is limits to what can be done inside the Interrupt Service Routine. As you will see in my code below, my ISR function simply sets a flag, nothing else.

Any ideas why this 'flag' only ISR routine causes a problem?

Code: Select all | TOGGLE FULL SIZE
// Crash casuing Rotary Encoder Interrupt example uisng MEGA 2560 and Adafruit's ctp libary
// Using Inland MEGA 2560 board
// Using Adafruit Rotary Encoder
// Rotary Encoder push button pins connected to: (a) ground; (b) pin 21

#include "Adafruit_FT6206.h"

// Global Variables

const byte  RotarybuttonPin  = 21;          // Define rotary push button pin as a Mega Interrupt pin
volatile byte Rotarybutton_Pressed_Flag;
TS_Point       touchpoint;

Adafruit_FT6206  ctp = Adafruit_FT6206();                // library from: ada_fruit company / Bithub


// ======================================== SETUP BLOCK ======================================

void setup() {
  ctp.begin(70);                          // passed value is screen touch sensitivity coeffceient
  Serial.begin(115200);   
  pinMode(RotarybuttonPin, INPUT_PULLUP);                                         // set RotarybuttonPin as an input, pull HIGH to provide 5V
  attachInterrupt(digitalPinToInterrupt(RotarybuttonPin), Button_Pin_ISR, LOW); // set an interrupt on RotarybuttonPin, define LOW pin value to execute Button_Pin_ISR
}


// ======================================== DEFINE ISR FUNCTION =========================================

void Button_Pin_ISR() {Rotarybutton_Pressed_Flag = 1;}            // set flag when button is pressed


// ======================================== MAIN LOOP =========================================

void loop() {

  Serial.println("In Loop!");
  touchpoint = WAIT_FOR_SCREEN_TOUCH();   
}


// ==================================== WAIT FOR SCREEN TOUCH ===============================

TS_Point WAIT_FOR_SCREEN_TOUCH() {
 
  CHECK_ROTARY_ENCODER();
  Serial.println("Entering 'While'");
 
//This next line locks the MEGA 2560 up with ctp function call
  while (!ctp.touched()) {CHECK_ROTARY_ENCODER();}             
  return (touchpoint);
}


// ==================================== CHECK ROTARY ENCODER ==================================

void CHECK_ROTARY_ENCODER() {

if (Rotarybutton_Pressed_Flag) {
   Serial.println("PRESSED");
    Rotarybutton_Pressed_Flag = 0;                                 // reset flag to zero
}
else {Serial.println("NOT PRESSED");}
delay(190);
   
}
 

JeffMD
 
Posts: 2
Joined: Wed Jul 18, 2018 10:21 pm

Re: 2.8" Capacitive Touch Screen with Interrupts?

by adafruit_support_rick on Thu Jul 19, 2018 10:26 am

Pin 21 is I2C SCL on a Mega. You can't use that for an interrupt, since it's already being used to talk to the FT-6206

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: 2.8" Capacitive Touch Screen with Interrupts?

by JeffMD on Fri Jul 20, 2018 12:01 am

Problem solved. Thanks for your guidance! Much appreciated. In learning more on the IC2, it appears that both pin 21 (SCL) and pin 20 (SDA) are unavailable for interrupts when using the FT6205 and the 2.8" TFT Display. Luckily the MEGA 2560 has six interrupt pins options (2, 3, 18, 19, 20, & 21). I have confirmed each of the other interrupts (2, 3, 18, or 19) allow the push button to work as expected.

I am using the 'shield' version of the 2.8" TFT, so access to pins 2 or 3 is a bit troublesome as header pin openings need to be shared; nevertheless, it is possible to insert a #22 gauge wire into header pins AND insert the shield. (You may wonder why not use the interrupts available on pins 18 or 19: I have reserved these interrupts for the clockwise /counterclockwise detection on the rotary encoder).

JeffMD
 
Posts: 2
Joined: Wed Jul 18, 2018 10:21 pm

Re: 2.8" Capacitive Touch Screen with Interrupts?

by adafruit_support_rick on Fri Jul 20, 2018 10:53 am

Oh, yeah. It is a bit sticky with the shield if you can't use 18 and 19.
You could also tack-solder a wire to the header for pin 2. Those are surface mount headers, so the pin is right there for soldering .

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Please be positive and constructive with your questions and comments.