Go Down

Topic: Adafruit 2.8 TFT Shield Slow after adding touch feature on Mega (Read 859 times) previous topic - next topic

urthlight

I have 2 of the 2.8" TFT Shields from Adafruit 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]
   #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);
     }

   
   }






This is the offending code. This function bogs every thing down When added.
Code: [Select]

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

It was suggested that i had "reached the practical limits of what you can do on a Mega." But on the uno it was only marginally better.

Anybody familiar with this issue?

PaulS

Quote
It was suggested that i had "reached the practical limits of what you can do on a Mega." But on the uno it was only marginally better.

Since the Mega has more code space, and more memory, I'd expect it to wok better on the Mega than the UNO.

Code: [Select]
      Serial.begin(9600);
The stone age ended a long time ago. Pick up the pace!

Code: [Select]
      // 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);

On every pass through loop()? I doubt it.

Code: [Select]
      tft.setCursor(0, 0);
       tft.fillScreen(BLACK);
      tft.setTextColor(GREEN);
      tft.setTextSize(5);
      tft.println("Waiting");

On every pass through loop()? Again, I doubt it.

urthlight

#2
Dec 08, 2012, 03:04 am Last Edit: Dec 08, 2012, 03:44 am by urthlight Reason: 1
"The stone age ended a long time ago. Pick up the pace!"



Well my wixel gave me problems over 9600 so Ihave been doing everything at that speed. And it is only for debugging.


Code: [Select]
tft.setCursor(0, 0);
      tft.fillScreen(BLACK);
     tft.setTextColor(GREEN);
     tft.setTextSize(5);
     tft.println("Waiting");


On every pass through loop()? Again, I doubt it.


No I have a counter that only bulds the screen the first time through the loop. This was just a frag to show the effect.

Code: [Select]

   // 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);


On every pass through loop()? I doubt it.

So maybe poll every 10th or 100th iteration of the loop ?



PaulS

Quote
So maybe poll every 10th or 100th iteration of the loop ?

Why isn't that in setup()?

Go Up