Tft Touch shield

Greetings!!

Here below in the link is the picture Tft touch shield that I have.
http://www.electroniccomponentsonline.co.in/how-to-use-2.4inch-tft-lcd-mcufriend

The ports Used by the Shield are mentioned in it. I wish to create buttons using the shield. In order to perform actions for the buttons I wanted to use some pins. But as seen in the link all pins are being used by the Shield.

Now coming to the digital pin 10, 11, 12, 13. They are used for SD select/data/clock. Since I am not interfacing the SD with the Arduino or the tft shield, these pins will not be in use in my program.
So I assumed I would be able to use them for other purpose. In order to verify this I ran an example code which does not involve the SD . In the void loop of this code I made a LED blink connecting it to pin D11. When I uploaded the code to the arduino, only the LED blinked and the tft screen did not respond. It could not sense the touch .
What could have been the reason for it?
Are there any means by which I will be able to use those pins?
Or is there any other way to achieve what I wish to do?
Thanks
Regards!

82365970LCDTFT214328318111442478039.jpg

tft shield 2.jpg

You have a regular mcufriend 2.4" shield. They have several different controllers but obey the pin-out as printed on the silkscreen.

Since you can display on the TFT, you obviously have a library that recognises and understands your particular controller chip. I would recommend the Adafruit style of library. UTFT does not understand that you have a RD pin on Analog#0 (which needs to be OUTPUT and HIGH)

Your LED should not interfere with the TFT. Post your LED sketch here with the Code tags i.e. the </> icon.

David.

I do have installed Adafruit.GFX library and also SWTFT library and TouchScreeen library which recognizes my code.

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




#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

// 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
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);



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


SWTFT tft;

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

void setup(void) {
  Serial.begin(9600);
  Serial.println(F("Paint!"));
  
  tft.reset();
  
  uint16_t identifier = tft.readID();

  Serial.print(F("LCD driver chip: "));
  Serial.println(identifier, HEX);
    

  tft.begin(identifier);

  tft.fillScreen(BLACK);

  tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED);
  tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW);
  tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN);
  tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN);
  tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE);
  tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA);
  // tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, WHITE);
 
  tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE);
  currentcolor = RED;
 pinMode(11,OUTPUT);//for the LED
  pinMode(13, OUTPUT);
}

#define MINPRESSURE 10
#define MAXPRESSURE 1000

void loop()
{
  digitalWrite(13, HIGH);
  // Recently Point was renamed TSPoint in the TouchScreen library
  // If you are using an older version of the library, use the
  // commented definition instead.
  // Point p = ts.getPoint();
  TSPoint 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 > MINPRESSURE && p.z < MAXPRESSURE) {
    /*
    Serial.print("X = "); Serial.print(p.x);
    Serial.print("\tY = "); Serial.print(p.y);
    Serial.print("\tPressure = "); Serial.println(p.z);
    */
    
    if (p.y < (TS_MINY-5)) {
      Serial.println("erase");
      // press the bottom of the screen to erase 
      tft.fillRect(0, BOXSIZE, tft.width(), tft.height()-BOXSIZE, BLACK);
    }
    // scale from 0->1023 to tft.width
    p.x = tft.width()-(map(p.x, TS_MINX, TS_MAXX, tft.width(), 0));
    p.y = tft.height()-(map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
    /*
    Serial.print("("); Serial.print(p.x);
    Serial.print(", "); Serial.print(p.y);
    Serial.println(")");
    */
    if (p.y < BOXSIZE) {
       oldcolor = currentcolor;

       if (p.x < BOXSIZE) { 
         currentcolor = RED; 
         tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE);
       } else if (p.x < BOXSIZE*2) {
         currentcolor = YELLOW;
         tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, WHITE);
       } else if (p.x < BOXSIZE*3) {
         currentcolor = GREEN;
         tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, WHITE);
       } else if (p.x < BOXSIZE*4) {
         currentcolor = CYAN;
         tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, WHITE);
       } else if (p.x < BOXSIZE*5) {
         currentcolor = BLUE;
         tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, WHITE);
       } else if (p.x < BOXSIZE*6) {
         currentcolor = MAGENTA;
         tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, WHITE);
       }

       if (oldcolor != currentcolor) {
          if (oldcolor == RED) tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED);
          if (oldcolor == YELLOW) tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW);
          if (oldcolor == GREEN) tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN);
          if (oldcolor == CYAN) tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN);
          if (oldcolor == BLUE) tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE);
          if (oldcolor == MAGENTA) tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA);
       }
    }
    if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) {
      tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
    }
  }//below is what i did to check the pin
  digitalWrite(11,HIGH);
  delay(1000);
  digitalWrite(11,LOW);
  delay(1000);

}

I had just tried to blink the LED in the Example (tftpaint) code which was available. Because pin D11 was not used i was expecting it to work.

I am just trying my hands on Tft Shield.
Sorry If I sound naive.
Thank you

You might look through the libraries. I suspect something
is using those pins.
Dwight

Well, I Googled for SWTFT. Installed the library. Ran the examples on a Mcufriend Shield (ILI9325).
They worked fine. (My Touch needed the X direction reversed)

I then tried your sketch. It cripples the Paint response. Basically by inserting 2000ms delays into the loop(). This rather restricts the response to any budding Artist !!

No, I have not looked at the SWTFT controller support. I could try other controllers. Which controller do you have? Run an example and observe the Serial Terminal.

David.

Thanks Dwight and David

@Dwight I went through the libraries used in the sketch. I could not find the usage of those pins. But because I am just getting along with the TFT, It may have been that I was not able to recognize it being used in the library code, but such a possibility is narrow. I would be grateful if you had a look into those libraries if available to you. thank you again

David thanks to you as well.
The X direction was reversed in my touch as well;)

What I understood from your reply was the 2000ms delay caused the problem. If that is the case then I will have to try something different. As mentioned in the beginning I wished to create buttons for the TFT , so in that case there should not be any hinderance for performing the actions assigned to the buttons. Please correct me if I misunderstood.

Sir, I did not follow you on the last part

david_prentice:
No, I have not looked at the SWTFT controller support. I could try other controllers. Which controller do you have? Run an example and observe the Serial Terminal.

What SWTFT controller were you referring to?
What controllers did you try?
When I checked the serial Terminal all it said was
“Paint!
LCD driver chip: 9325”

This was for the same example sketch(tfpaint) from SWTFT library.

Study the logic of the Paint program. i.e. it reads the Touch location on every pass through loop()
If the stylus matches a certain (button) area, it changes colour.

You will also notice that it tries to "average" a few stylus readings. Otherwise you get random dots on the screen.

Yes, I guessed correctly. You have an ILI9325 controller. You just need to swap the XMIN and XMAX values. Then you get the correct mapping of the Touch.

David.

Looking at other things on the web about these I see two things.
One says that if not using the SD reader, you can use D12, nothing
about D11.
There is also a note about putting some insulating tape on the top of
your USB connector to keep it from shorting.
Dwight

@ David .
The swapping worked. Now the touch is working fine. thanks for everything.

@Dwight
USB port has been insulated:)
thanks

It depends on how the shield does the level-shifting for the 3.3V microSD.
Normally, there are just series resistors on the signal lines with the SD having VCC=3.3V

If the schematic has level-shifter buffer chips, MISO will connect to the buffer output. MOSI, SS, SCK will connect to buffer inputs. So there will be a fight on MISO with an AVR output driver. The other pins present no loading.

David.