Waveshare TFT LCD touch doesnt work in tandem with the display code

Hi all
i have been bashing my head against this 2.8 inch Waveshare TFT LCD shield.I got the display part working just fine and the touchscreen working with the xtp2046_Touchscreen library.The shield uses a HX8347D so originaly i thought of using the included waveshare library which i found out is not all that good, so then i tried using David Prentice's library based on the Adafruit gfx library wich was a much better experince.However when i try and put it all together i always have the same problem.The display part works just fine but the touchscreen instead of writing to the serial monitor whenever i touch it it always no matter if i touch it or not it writes y=0 x=0 and pressure=4095 to the serial monitor.I believe that the problem has to do with SPI.The display and touchscreen both use spi and share the pins so i feel it might have to do with that.This is my first time using spi so any advice would be greatly appreciated
This is my sketch with the GFX based library

#define LCD_CS 10 // 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 A4 // Can alternately just connect to Arduino's reset pin
#include <XPT2046_Touchscreen.h>


#include <SPI.h>          // f.k. for Arduino-1.5.2
#include "Adafruit_GFX.h"// Hardware-specific library
#include <HX8347D_kbv.h>
HX8347D_kbv tft;
//#include <MCUFRIEND_kbv.h>
//MCUFRIEND_kbv tft;
//#include <Adafruit_TFTLCD.h>
//Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
uint16_t g_identifier;

#define CS_PIN  3
// MOSI=11, MISO=12, SCK=13

//XPT2046_Touchscreen ts(CS_PIN);

XPT2046_Touchscreen ts(CS_PIN);  // Param 2 - NULL - No interrupts
//XPT2046_Touchscreen ts(CS_PIN, 255);  // Param 2 - 255 - No interrupts
//XPT2046_Touchscreen ts(CS_PIN, TIRQ_PIN);  // Param 2 - Touch IRQ Pin - interrupt enabled polling

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

void setup() {
pinMode(10,OUTPUT);
pinMode(3,OUTPUT);
digitalWrite(10,HIGH);
digitalWrite(3,HIGH);

  // put your setup code here, to run once:
    Serial.begin(9600);
     static uint16_t identifier;
    //    tft.reset();                 //we can't read ID on 9341 until begin()
    g_identifier = tft.readID(); //
 tft.begin(g_identifier);
 ts.begin();
  ts.setRotation(1);
  while (!Serial && (millis() <= 1000));
}

void loop() {
  // put your main code here, to run repeatedly:
  if (ts.touched()) {
    TS_Point p = ts.getPoint();
    Serial.print("Pressure = ");
    Serial.print(p.z);
    Serial.print(", x = ");
    Serial.print(p.x);
    Serial.print(", y = ");
    Serial.print(p.y);
    delay(30);
    Serial.println();
  }
}

And this is the sketch with the included Wavehsare library

#include <stdint.h>
#include <HX8347D.h>
#include <XPT2046_Touchscreen.h>
#include <SPI.h>

#define CS_PIN  3

#define TIRQ_PIN  2
XPT2046_Touchscreen ts(CS_PIN);  // Param 2 - NULL - No interrupts




void setup()
{  
      pinMode(10,OUTPUT);
      pinMode(3,OUTPUT);
      digitalWrite(10,HIGH);
      digitalWrite(3,HIGH);
      
      __SD_CS_DISABLE();
    
    SPI.setDataMode(SPI_MODE3);
    SPI.setBitOrder(MSBFIRST);
    SPI.setClockDivider(SPI_CLOCK_DIV4);
    SPI.begin();
    
  Serial.begin(38400);

 ts.begin();
  ts.setRotation(1);
  while (!Serial && (millis() <= 1000));

  //  Tft.lcd_init();                                      // init TFT library

/*   
    Tft.lcd_clear_screen(RED);
    Tft.lcd_fill_rect(77,0,6,290,BLACK);
    Tft.lcd_fill_rect(157,0,6,290,BLACK);
    Tft.lcd_fill_rect(0,77,240,6,BLACK);
    Tft.lcd_fill_rect(0,157,240,6,BLACK);
    Tft.lcd_fill_rect(0,237,240,6,BLACK);
    //Tft.lcd_fill_rect(0,270,83,6,BLACK);
    //Tft.lcd_fill_rect(157,270,83,6,BLACK);
  Tft.lcd_fill_rect(0,290,240,6,BLACK);
    Tft.lcd_display_num(34,33,1,1,FONT_1608,BLACK);
    Tft.lcd_display_num(114,113,5,1,FONT_1608,BLACK);
    Tft.lcd_display_num(34,113,4,1,FONT_1608,BLACK);
    Tft.lcd_display_num(114,34,2,1,FONT_1608,BLACK);
    Tft.lcd_display_num(194,194,9,1,FONT_1608,BLACK);
    Tft.lcd_display_num(114,34,2,1,FONT_1608,BLACK);
    Tft.lcd_display_num(34,194,7,1,FONT_1608,BLACK);
    Tft.lcd_display_num(114,194,8,1,FONT_1608,BLACK);
    Tft.lcd_display_num(194,34,3,1,FONT_1608,BLACK);
    Tft.lcd_display_num(194,114,6,1,FONT_1608,BLACK);
    Tft.lcd_display_num(114,254,0,1,FONT_1608,BLACK);
*/

 pinMode(10,OUTPUT);
      pinMode(3,OUTPUT);
      digitalWrite(10,HIGH);
      digitalWrite(3,HIGH);
}



  void loop() {

  if (ts.touched()) {
    TS_Point p = ts.getPoint();
    Serial.print("Pressure = ");
    Serial.print(p.z);
    Serial.print(", x = ");
    Serial.print(p.x);
    Serial.print(", y = ");
    Serial.print(p.y);
    delay(30);
    Serial.println();
  }
}

Thanks in advance

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.