Can TFT and Touch be both connected to VSPI?

trailsurfer604
Posts: 2
Joined: Wed Dec 21, 2022 10:03 pm

Can TFT and Touch be both connected to VSPI?

Postby trailsurfer604 » Wed Dec 21, 2022 10:41 pm

Hello,

I am using an ESP32 NodeMCU-32S and a 2.4" TFT ILI9341 display with XPT2046 touch controller (this one http://www.lcdwiki.com/2.4inch_SPI_Modu ... KU:MSP2402)

I understood that I could save both, TFT and Touch, off the VSPI, and thus connected both to the default VSPI pins, the only custom pin is CS, as follows:

Code: Select all

//  Display SPI  - default VSPI for ESP32 WROOM32
#define TFT_MISO 19  // shared with T_DO
#define TFT_MOSI 23  // shared with T_DIN
#define TFT_SCLK 18  // shared with T_CLK
#define TFT_CS    5   // Chip select control pin
#define TFT_DC    4   // Data Command control pin
#define TFT_RST   2  // Reset pin (could connect to RST pin)   
#define TFT_BL          16    // backlight

// screen initialization 
Adafruit_ILI9341 display = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST, TFT_MISO);
U8G2_FOR_ADAFRUIT_GFX u8g2_for_adafruit_gfx;

#define TOUCH_CS        15   //HSPI CS

// touch controller init
XPT2046_Touchscreen touch(TOUCH_CS);
TS_Point rawLocation;
The issue I am having is that the TFT and Touch controller are not working together. I initialize the TFT, draw some elements, then initialize Touch, and able to pick up coordinates, but can no longer output to the display:

Code: Select all

void setup() {
  Serial.begin(115200);
  //analogReference(INTERNAL);    //2.56V for micro
  
  //initialize I2C SPL06 Sensor
  Wire.begin();
  SPL_init();

  //initialize the display
  initDisplay();
  drawStaticSensorScreen();     //draw static screen for sensor measurements, including banner
 
  touch.begin();
  touch.setRotation(3);

  u8g2_for_adafruit_gfx.setCursor(100,100);
  u8g2_for_adafruit_gfx.print("TEST");
}
If I don't initialize the touch controller (i.e. touch.begin()), the display works fine.

mikemoy
Posts: 622
Joined: Fri Jan 12, 2018 9:10 pm

Re: Can TFT and Touch be both connected to VSPI?

Postby mikemoy » Thu Dec 22, 2022 6:45 am

Your initializing SPI with Adafruit_ILI9341 with TFT_CS.
Then your doing the same later with XPT2046_Touchscreen touch(TOUCH_CS);
so it overwriting the first SPI instance of the TFT.

trailsurfer604
Posts: 2
Joined: Wed Dec 21, 2022 10:03 pm

Re: Can TFT and Touch be both connected to VSPI?

Postby trailsurfer604 » Fri Dec 23, 2022 6:42 pm

switched to using Bomder's TFT_eSPI library and now everything works fine.

Who is online

Users browsing this forum: No registered users and 84 guests