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.