TFT screen problem

I am using a ILI9342 Touchscreen TFT and the MCUFRIEND_kbv.h library and the examples all work fine. I am trying to adapt a working RC522 RFID I2C sketch which uses the MFRC522_I2C.h library to use the TFT rather than the serial monitor. The TFT uses SPI and the RFID uses I2C so there is no conflict there. The problem I encounter it that the TFT stops displaying and presents a white screen when I include this statement in the sketch:

// Look for new cards, and select one if present
  if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
    delay(50);
    return;
  }

It seems that this statement, which is testing for the presence of a readable card, works fine with the serial monitor but somehow stops the Arduino from communicationg with the TFT.

What exactly is going wrong here and/or is there another way of testing for the presence of a card that the above "if statement"?

For completeness the cutdown sketch is below. If the commented out if statement is included the TFT shows nothing but a white screen. If it is commented out the screen show the message.

#include <Wire.h>
#include "MFRC522_I2C.h"
#include <Adafruit_GFX.h>    // Core graphics library
#include <MCUFRIEND_kbv.h>   // Hardware-specific library

MFRC522 mfrc522(0x28);   // Create MFRC522 instance.
MCUFRIEND_kbv tft;    // Create tft instance.

#include <Fonts/FreeSans12pt7b.h>
#include <Fonts/FreeSerif12pt7b.h>

#include <FreeDefaultFonts.h>

#define BLACK   0x0000
#define RED     0xF800
#define GREEN   0x07E0
#define WHITE   0xFFFF
#define GREY    0x8410

struct CardName {
  const char* cardId;
  const char* userName;
}

registeredCards [] {
  {"214:136:105:109", "One"},
  {"006:159:111:109", "Two"},
  {"059:173:223:018", "Three"},
  {"059:173:223:015", "Four"}
};

const int nCards = sizeof registeredCards / sizeof 0 [registeredCards];

void setup() {
  Serial.begin(9600);
  Wire.begin();                   // Initialize I2C
  mfrc522.PCD_Init();             // Init MFRC522
  Serial.println("Scanning for a card...");
  uint16_t ID = tft.readID();
  Serial.println("Example: Font_simple");
  Serial.print("found ID = 0x");
  Serial.println(ID, HEX);
  if (ID == 0xD3D3) ID = 0x9481; //force ID if write-only display
  tft.begin(ID);
  tft.setRotation(0);
}

void loop() {
  tft.fillScreen(BLACK);
  showmsgXY(10, 80, 1, &FreeSans12pt7b, "Place card over RFID");

  // Look for new cards, and select one if present
 /* if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
    tft.fillScreen(BLACK);
    showmsgXY(10, 80, 1, &FreeSans12pt7b, "Place card over RFID");
    //return;
  }*/
}

void showmsgXY(int x, int y, int sz, const GFXfont *f, const char *msg) {
  int16_t x1, y1;
  uint16_t wid, ht;
  tft.drawFastHLine(0, y, tft.width(), WHITE);
  tft.setFont(f);
  tft.setCursor(x, y);
  tft.setTextColor(GREEN);
  tft.setTextSize(sz);
  tft.print(msg);
  delay(2000);
}

There would be no conflict if they were both i²c or both SPI. Both i²c and SPI are both bus systems designed to connect to multiple devices.

So, is there a potential problem/conflict between a device on an I2C bus and one on an SPI bus?

Clearly, in your case there is a conflict. I read your code but I could not figure out what the conflict could be.

But in general, if one device is i²c and the other is SPI, in theory there should be no conflict.

Which arduino are you using, and which specific display? Some of the display shields use one of the I2C pins (A4 or A5) as the reset line.

Ah, that is possibly the problem. The touchscreen was given to me by an acquaintance and is an Arduino shield, VMA412 from Velleman with a sticker that reads ILI9341 on it. I am using an Arduino Uno.

If I remember correctly, the reset pin is on A4. You can disconnect that and wire it to the RESET pin of the UNO (I think I put a resister inline just to be safe). The only time the library uses the reset is at initialization, so it will not interfere with I2C afterwards, just initialize the display before any I2C devices.

Thank you so much, that seems to solve the issue. I have spent over a week trying to figure out why this didn't work!