I have a problem getting the SD card slot in the Adafruit 1.44 Color TFT to work with the Wemos Lolin ESP 32. I have tried many tutorials but am unable to get the Wemos to write a txt file on the SD card. In the current setup, the screen works fine but does not work with the SD card. I have attached the code I used below as well as my pin-to-pin connections.
Pin-to-Pin Connections
Adafruit 1.44 Color TFT -> Wemos Lolin ESP32
Vin -> 3V3
Gnd -> Gnd
SCK -> SCK/18
SO -> MISO/19
SI -> MOSI/23
TCS -> 17
RST -> 16
D/C -> 4
CCS -> SS/5/LED
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <SD.h>
// TFT display and SD card will share the hardware SPI interface.
// Hardware SPI pins are specific to the Arduino board type and
// cannot be remapped to alternate pins. For Arduino Uno,
// Duemilanove, etc., pin 11 = MOSI, pin 12 = MISO, pin 13 = SCK.
#define TFT_CS 17 // Chip select line for TFT display
#define TFT_RST 16 // Reset line for TFT (or see below...)
#define TFT_DC 4 // Data/command line for TFT
#define SD_CS 5 // Chip select line for SD card
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
File logfile;
char filename[] = "test.txt";
void setup(void) {
Serial.begin(9600);
digitalWrite(5, LOW);
// Init tft
tft.initR(INITR_144GREENTAB);
Serial.print("Initializing SD card...");
if (!SD.begin(SD_CS)) {
Serial.println("failed!");
return;
}
Serial.println("OK!");
}
void loop() {
// only open a new file if it doesn't exist
if (!SD.exists(filename)) {
Serial.print("file doesnt exist. Trying to create... ");
logfile = SD.open(filename, FILE_WRITE);
if (!SD.exists(filename)) {
Serial.println("couldnt create file");
return;
}
logfile.println("A");
logfile.println("B");
logfile.close();
Serial.println("file created");
} else Serial.println("file existed");
Serial.print("Logging to: ");
Serial.println(filename);
logfile = SD.open(filename, FILE_WRITE);
if (logfile) {
logfile.println("A");
logfile.println("B");
logfile.close();
} else Serial.println("file still not exists");
logfile = SD.open(filename);
if (logfile) {
Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while (logfile.available()) {
Serial.write(logfile.read());
}
// close the file:
logfile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
delay(2000);
Serial.println("###############################");
}
The thing is that when the code is modified for use with the Arduino Uno, the SD writing capabilities seems to work fine. Please help!