SD (File Operations)
The Memory Card library allows for reading from and writing to SD cards. It is built on sdfatlib by William Greiman. The library supports FAT16 and FAT32 file systems on standard SD cards and SDHC cards. It uses short 8.3 names for files. The file names passed to the SD library functions can include paths separated by forward-slashes, /, e.g. "directory/filename.txt". Because the working directory is always the root of the SD card, a name refers to the same file whether or not it includes a leading slash (e.g. "/file.txt" is equivalent to "file.txt").
To use, import as a library and specify
- Initializes the SD library and card.
- cspin (optional): The pin connected to the chip select line of the SD card; defaults to the hardware SS line(22) of the SPI bus.
- True on success; false on failure.
- Tests whether the target file or directory exists on the card.
- filename: The name of the file to test for existence, which can include directories (delimited by forward-slashes, /).
- True if the file or directory exists, false if not.
- Creates a directory on the SD card. This will also create any intermediate directories that don't already exists; e.g. SD.mkdir("a/b/c") will create a, b and c.
- filename: The name of the directory to create, with sub-directories separated by forward-slashes, /.
- True if the creation of the directory succeeded, false if not.
- Opens a file on the SD card. If the file is opened for writing, it will be created if it doesn't already exist (but the directory containing it must already exist).
- filename: The name the file to open, which can include directories (delimited by forward slashes, /) - char *
mode (optional): The mode in which to open the file, defaults to FILE_READ - byte. one of:
-FILE_READ: Open the file for reading, starting at the beginning of the file -FILE_WRITE: To write to the file
- A File object referring to the opened file; if the file couldn't be opened, this object will evaluate to false in a boolean context, i.e. you can test the return value with "if (f)".
- Removes the specified file from the card.
- filename: The name of the file to remove, which can include directories (delimited by forward-slashes, /)
- True if the removal of the file succeeded, false if not. (If the file didn't exist, the return value is unspecified.)
- Removes a directory from the card.
- filename: The name of the directory to remove, with sub-directories separated by forward-slashes, /
- True if the removal of the directory succeeded, false if not. (If the directory didn't exist, the return value is unspecified.)
Please refer to SD (File Operations).