nRF24L01 and TFT ili9341 not playing nice SPI ?

Hi every one
I am working on a weather station
Setup Elegoo Mega 2560,Nano, nRF24L01 x2, TFT ili9341, RTC DS3231, DHT 22/AM2302 x2 cap’s, 3.3 power and resistors (touch and sd slot not connected) and all works together. Arduino graphics test, ArduinoILI9341Touch, TFT ILI9341_RTC_time and temp. and nrf24 “hello world” just change sketch, tells me the wiring is good But the when I run my sketch (built from all you coders thank you) the serial printer, prints inside, outside, time, date. prints fine and dose not stop all day long time and temp. change so the sketch doesn’t stop. I did get the TFT to print the temp “0.0” so I think it would work. But the TFT stops after nRF24L01. I have tried it all maybe.
All Amazon parts
Elegoo MEGA 2560 R3 Board ATmega2560 ATMEGA16U2
[CANADUINO® DS3231 RTC Module, 32kB Memory, I2C Interface, Battery Backup]
[Hosyond 3.2 Inches TFT LCD Touch Screen Shield Display Module ]
Funsto DHT22/AM2302 Digital Temperature and Humidity Sensor
[DHT22/AM2302 Digital Temperature and Humidity Sensor Module Tem]
10Gtek NRF24L01 2.4GHz Antenna Wireless transceiver Module
@Robin2 is a lot of help thanks

Please help
Thank you
barr1910

#include <RF24.h>
#include <RF24_config.h>
#include <nRF24L01.h>
#include <printf.h>
#include <Sodaq_DS3231.h>
#include <DHT.h>
//#include <DHT_U.h>
#include <Wire.h>
#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

#define TFT_RST 49
#define TFT_CLK 52
#define TFT_MISO 50
#define TFT_MOSI 51
#define TFT_DC 46
#define TFT_CS 53
#define ILI9341_WIDTH 380   // Example: Setting width to 320
#define ILI9341_HEIGHT 240  // Example: Setting height to 240
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

#define DHTPIN 6
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

RF24 myRadio(9, 10);
byte addresses[][6] = { "0" };
float remoteHumidity = 0.0;
float remoteTemperature = 0.0;

String dateString;
String hours;
int minuteNow = 0;
int minutePrevious = 0;

struct package {
  float temperature;
  float humidity;
};

float previousIndoorHumidity = 0;
float previousIndoorTemperature = 10;

float previousRemoteHumidity = 0.1;
float previousRemoteTemperature = 0.1;

float indoorHumidity = 0;
float indoorTemperature = 0;

typedef struct package Package;
Package data;

char weekDay[][4] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };

//year, month, date, hour, min, sec and week-day(starts from 0 and goes to 6)
//writing any non-existent time-data may interfere with normal operation of the RTC.
//Take care of week-day also.
DateTime dt(2025, 04, 27, 8, 36, 0, 0);

void setup() {

  Serial.begin(9600);
  tft.begin();  // Initialize ILI9341 display
  dht.begin();
  rtc.begin();
  Wire.begin();
  // rtc.setDateTime(dt); //Adjust date-time as defined 'dt' above
  //non changing tft graphics
  tft.setRotation(1);             // Set screen rotation (e.g., landscape)
  tft.fillScreen(ILI9341_BLACK);  // Clear screen
  tft.setCursor(139, 158);
  tft.drawRoundRect(3, 3, 315, 71, 5, ILI9341_WHITE);
  tft.drawRoundRect(4, 5, 313, 68, 5, ILI9341_RED);

  tft.drawRoundRect(5, 85, 159, 150, 5, ILI9341_GREEN);
  tft.drawRoundRect(6, 86, 158, 148, 5, ILI9341_GREEN);

  tft.drawRoundRect(166, 85, 150, 150, 5, ILI9341_PURPLE);
  tft.drawRoundRect(167, 86, 148, 148, 5, ILI9341_PURPLE);

  tft.fillRect(10, 90, 150, 40, ILI9341_GREEN);
  tft.fillRect(171, 90, 130, 40, ILI9341_CYAN);

  tft.setCursor(13, 100);
  tft.setTextColor(ILI9341_BLACK);
  tft.setTextSize(3);
  tft.print("Indoor");

  tft.setCursor(173, 100);
  tft.setTextColor(ILI9341_BLACK);
  tft.setTextSize(3);
  tft.print("Outdoor");

  tft.setCursor(139, 158);
  tft.setTextColor(ILI9341_GREEN);
  tft.setTextSize(2);
  tft.print("%");

  tft.setCursor(289, 158);
  tft.setTextColor(ILI9341_CYAN);
  tft.setTextSize(2);
  tft.print("%");

  tft.setCursor(139, 140);
  tft.setTextColor(ILI9341_GREEN);
  tft.setTextSize(2);
  tft.print("F");

  tft.setCursor(139, 175);
  tft.setTextColor(ILI9341_GREEN);
  tft.setTextSize(2);
  tft.print("o");

  tft.setCursor(289, 140);
  tft.setTextColor(ILI9341_CYAN);
  tft.setTextSize(2);
  tft.print("F");

  tft.setCursor(289, 175);
  tft.setTextColor(ILI9341_CYAN);
  tft.setTextSize(2);
  tft.print("o");
  delay(100);
}

uint32_t old_ts;
void loop() {

  {
    myRadio.begin();
    myRadio.setChannel(115);
    myRadio.setPALevel(RF24_PA_MAX);
    myRadio.setDataRate(RF24_250KBPS);
    myRadio.openReadingPipe(1, addresses[0]);
    myRadio.startListening();
    delay(100);
  }
  if (myRadio.available())
    ;
  {
    while (myRadio.available()) {
      myRadio.read(&data, sizeof(data));
      previousRemoteTemperature = remoteTemperature;
      previousRemoteHumidity = remoteHumidity;
      remoteTemperature = data.temperature;
      remoteHumidity = data.humidity;
    }
    tft.fillRect(90, 10, 40, 150, ILI9341_GREEN);  //test TFT

/*
    {
      Serial.print("\nPackage:");
      Serial.print("\n");
      Serial.println(data.temperature);
      Serial.println(data.humidity);
}
*/
    Serial.print("outside Humidity: ");
    Serial.print(data.humidity);
    Serial.print(" %\t");
    Serial.print("outside Temperature: ");
    Serial.print(data.temperature);
    Serial.println(" *C");

    float indoorHumidity = dht.readHumidity();
    float indoorTemperature = dht.readTemperature();

    Serial.print("Indoor Humidity: ");
    Serial.print(indoorHumidity);
    Serial.print(" %\t");
    Serial.print("Indoor Temperature: ");
    Serial.print(indoorTemperature);
    Serial.println(" *C");

    DateTime now = rtc.now();  //get the current date-time
    uint32_t ts = now.getEpoch();

    if (old_ts == 0 || old_ts != ts) {
      old_ts = ts;

      Serial.print(now.year(), DEC);
      Serial.print('/');
      Serial.print(now.month(), DEC);
      Serial.print('/');
      Serial.print(now.date(), DEC);
      Serial.print(' ');
      Serial.print(now.hour(), DEC);
      Serial.print(':');
      Serial.print(now.minute(), DEC);
      Serial.print(':');
      Serial.print(now.second(), DEC);
      Serial.print(' ');
      Serial.print(weekDay[now.dayOfWeek()]);
      Serial.println();
      // Serial.print("Seconds since Unix Epoch: ");
      //Serial.print(ts, DEC);
      Serial.println();
      Serial.println();
      delay(3000);                                    // Wait a few seconds between readings
      tft.fillRect(90, 100, 75, 150, ILI9341_GREEN);  //test TFT
    }
  }
}

It's possible that 5V to 3.3V level shifters on the display are causing a problem with the SPI bus. We would need to see a schematic of the display's internal circuit to confirm.

Also possible that some error in your circuit is causing a problem. Post a schematic. Hand drawn is fine.

Why x2?

Which is it? Either everything works together, or it doesn't.

Links to actual hardware used?

Annotated schematic?

Clear, well lit, in focus pictures of actual wiring?

Post an annotated schematic showing exactly how you have wired this. Be sure to include all power sources, connections, power, ground etc on the drawing. I do not read frizzies. Posting a clear picture of your complete assembly may help.

Hi Every one
Thank you for your posts
I changed my sketch to better show what I have done so far.
I was having a dha moment nrf24’s don’t work by them selfs.
This site is for TFT

This is the Schematics
http://www.lcdwiki.com/res/MSP3218/MSP3218-3.2-SPI.pdf
when I say it all works together is all components are connected like it would be when up and running.
The 4 test sketch’s work just upload the one you like. (for testing touch not connected for now just add the jumper wires and it works and sd slot has never been connected) on tft I used 10k resistors on all pins, but not on vcc, gnd, led and T-DO pins. RTC is on pins 20, 21, nrf24 and tft share 50, 51 and 52.
The rest off the pins are as shown in sketch. The set up works comment the nrf24 and tft works, date time, indoor temp/humidity no outside temp/humidity. un comment the nrf24 tft quits every thing before nrf24 prints to tft. I put the nrf24 at the end or loop and it print every thing prints one time, date, time indoor temp/humidity but not outside temp/humidity. I can get it to print 0.10 on the tft if I change line 222 from data.humidity to previousRemoteHumidity from line240 and nrf24 at the end of loop.
The serial monitor tells us that either way the loop dose not stop. I can see the outside temp/humidity (comment the nrf24 no data.) so the data is coming form outside.

Thank you for
your time
Barr1910

#include <RF24.h>
#include <RF24_config.h>
#include <nRF24L01.h>
#include <printf.h>
#include <Sodaq_DS3231.h>
#include <DHT.h>
//#include <DHT_U.h>
#include <Wire.h>
#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

#define TFT_RST 49
#define TFT_CLK 52
#define TFT_MISO 50
#define TFT_MOSI 51
#define TFT_DC 46
#define TFT_CS 53
#define ILI9341_WIDTH 380   // Example: Setting width to 320
#define ILI9341_HEIGHT 240  // Example: Setting height to 240
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

#define DHTPIN 6
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

RF24 myRadio(9, 10);
byte addresses[][6] = { "0" };
float remoteHumidity = 0.0;
float remoteTemperature = 0.0;

String dateString;
String hours;
int minuteNow = 0;
int minutePrevious = 0;

struct package {
  float temperature;
  float humidity;
};

float previousIndoorHumidity = 0;
float previousIndoorTemperature = 10;

float previousRemoteHumidity = 0.1;
float previousRemoteTemperature = 0.1;

float indoorHumidity = 0;
float indoorTemperature = 0;

typedef struct package Package;
Package data;

char weekDay[][4] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };

//year, month, date, hour, min, sec and week-day(starts from 0 and goes to 6)
//writing any non-existent time-data may interfere with normal operation of the RTC.
//Take care of week-day also.
DateTime dt(2025, 04, 27, 8, 36, 0, 0);

void setup() {

  Serial.begin(9600);
  tft.begin();  // Initialize ILI9341 display
  dht.begin();
  rtc.begin();
  Wire.begin();
  // rtc.setDateTime(dt); //Adjust date-time as defined 'dt' above
  //non changing tft graphics
  tft.setRotation(1);             // Set screen rotation (e.g., landscape)
  tft.fillScreen(ILI9341_BLACK);  // Clear screen
  tft.setCursor(139, 158);
  tft.drawRoundRect(3, 3, 315, 71, 5, ILI9341_WHITE);
  tft.drawRoundRect(4, 5, 313, 68, 5, ILI9341_RED);

  tft.drawRoundRect(5, 85, 159, 150, 5, ILI9341_GREEN);
  tft.drawRoundRect(6, 86, 158, 148, 5, ILI9341_GREEN);

  tft.drawRoundRect(166, 85, 150, 150, 5, ILI9341_PURPLE);
  tft.drawRoundRect(167, 86, 148, 148, 5, ILI9341_PURPLE);

  tft.fillRect(10, 90, 150, 40, ILI9341_GREEN);
  tft.fillRect(171, 90, 130, 40, ILI9341_CYAN);

  tft.setCursor(13, 100);
  tft.setTextColor(ILI9341_BLACK);
  tft.setTextSize(3);
  tft.print("Indoor");

  tft.setCursor(173, 100);
  tft.setTextColor(ILI9341_BLACK);
  tft.setTextSize(3);
  tft.print("Outdoor");


  tft.setCursor(110, 145);
  tft.setTextColor(ILI9341_GREEN);
  tft.setTextSize(2);
  tft.print("C");

  tft.setCursor(110, 180);
  tft.setTextColor(ILI9341_GREEN);
  tft.setTextSize(2);
  tft.print("H");

  tft.setCursor(125, 180);
  tft.setTextColor(ILI9341_GREEN);
  tft.setTextSize(2);
  tft.print("%");

  tft.setCursor(260, 145);
  tft.setTextColor(ILI9341_CYAN);
  tft.setTextSize(2);
  tft.print("C");

  tft.setCursor(260, 180);
  tft.setTextColor(ILI9341_CYAN);
  tft.setTextSize(2);
  tft.print("H");

  tft.setCursor(280, 180);
  tft.setTextColor(ILI9341_CYAN);
  tft.setTextSize(2);
  tft.print("%");

  delay(100);
}

uint32_t old_ts;
void loop() {


  //tft.fillRect(90, 10, 40, 150, ILI9341_GREEN);  //test TFT

  /*
    {
      Serial.print("\nPackage:");
      Serial.print("\n");
      Serial.println(data.temperature);
      Serial.println(data.humidity);
}
*/
  Serial.print("outside Humidity: ");
  Serial.print(data.humidity);
  Serial.print(" %\t");
  Serial.print("outside Temperature: ");
  Serial.print(data.temperature);
  Serial.println(" *C");

  float indoorHumidity = dht.readHumidity();
  float indoorTemperature = dht.readTemperature();

  Serial.print("Indoor Humidity: ");
  Serial.print(indoorHumidity);
  Serial.print(" %\t");
  Serial.print("Indoor Temperature: ");
  Serial.print(indoorTemperature);
  Serial.println(" *C");

  DateTime now = rtc.now();  //get the current date-time
  uint32_t ts = now.getEpoch();

  if (old_ts == 0 || old_ts != ts) {
    old_ts = ts;

    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.date(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.print(' ');
    Serial.print(weekDay[now.dayOfWeek()]);
    Serial.println();
    // Serial.print("Seconds since Unix Epoch: ");
    //Serial.print(ts, DEC);
    Serial.println();
    Serial.println();
    delay(3000);  // Wait a few seconds between readings
   
    tft.fillRect(5, 6, 311, 66, ILI9341_BLACK);
    tft.setCursor(7, 8);
    tft.setTextColor(ILI9341_WHITE);
    tft.setTextSize(3);
    tft.print(weekDay[now.dayOfWeek()]);
    tft.print(",");
    tft.print(now.date(), DEC);
    tft.print(' ');
    tft.print(now.month(), DEC);
    tft.setCursor(8, 35);
    tft.print(now.hour(), DEC);
    tft.print(":");
    tft.print(now.minute(), DEC);
    tft.print(":");
    tft.print(now.second(), DEC);

    tft.fillRect(10, 130, 90, 75, ILI9341_BLACK);
    tft.setCursor(11, 140);
    tft.setTextColor(ILI9341_YELLOW);
    tft.setTextSize(3);
    tft.print(indoorTemperature);

    tft.setCursor(11, 175);
    tft.setTextColor(ILI9341_CYAN);
    tft.setTextSize(3);
    tft.print(indoorHumidity);

    tft.fillRect(168, 130, 90, 75, ILI9341_BLACK);
    tft.setCursor(170, 140);
    tft.setTextColor(ILI9341_YELLOW);
    tft.setTextSize(3);
    tft.print(data.temperature);

    tft.setCursor(170, 175);
    tft.setTextColor(ILI9341_CYAN);
    tft.setTextSize(3);
    tft.print(data.humidity);
    
    {
      myRadio.begin();
      myRadio.setChannel(115);
      myRadio.setPALevel(RF24_PA_MAX);
      myRadio.setDataRate(RF24_250KBPS);
      myRadio.openReadingPipe(1, addresses[0]);
      myRadio.startListening();
      delay(100);
    }
   
    if (myRadio.available())
      ;
    {
      while (myRadio.available()) {
        myRadio.read(&data, sizeof(data));
        previousRemoteTemperature = remoteTemperature;
        previousRemoteHumidity = remoteHumidity;
        remoteTemperature = data.temperature;
        remoteHumidity = data.humidity;
      }
    
    }}}
  

Sorry forgot the pic's



Thanks for your patience
Barr1910

One way to diagnose your problem and possibly find an alternative way to drive both SPI devices would be to use Software Driven SPI, via the GitHub - greiman/DigitalIO: Fast Digital I/O, Software I2C, and Software SPI for AVR Arduino library

I would recommend downloading the above library via the Arduino IDE library manager, and then per the below instructions, edit RF24_config.h in the RF24 library, and

  1. Uncomment #define SOFTSPI
  2. Scroll down and find where it says #define SOFT_SPI_MISO_PIN 9 etc and define your pins to any suitable digital pins to drive the nRF24 radio.
    See:
    Optimized high speed nRF24L01+ driver class documentation: Arduino

Then re-wire your RF24 radio to use the pins chosen in RF24_config.h.

This will at least tell you if you have a working setup and/or indicate if there is an SPI issue between nRF24 and the TFT display.

Hi Every one
I thank you
The tft and nrf24 are working now but I have “ovf,nan 0,00 on the out side temp and humidity which I never had before. Would it be the spi or some thing in my code?

Thank you Every one
Thank you @TMRh20
barr1910

Hard to say whats causing the temp/humidity issues. It could be wiring, could be code.