Problem with writing to SD card and to screen in the same code

Hi!

We want to both write to the SD card and write to screen in the same code, but it seems like it can only do one of them. If the SD-part is placed first in the loop, it writes only to the SD card and not to the screen but if the screen-part is placed first it only writes to the screen and not to the SD card.

We use:
Arduino Uno
Screen: 2.8 tft spi 240x320 v1.2
SD card shield: V4, 103030005

This is our code:

#include <Adafruit_ILI9341.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <gfxfont.h>
#include <SPI.h>
#include <SD.h>

#define TFT_DC 9              
#define TFT_CS 10             
#define TFT_RST 8             
#define TFT_MISO 5           
#define TFT_MOSI 3           
#define TFT_CLK 13    

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
File myFile;

void setup() {
  
tft.begin();                      
tft.setRotation(0);            
tft.fillScreen(ILI9341_BLACK);
SD.begin();}

void loop() {

tft.fillRect(tft.width()/2,100,90,90,ILI9341_BLACK);
tft.setCursor(tft.width()/2,100);
tft.setTextSize(2);
tft.setTextColor(ILI9341_WHITE);
tft.print("hello");

myFile= SD.open("TEST.txt", FILE_WRITE);
myFile.println("hello");
myFile.close();}

Would really appreciate some help! We have worked on this for weeks and are out of ideas. We have tried a nano, separate SD card shield, different ground resistors, several changes in the code/libraries and so on.

the default SPI speed in tft library is 8000000 and in SD library 4000000.
in both begin() function you can add speed parameter

Adafruit_ILI9341
void begin(uint32_t freq)

SD
boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN, uint32_t speed = SPI_HALF_SPEED);

Thanks for answering my post! I tried changing the TFT speed to the SD speed (4000000) but it still didn't work. Any other suggestions?