Hey, can't open my File. Connection to the SD-Card is there so the wiring should be ok.
I try to open, write and directly close the File. Even tested it, when I created the File from my PC.
MC => ESP32
Code:
#include <SPI.h>
#include <SD.h>
File thisFile;
void SD_Setup(int sd_Connection)
{
if(SD.begin(sd_Connection))
{
Serial.println("Connected to SD");
}
else{
Serial.println("Connection to SD failed");
}
}
bool SD_WriteFile(String file, String data)
{
// Open File for Write
Serial.println("OF 1");
thisFile = SD.open(file,FILE_WRITE);
Serial.println("OF 2");
if(!thisFile) return false; // Return when File not opened
// Write to File
Serial.println("WF 1");
thisFile.print(data);
Serial.println("WF 2");
thisFile.close();
Serial.println("CF");
return true;
}
Calling SD_Setup from the Setup and directly after that SD_WriteFile.
// Setup SD-Card
SD_Setup(SD_CardSelect);
//Testing
SD_WriteFile("Data.txt", "TestData");
Serial.println("Started LUX, now prepare RUN");
This is the circuit:
EDIT: The Code returns out at the if(!thisFile) check