TFT 2.8" LCD Touch wont if setup tft

by MauiMaker on Sat Feb 16, 2013 10:27 pm

I have one of your 2.8"TFT LCD + Touch (http://www.adafruit.com/products/335)
I have it mounted on a Mega 2560 using most of the pin outs per the tutorial.
I did move the X-/Y+ touch to A4/A5, and have TFT Reset connected to the arduino reset
I change code appropriately in the test code.

I can get the graphics working nicely, and the touchdemo works nicely too.
However, I cant get consistent results when I try any combination of using the tft and touch screen.
The tftpaint demo wont change colors and gives dots that do not correspond to touch points

When I run the touchdemo, it outputs position/pressure pretty regularly
.. i modified touchdemo with an else on the pressure test to simply Serial.print("0 ")
this gives an indication of no-read without taking too much screen/io space

If I graft that same code into the graphicstest, it does not output the same way.
I get a LOT more 0 reads and only the occasional Point read.
If I comment out the tftSetup, the touch runs fine. nice quick response (but no graphics)

(NOTE - PSTR() macro in graphicstest does not seem to work to id the chip)

Is there some oddity in moving the X-/Y+ to A4/A5 that would cause this discrepancy?
Jerry Isdale
Maui Makers
http://mauiMakers.com
MauiMaker
 
Posts: 58
Joined: Tue Dec 14, 2010 11:54 pm
Location: Haiku, Maui Hawaii USA

Re: TFT 2.8" LCD Touch wont if setup tft

by adafruit_support_rick on Sun Feb 17, 2013 2:40 pm

That sounds very strange.
Does it work using the suggested wiring from the tutorial?
Have you commented out #define USE_ADAFRUIT_SHIELD_PINOUT in Adafruit_TFTLCD.h?
User avatar
adafruit_support_rick
 
Posts: 8585
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: TFT 2.8" LCD Touch wont if setup tft

by adafruit on Sun Feb 17, 2013 5:52 pm

MauiMaker wrote:I have one of your 2.8"TFT LCD + Touch (http://www.adafruit.com/products/335)
I have it mounted on a Mega 2560 using most of the pin outs per the tutorial.
I did move the X-/Y+ touch to A4/A5, and have TFT Reset connected to the arduino reset
I change code appropriately in the test code.

Is there some oddity in moving the X-/Y+ to A4/A5 that would cause this discrepancy?


so you aren't using the tutorial code/wiring and its not working quite right?

have you tried the exact tutorial wiring?

it seems like the easiest way to tell how your changes affect the program is to first verify if the tutorial works, and -then- modify it :D
User avatar
adafruit
 
Posts: 11509
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: TFT 2.8" LCD Touch wont if setup tft

by MauiMaker on Tue Feb 19, 2013 10:20 pm

Ok - i ripped apart the cable I made up to keep all the pins going into the Midi breakout header together and moved X-/Y+ from A4/5 to A2/A3 (which means they are shared with the TFT). To do this I am using the Screw shield to access A2/3.
Fine - it is all wired up according to the tutorial (http://www.ladyada.net/products/tfttouchbreakout/)
which, by the way does say on the Mega you can use A4/5 for these lines.

There is no demo provided by Adafruilt libraries that exercises BOTH the TFT and Touch... except perhaps tftpaint - which doesnt work well. So I created graphics_touch_test by merging the graphics demo and touch demo... a bit of code cleanup to put their setup/test code in functions instead of inline setup/loop. Now you can comment out/in parts and see from same code base what works.

I still get the same problem. Code is included in next reply.
If I comment out the tftSetup() the touch responds nice and quick.
If I uncomment tftSetup() the touch rarely responds.

I say there is an issue with the TFT Code and Touch on the Mega.
I will forgo using the touch, perhaps the entire board for this project - which needs to be operational in 2 days.
Jerry Isdale
Maui Makers
http://mauiMakers.com
MauiMaker
 
Posts: 58
Joined: Tue Dec 14, 2010 11:54 pm
Location: Haiku, Maui Hawaii USA

Re: TFT 2.8" LCD Touch wont if setup tft

by MauiMaker on Tue Feb 19, 2013 10:21 pm

Code below is graphics_touch_test

Code: Select all
// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY
// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.
// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP.
// Feb 19, 2013 - jerry isdale (isdale@gmail.com)
// Includes TouchScreen Demo code
// merged code by breaking each setup & test into separate functions
// which makes it easier to comment out for debugging
//
// also This version was setup for Mega 2560, using A4/5 for touch
// and connecting to Arduino reset line

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library

#include <stdint.h>
#include "TouchScreen.h"

#define YP A2  // A2 | A4 must be an analog pin, use "An" notation!
#define XM A3  // A3 | A5 must be an analog pin, use "An" notation!
#define YM 8   // can be a digital pin
#define XP 9   // can be a digital pin

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
// mine is 267
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 267);

// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

#define LCD_RESET 0 //A4 // Can alternately just connect to Arduino's reset pin

// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
// For the Arduino Uno, Duemilanove, Diecimila, etc.:
//   D0 connects to digital pin 8  (Notice these are
//   D1 connects to digital pin 9   NOT in order!)
//   D2 connects to digital pin 2
//   D3 connects to digital pin 3
//   D4 connects to digital pin 4
//   D5 connects to digital pin 5
//   D6 connects to digital pin 6
//   D7 connects to digital pin 7
// For the Arduino Mega, use digital pins 22 through 29
// (on the 2-row header at the end of the board).

// 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(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Adafruit_TFTLCD tft;

boolean tftIsSetup = 0;

void setup(void) {
  Serial.begin(9600);
  Serial.println("TFT LCD + Touch test");

#ifdef USE_ADAFRUIT_SHIELD_PINOUT
  Serial.println("Using Adafruit 2.8\" TFT Arduino Shield Pinout");
#else
  Serial.println("Using Adafruit 2.8\" TFT Breakout Board Pinout");
#endif

//  tftSetup();
////  tftAllGfx();
//  // touch does not require setup
//  doRotationTest();
  tft_message("End Setup Begin Loop");
  Serial.println("End Setup Begin Loop");
}

void loop(void) {
//    doRotationTest();
  doTouchScreen();
}

/////////////
int counter =0;
void doTouchScreen()
{
    // a point object holds x y and z coordinates
  Point p = ts.getPoint();
 
  // 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);
      tft_Point(&p);
  }
  else {
      tft_message("No Touch");
    Serial.print("0 ");
    if (++counter % 40 == 0) {
      counter = 0;
      Serial.println(".");
    }
  }
  delay(100);
}
///////////////////////////////////////

void tftSetup()
{
  Serial.println("TFT Setup");
  tft.reset();
  tftIsSetup = 1;

  uint16_t identifier = tft.readID();

  // note adafruit library version has weird macro/func around text
  // it was found to be defective and removed
  if(identifier == 0x9325) {
    Serial.println("Found ILI9325 LCD driver");
  } else if(identifier == 0x9328) {
    Serial.println("Found ILI9328 LCD driver");
  } else if(identifier == 0x7575) {
    Serial.println("Found HX8347G LCD driver");
  } else {
    Serial.print("Unknown LCD driver chip: ");
    Serial.println(identifier, HEX);
    Serial.println("If using the Adafruit 2.8\" TFT Arduino shield, the line:");
    Serial.println("  #define USE_ADAFRUIT_SHIELD_PINOUT");
    Serial.println("should appear in the library header (Adafruit_TFT.h).");
    Serial.println("If using the breakout board, it should NOT be #defined!");
    Serial.println("Also if using the breakout, double-check that all wiring");
    Serial.println("matches the tutorial.");
    return;
  }

  tft.begin(identifier);
  tft_message("TFT SETUP COMPLETE");
}

// added tft_message = clear screen + write text
void tft_message(char*msg) {
  if (tftIsSetup == 0) return;
  tft.fillScreen(BLACK);
  unsigned long start = micros();
  tft.setCursor(0, 0);
  tft.setTextColor(WHITE);  tft.setTextSize(2);
  tft.println(msg);
}

// added tft_Point = clear screen + write Point data
void tft_Point(Point*ppoint) {
  if (tftIsSetup == 0) return;

  tft.fillScreen(BLACK);
  unsigned long start = micros();
  tft.setCursor(0, 0);
  tft.setTextColor(WHITE);  tft.setTextSize(2);
  tft.print("Touch: ");
  tft.print(ppoint->x);
  tft.print(" ");
  tft.print(ppoint->y);
  tft.print(" ");
  tft.println(ppoint->z);
}


void doRotationTest()
{
  for(uint8_t rotation=0; rotation<4; rotation++) {
    tft.setRotation(rotation);
    testText();
    delay(1000);
  }
}

void tftAllGfx()
{
  Serial.println("Benchmark                Time (microseconds)");

  Serial.print("Screen fill              ");
  Serial.println(testFillScreen());
  delay(500);

  Serial.print("Text                     ");
  Serial.println(testText());
  delay(3000);

  Serial.print("Lines                    ");
  Serial.println(testLines(CYAN));
  delay(500);

  Serial.print("Horiz/Vert Lines         ");
  Serial.println(testFastLines(RED, BLUE));
  delay(500);

  Serial.print("Rectangles (outline)     ");
  Serial.println(testRects(GREEN));
  delay(500);

  Serial.print("Rectangles (filled)      ");
  Serial.println(testFilledRects(YELLOW, MAGENTA));
  delay(500);

  Serial.print("Circles (filled)         ");
  Serial.println(testFilledCircles(10, MAGENTA));

  Serial.print("Circles (outline)        ");
  Serial.println(testCircles(10, WHITE));
  delay(500);

  Serial.print("Triangles (outline)      ");
  Serial.println(testTriangles());
  delay(500);

  Serial.print("Triangles (filled)       ");
  Serial.println(testFilledTriangles());
  delay(500);

  Serial.print("Rounded rects (outline)  ");
  Serial.println(testRoundRects());
  delay(500);

  Serial.print("Rounded rects (filled)   ");
  Serial.println(testFilledRoundRects());
  delay(500);

  Serial.println("Done!");
}

unsigned long testFillScreen() {
  unsigned long start = micros();
  tft.fillScreen(BLACK);
  tft.fillScreen(RED);
  tft.fillScreen(GREEN);
  tft.fillScreen(BLUE);
  tft.fillScreen(BLACK);
  return micros() - start;
}

unsigned long testText() {
  tft.fillScreen(BLACK);
  unsigned long start = micros();
  tft.setCursor(0, 0);
  tft.setTextColor(WHITE);  tft.setTextSize(1);
  tft.println("Hello World!");
  tft.setTextColor(YELLOW); tft.setTextSize(2);
  tft.println(1234.56);
  tft.setTextColor(RED);    tft.setTextSize(3);
  tft.println(0xDEADBEEF, HEX);
  tft.println();
  tft.setTextColor(GREEN);
  tft.setTextSize(5);
  tft.println("Groop");
  tft.setTextSize(2);
  tft.println("I implore thee,");
  tft.setTextSize(1);
  tft.println("my foonting turlingdromes.");
  tft.println("And hooptiously drangle me");
  tft.println("with crinkly bindlewurdles,");
  tft.println("Or I will rend thee");
  tft.println("in the gobberwarts");
  tft.println("with my blurglecruncheon,");
  tft.println("see if I don't!");
  return micros() - start;
}

unsigned long testLines(uint16_t color) {
  unsigned long start, t;
  int           x1, y1, x2, y2,
                w = tft.width(),
                h = tft.height();

  tft.fillScreen(BLACK);

  x1 = y1 = 0;
  y2    = h - 1;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = w - 1;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t     = micros() - start; // fillScreen doesn't count against timing

  tft.fillScreen(BLACK);

  x1    = w - 1;
  y1    = 0;
  y2    = h - 1;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = 0;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t    += micros() - start;

  tft.fillScreen(BLACK);

  x1    = 0;
  y1    = h - 1;
  y2    = 0;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = w - 1;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t    += micros() - start;

  tft.fillScreen(BLACK);

  x1    = w - 1;
  y1    = h - 1;
  y2    = 0;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = 0;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);

  return micros() - start;
}

unsigned long testFastLines(uint16_t color1, uint16_t color2) {
  unsigned long start;
  int           x, y, w = tft.width(), h = tft.height();

  tft.fillScreen(BLACK);
  start = micros();
  for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
  for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);

  return micros() - start;
}

unsigned long testRects(uint16_t color) {
  unsigned long start;
  int           n, i, i2,
                cx = tft.width()  / 2,
                cy = tft.height() / 2;

  tft.fillScreen(BLACK);
  n     = min(tft.width(), tft.height());
  start = micros();
  for(i=2; i<n; i+=6) {
    i2 = i / 2;
    tft.drawRect(cx-i2, cy-i2, i, i, color);
  }

  return micros() - start;
}

unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
  unsigned long start, t = 0;
  int           n, i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  n = min(tft.width(), tft.height());
  for(i=n; i>0; i-=6) {
    i2    = i / 2;
    start = micros();
    tft.fillRect(cx-i2, cy-i2, i, i, color1);
    t    += micros() - start;
    // Outlines are not included in timing results
    tft.drawRect(cx-i2, cy-i2, i, i, color2);
  }

  return t;
}

unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
  unsigned long start;
  int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;

  tft.fillScreen(BLACK);
  start = micros();
  for(x=radius; x<w; x+=r2) {
    for(y=radius; y<h; y+=r2) {
      tft.fillCircle(x, y, radius, color);
    }
  }

  return micros() - start;
}

unsigned long testCircles(uint8_t radius, uint16_t color) {
  unsigned long start;
  int           x, y, r2 = radius * 2,
                w = tft.width()  + radius,
                h = tft.height() + radius;

  // Screen is not cleared for this one -- this is
  // intentional and does not affect the reported time.
  start = micros();
  for(x=0; x<w; x+=r2) {
    for(y=0; y<h; y+=r2) {
      tft.drawCircle(x, y, radius, color);
    }
  }

  return micros() - start;
}

unsigned long testTriangles() {
  unsigned long start;
  int           n, i, cx = tft.width()  / 2 - 1,
                      cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  n     = min(cx, cy);
  start = micros();
  for(i=0; i<n; i+=5) {
    tft.drawTriangle(
      cx    , cy - i, // peak
      cx - i, cy + i, // bottom left
      cx + i, cy + i, // bottom right
      tft.color565(0, 0, i));
  }

  return micros() - start;
}

unsigned long testFilledTriangles() {
  unsigned long start, t = 0;
  int           i, cx = tft.width()  / 2 - 1,
                   cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  start = micros();
  for(i=min(cx,cy); i>10; i-=5) {
    start = micros();
    tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
      tft.color565(0, i, i));
    t += micros() - start;
    tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
      tft.color565(i, i, 0));
  }

  return t;
}

unsigned long testRoundRects() {
  unsigned long start;
  int           w, i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  w     = min(tft.width(), tft.height());
  start = micros();
  for(i=0; i<w; i+=6) {
    i2 = i / 2;
    tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
  }

  return micros() - start;
}

unsigned long testFilledRoundRects() {
  unsigned long start;
  int           i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  start = micros();
  for(i=min(tft.width(), tft.height()); i>20; i-=6) {
    i2 = i / 2;
    tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
  }

  return micros() - start;
}
Jerry Isdale
Maui Makers
http://mauiMakers.com
MauiMaker
 
Posts: 58
Joined: Tue Dec 14, 2010 11:54 pm
Location: Haiku, Maui Hawaii USA

Re: TFT 2.8" LCD Touch wont if setup tft

by adafruit_support_rick on Wed Feb 20, 2013 8:46 pm

Jerry -

I loaded your sketch on my Mega. I've got the shield version of the screen, so I changed the definitions of YP, etc., as follows:
Code: Select all
#ifdef USE_ADAFRUIT_SHIELD_PINOUT
// 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
#else
#define YP A2  // A2 | A4 must be an analog pin, use "An" notation!
#define XM A3  // A3 | A5 must be an analog pin, use "An" notation!
#define YM 8   // can be a digital pin
#define XP 9   // can be a digital pin
#endif


This is the only change I made. The sketch seems to run fine. Here's a sample of the output for a touch - does this correspond to what you're seeing?
Code: Select all
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .
0 0 0 0 0 0 0 0 0 0 0 0 X = 556   Y = 471   Pressure = 356
0 X = 546   Y = 460   Pressure = 276
X = 542   Y = 464   Pressure = 241
X = 544   Y = 464   Pressure = 236
X = 546   Y = 464   Pressure = 225
X = 551   Y = 466   Pressure = 220
X = 546   Y = 465   Pressure = 209
X = 545   Y = 466   Pressure = 201
X = 545   Y = 466   Pressure = 190
0 X = 545   Y = 463   Pressure = 202
X = 545   Y = 462   Pressure = 191
X = 549   Y = 465   Pressure = 195
X = 549   Y = 461   Pressure = 194
X = 547   Y = 457   Pressure = 197
X = 547   Y = 455   Pressure = 196
X = 550   Y = 457   Pressure = 215
X = 551   Y = 456   Pressure = 204
X = 549   Y = 454   Pressure = 213
X = 551   Y = 455   Pressure = 208
X = 551   Y = 452   Pressure = 198
X = 551   Y = 452   Pressure = 183
X = 551   Y = 452   Pressure = 180
X = 551   Y = 456   Pressure = 195
0 X = 544   Y = 466   Pressure = 221
0 0 X = 550   Y = 479   Pressure = 195
0 X = 555   Y = 477   Pressure = 183
X = 549   Y = 473   Pressure = 187
X = 549   Y = 462   Pressure = 185
0 X = 551   Y = 456   Pressure = 245
X = 545   Y = 462   Pressure = 250
0 X = 435   Y = 449   Pressure = 391
X = 424   Y = 455   Pressure = 337
0 X = 367   Y = 490   Pressure = 247
X = 415   Y = 510   Pressure = 363
X = 426   Y = 495   Pressure = 369
0 0 0 0 0 0 X = 375   Y = 370   Pressure = 1256
0 X = 360   Y = 426   Pressure = 254
X = 340   Y = 425   Pressure = 222
X = 332   Y = 419   Pressure = 209
0 X = 335   Y = 417   Pressure = 194
X = 333   Y = 417   Pressure = 201
0 X = 329   Y = 419   Pressure = 210
0 0 0 0 0 X = 424   Y = 421   Pressure = 2370
0 0 0 0 0 .
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .
User avatar
adafruit_support_rick
 
Posts: 8585
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: TFT 2.8" LCD Touch wont if setup tft

by MauiMaker on Fri Feb 22, 2013 4:51 pm

I will get back to this soon (someday?)
The project has moved on without LCD display... and now is Mega ADK based as my 2560's regulator blew.
ADK version also lets us drop the MIDI shield and go straight to usb midi.
Stay tooned for pics of Midi Poof in action (8x propane flares)
Jerry Isdale
Maui Makers
http://mauiMakers.com
MauiMaker
 
Posts: 58
Joined: Tue Dec 14, 2010 11:54 pm
Location: Haiku, Maui Hawaii USA