2.8 TFT Shield Slow after adding touch feature on Mega
Moderators: adafruit_support_bill, adafruit

2.8 TFT Shield Slow after adding touch feature on Mega

by urthlight on Thu Dec 06, 2012 8:45 pm

I have 2 of the 2.8" TFT Shields from the last batch. Plugged into 2 Mega 2560 Arduinos I have my program written and working for the most part.The valves are popping the pumps are pumping. The agitator is running. The timers are timing. Got the display up and displaying. Sweet, I have Two buttons plugged in right now , YES and ABORT.
Everything is peachy. I have it running for a few days as I play with the other Mega/TFT and the touch screen examples. Now I have my two touch buttons mapped and Printing to the serial monitor "Button 1" and "Button 2" on the second platform. Upon moving this piece of code into the unit I get the touch screen working but the display whites out. Ahhh the shared pins! Using The paint example as a guide I get the pin sharing working.

Now....the program is so slow you have to hold the soft button and wait for the update. Not good.
The Paint Program did not seem to have this problem

do I need to get rid of the shared pins?
Is there some clever code that I am missing?
Do I need a dedicated Arduino for the display? I have an Uno I could use.Maybe a SPI connection.

HELP!
HELP!



The gist of it is here
Code: Select all | TOGGLE FULL SIZE
#include <stdint.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>

#ifndef USE_ADAFRUIT_SHIELD_PINOUT
 #error "This sketch is intended for use with the TFT LCD Shield. Make sure that USE_ADAFRUIT_SHIELD_PINOUT is #defined in the Adafruit_TFTLCD.h library file."
#endif

// These are the pins for the shield!
#define YP A1  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 7   // can be a digital pin
#define XP 6   // can be a digital pin

#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940


TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0

// Assign human-readable names to some common 16-bit color values:
#define   BLACK   0x0000
#define   BLUE    0x001F
#define   RED     0xF800
#define   GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF


Adafruit_TFTLCD tft;

#define BOXSIZE   40
#define PENRADIUS  4
int oldcolor, currentcolor;

void setup(void) {
  Serial.begin(9600);
  //progmemPrintln(PSTR("Paint!"));
  tft.reset();
  uint16_t identifier = tft.readID();
  tft.begin(identifier);
 tft.fillScreen(BLACK);
 pinMode(13, OUTPUT);
}

#define MINPRESSURE 10
#define MAXPRESSURE 1000

void loop()
{
  tft.setCursor(0, 0);
   tft.fillScreen(BLACK);
  tft.setTextColor(GREEN);
  tft.setTextSize(5);
  tft.println("Waiting");
  digitalWrite(13, HIGH);
  Point p = ts.getPoint();
  digitalWrite(13, LOW);

  // if sharing pins, you'll need to fix the directions of the touchscreen pins
  //pinMode(XP, OUTPUT);
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  //pinMode(YM, OUTPUT);

  // we have some minimum pressure we consider 'valid'
  // pressure of 0 means no pressing!

  if (p.z > ts.pressureThreshhold) {
     Serial.print("X = "); Serial.print(p.x);
     Serial.print("\tY = "); Serial.print(p.y);
     Serial.print("\tPressure = "); Serial.println(p.z);
  }

 
 }


urthlight
 
Posts: 15
Joined: Thu Dec 06, 2012 3:16 pm

Re: 2.8 TFT Shield Slow after adding touch feature on Mega

by adafruit_support_bill on Fri Dec 07, 2012 7:05 am

These are always slower on a Mega due to the software SPI. It sounds like you are reaching the practical limits of what you can do on a Mega. A separate display controller might work - if you can minimize the communication requirements between that and the main processor. An UNO would be a good choice.
User avatar
adafruit_support_bill
 
Posts: 32625
Joined: Sat Feb 07, 2009 10:11 am

Re: 2.8 TFT Shield Slow after adding touch feature on Mega

by urthlight on Fri Dec 07, 2012 11:32 am

This is the offending code. This function bogs every thing down When added. Could this be done in an ISR perhaps

digitalWrite(13, HIGH);
Point p = ts.getPoint();
digitalWrite(13, LOW);

Apparently y'all sell many of these surely I am not the only one with this problem. Or even the first.

Update: The Uno is a little better but still too slow to be useful
urthlight
 
Posts: 15
Joined: Thu Dec 06, 2012 3:16 pm

Re: 2.8 TFT Shield Slow after adding touch feature on Mega

by adafruit_support_bill on Fri Dec 07, 2012 11:56 am

Could this be done in an ISR perhaps

That would be tricky. Pin 13 is used for the LCD and SD too. You wouldn't want the ISR to trash any card or screen access in progress.
User avatar
adafruit_support_bill
 
Posts: 32625
Joined: Sat Feb 07, 2009 10:11 am

Re: 2.8 TFT Shield Slow after adding touch feature on Mega

by urthlight on Fri Dec 07, 2012 3:54 pm

So... You would recommend?
urthlight
 
Posts: 15
Joined: Thu Dec 06, 2012 3:16 pm

Re: 2.8 TFT Shield Slow after adding touch feature on Mega

by adafruit_support_bill on Fri Dec 07, 2012 4:06 pm

Hard to say without knowing the scope and constraints of your project. But an UNO is inherently faster (approx 2x) than the Mega with this shield.
User avatar
adafruit_support_bill
 
Posts: 32625
Joined: Sat Feb 07, 2009 10:11 am