SD Library - Hirokuzu/EECE281_project2 GitHub Wiki

Uses SPI data to read or write files to an SD card connected to an Arduino. In addition to the pins required for SPI (13,12,11,10) it also requires one more pin to select the SD card from within the code (so it requires 5 pins including the ones for SPI).

A note on the microSD cards you use:

  • It appears the it only uses regular SD cards and doesn't support HC, or XC variations which makes finding cards at this point in time difficult.
  • The cards must be formatted in FAT and the best case is FAT 16, however FAT 32 is also acceptable. Because of the formatting the names of the files can be 8 characters long, followed by a . and 3 letter extension
  • Files aren't actually written/saved until you call flush() or close()

Flow of your program is as follows:

SD.begin(Pin Number for SD)

File variableName = SD.open("NameOfFile", FILE_WRITE) //FILE_READ is used to read from the file

variableName.println("StirngsToPrintToFile")

if you variableName.flush() here it wont actually close the file, but will actually save the file with the new string in it

variableName.close() //will close your file when you're done with it and save the changes

If you need to read you would usually print to serial, otherwise the command is variableName.read() and will read the file until there isn't anything left

If you need to create a file you can just use the SD.open() command. To remove a file use SD.remove("fileName").