Hi all,
Been playing with a couple different libraries for working with SD cards, specifically William Greiman's Fat16lib and the 'SD' that comes with Arduino IDE as of 0022. Writing to SD cards is just plain useful, but my specific aim is to find / specify a lib that works well for a low-power Arduino variant I'm working on. ("Low power friendly" = less CPU cycles per bytes read/written, ability to reinitialize the card after cutting its power.)
'SD' scores usability points for being included right in the official Arduino distribution and examples. Unfortunately, it loses them (and then some) for having pin numbers hardcoded in the library(!)(a series of #ifdefs guesses the board you are using based on the CPU), meaning a user has to basically hack the library to use it with with something other than a commercially produced SD shield / well-known board. It gains some back for supporting FAT32 and SDHC cards, which to my knowledge fat16lib doesn't support.
Another ding for 'SD' is that I could only get it to initialize the card once. Subsequent begin() calls (e.g. after the card's power has been cut for a bit) fail. I haven't done enough digging yet to find why this is or how easy it would be to fix. Some of the cards I tested consumed as much as 20mA when idle, so it is important
The real eye-popper was benchmarking them side by side on the same card (SanDisk branded 1GB microSD, FAT16 format). Replicating fat16lib's read/write benchmark as best as possible on SD, the following results are obtained on my board. Note that the test board runs at only 4MHz, so this should not be taken as an authoritative Arduino+SD benchmark of any kind. Both are using hardware SPI.
FAT16lib on SanDisk 1G uSD:
Free RAM: 3062
File size 1 MB
Starting write test. Please wait up to three minutes
Write 67.20 KB/sec
Starting read test. Please wait up to a minute
Read 86.57 KB/sec
Done
Arduino SD lib on SanDisk 1G uSD:
Initializing SD card...
initialization done.
Writing to test.txt, press a key to start...
File size
1
MB
Starting write test. Please wait up to three minutes
Write
3.36
KB/sec
Starting read test. Please wait up to a minute
Read
7.27
KB/sec
Done
Are these results consistent with expectations? That's a pretty big difference, and I have to say fat16lib's scores are impressive, almost enough to make me nervous (i.e. look for bugs). A slower read speed from 'SD' is forgivable considering it does not support reading entire buffers, only single bytes at a time, so the read test is not a 100% apples-to-apples comparison.
Besides all of what's above, are there any other reasons (bugs, etc.) to choose one over the other? Are there any of the less well-known SD libraries I should have a look at too?
fat16bench.pde (2.08 KB)
new_SD_bench.pde (3.08 KB)