TFT LCD Software SPI with SD Card Hardware SPI

Hi all. I'm a bit new to this world but loving it! This is a bit convoluted so props if you hang in there through this explanation.

I purchased a 9" TFT LCD from buydisplays which has a shield for the Mega (I am using a Mega) with an SD card reader and takes a separate 5V power supply.
Turns out you cannot use the touchscreen and the SD card at the same time even though they initially make it seem that way but confirmed through support that's not the case without modification. The link below has a bunch of diagrams.

I found these most helpful (note JP1 & JP2 are references backwards):

The LCD also has it's own sd card reader on board that isn't connected to anything but does get 3.3V when the screen is powered.

I dug through the pinouts of the shield and found that the hardware SPI ports aren't actually used, the screen is using software SPI

Soooo I broke off those pins and wired in to 50, 51, 52, 53 (initially 53, I tried switching to 7 just in case) and was able to get that card reader working (yay)

But now it seems the touchscreen isn't working. I tried using pin 53 as the cs pin but I know the mega can be temperamental about it since it's the ss pin so I tried swapping to another open pin but same outcome.

I have pin 53 set as output just in case. The issue arises when I call "SD.begin()". I have tried setting the cs pin HIGH after that call but no luck.

If it helps diagnose I have noticed that if I remove SD.begin() and push the sketch the touch still doesn't work until I power everything off and back on.

I thought with the LCD and TFT running as software SPIs that the hardware SPI would function without issue but maybe that's not the case?

I've attached what I believe to be the relevant code. Am I trying to do something impossible?

#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <UTFT.h>
#include <UTouch.h>

//chip select pin
#define SD_CS 7

//force landscape
#define TOUCH_ORIENTATION LANDSCAPE  //PORTRAIT

//LCD pins through shield - Software SPI
UTFT myGLCD(SSD1963_800480, 38, 39, 40, 41);  //(byte model, int RS, int WR, int CS, int RST, int SER)

//touchscreen - Software SPI
UTouch myTouch(43, 42, 44, 45, 46);  //byte tclk, byte tcs, byte din, byte dout, byte irq

// Declare which fonts we will be using
extern uint8_t BigFont[];

int x, y;
int dispx, dispy, text_y_center;
char stCurrent[20] = "";
int stCurrentLen = 0;
char stLast[20] = "";

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);

  // Setup the LCD
  myGLCD.InitLCD();
  myGLCD.clrScr();
  // -------------------------------------------------------------
  pinMode(8, OUTPUT);     //backlight
  digitalWrite(8, HIGH);  //on
                          // -

  //set ss as output
  pinMode(53, OUTPUT);

  myTouch.InitTouch(TOUCH_ORIENTATION);
  myTouch.setPrecision(PREC_MEDIUM);

  dispx = myGLCD.getDisplayXSize();
  dispy = myGLCD.getDisplayYSize();
  text_y_center = (dispy / 2) - 6;

  myGLCD.setFont(BigFont);
  myGLCD.setBackColor(0, 0, 255);

  SD.begin(SD_CS);
  digitalWrite(7, HIGH);

  //bmpDraw("BMP_1.bmp", 0, 0); //remove for now while troubleshooting

  drawButtons();
}

Hey @crippyd you can look into the article i wrote that exactly explained this case. Let me know if it worked for you!

Article: [SOLUTION] BuyDisplay 7" use touchscreen & SD card at the same time

Regards
Dario

Hi @DarioCas! I actually had already read your post and tried it but we didn't have the best tools on hand and couldn't quite get the jumpers & wires right like you did (so small!) That's why I opted to go after the SD card that's on the TFT rather than the one that's on the shield. Since it's not the SD reader from the shield and the shield is using software SPI I figured hardware spi would be useable but you're probably right, the shield is probably somehow still keeping this from working but I don't understand how.

SIGH. NEVERMIND. It was right the whole time. I finally questioned my fiance's soldering skills and went back through the shield he had messed with and one of the hardware jumpers was still closed when he thought he had made it open again (we messed with this trying the wiring DarioCas had suggested in an earlier post) so after scraping that off everything works as expected. facepalm

1 Like

Very Nice, glad it worked!

Regards
DarioCas

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