Enable Javascript


Last Arduino/ESP8266 project (click to open)

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 

A small library to use a SD Card as NVRAM (non volatile memory):
Use it as stand alone RAW or mixed RAW and files.
SD and SDHC Cards up to 32GB can be used. With standard formatting: <= 2GB FAT (=FAT16), > 2GB and <= 32GB FAT32.
The files sdcard.cpp and sdcard.h are the same as those of my SD SPI filesystem library.

Stand alone RAW:
In the example, i use a 2GB FAT (= FAT16) formatted SD card and started read/write at first data sector 512. The card will remain usable for normal use, your raw data is then overwritten.
* For SD cards > 2GB and/or other formats as Standard FAT16 the first data sector is NOT 512 (see Explanation of the file system to find the first data sector).

Raw and files mixed (files without a filesystem):
Format SD and create as first one file (use my Windows SD Flash tool, see below). For example myData.bin with 64KB of dummy data. Then you have (only on FAT16) reserved 2 cluster that's 128 sectors of 512 bytes. Then you can use sectors 512 to 640 voor raw and the other SD space for other files.
* For SD cards > 2GB and/or other formats as Standard FAT the first data sector is NOT 512 (see Explanation of the file system to find the first data sector on other formats).

See also my SD SPI Filesystem Library. A small Software SPI library based on a stripped-down version of ChaN FatFs.
        File functions: f_mount, f_open, f_close, f_read, f_write, f_lseek, f_sync, f_gets, f_putc, f_puts, f_printf, f_tell, f_eof, f_size, f_error.
        File Open options: FA_READ, FA_WRITE, FA_OPEN_EXISTING, FA_CREATE_NEW, FA_CREATE_ALWAYS

Data logger needed and/or need to read data from SD, and with a file system you running out of memory?
Data Logger: With SD Flash Raw and files mixed, you can create your own small data logger system. Put the position pointer at the beginning of the file. Write the log data on the address of the position pointer and update the position pointer to the next free location in the file.
Data input: With SD Flash Raw and files mixed, on a PC, Tablet, ... write data to the file. After inserting the SD in Arduino use a pushbutton to start reading and processing the data.
Data Logger and Data input: Format SD en write the first (log) file (on Windows: use my SD Flash tool), then create a second file with the data. The start sector of the second file is the last sector of the first file + 1.

Explanation of the file system (the last image):
As an example FAT (=FAT16), but it´s also usable for other formats. Use this explanation to find out where the first data sector on your own SD started.
Also quite useful for this: Active@ Disk Editor - Advanced Disk Editor FREEWARE, (use the themplates to read the correct values).

Downloads:
All my downloads for Arduino can be found on the Download page
My Windows tools (works without installation) SD flash (13KB) and Serial Monitor 8n1 (20Kb) are included in the download.

Explanation of the file system