Ill try to make it as simple and short as I can be while still being descriptive.
Some background info that might be helpful is im a complete noob with Arduino im used to using raspberry pis, python and java.
Second im trying to read a txt file on my Arduino but for some reason when I try to print what it sees I get just -1 which I know that means it doesn't see anything as per the documentation.
I made poopy123 as folder just to mess around with for testing so you can ignore that I've been trying to open t.txt
I already tried to do what has been listed in another forum here and I tried to open the txt file inside the folder just to make sure it wasn't an issue with my directory
/*
SD card read/write
This example shows how to read and write data to and from an SD card file
The circuit:
SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)
created Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
File myFile;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
Serial.println("Initializing SD card...");
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("t.txt");
// read from the file until there's nothing else in it:
Serial.print(myFile.read());
while (myFile.available()) {
Serial.print(myFile.read());
}
Serial.println("should be done");
myFile.close();
}
void loop() {
// nothing happens after setup
}
OUTPUT
Initializing SD card...
initialization done.
-1should be done
Initializing SD card...
initialization done.
-1should be done
Contents of t.txt (censored to comply with TOS sorry I was tried while making the file)
When you see such "strange" list of file names:
the files are as FAT32 (long names), but if your FW uses FAT16 (the old 8.3 rule for file names), you might get such "strange" print.
Check, if the SD card is FAT32 and if you use really FAT32 as File System. I guess, when you configure FatFS, there is an option (macro) to specify if "long file names" should be used.
Looks more like a config at your FatFS is wrong or missing.
All file and directory names MUST be DOS 8.3 style. No longer filenames will work. The SD card itself must be 32gb or smaller and must be formatted FAT-32. If you get all these condtions are met and it still doesn't work, let me know.
It is not the formatting of SD Card on a host computer: it is the FatFS as part of your MCU FW system. It looks like: your FW supports only FAT16 (with old DOS 8.3 file names).
I know for sure, that FAT32 is possible and working (I use). But you have to set your FatFS source code to do so.
If it is limited to DOS 8.3 format (FAT16) - then just use 8.3 file names (potentially also format SD card as FAT16).
The "issue" is on your embedded FW side: which format accepted/expected by your FatFS. It is not related to how you format SD card or copy files.
But a PC will assume SD card as FAT32 and copy files with long name - this ends up in these "strange" names (still compatible with FAT16 8.3 file name convention, just the fact that files names look now so strange.