Reference.SDCardNotes History

Hide minor edits - Show changes to output

September 17, 2013, at 11:38 AM by Scott Fitzgerald -
Changed lines 11-12 from:
You’ll need a SD reader and computer to format your card properly. The library supports the FAT16 and FAT32 filesystems, but use FAT16 when possible. The process to format is fairly straightforward.
to:
Most SD cards work right out of the box, but it's possible you have one that was used in a computer or camera and it cannot be read by the SD library. Formatting the card will create a file system that the Arduino can read and write to.

It's not desirable to format SD cards frequently, as it shortens their life span.

You’ll need a SD reader and computer to format your card. The library supports the FAT16 and FAT32 filesystems, but use FAT16 when possible. The process to format is fairly straightforward.
October 31, 2011, at 02:59 PM by Scott Fitzgerald -
Changed lines 26-27 from:
Make sure to close a file before opening a new one. It is only possible to have one file open at a time.
to:
As of version 1.0, it is possible to have multiple files open.
March 18, 2011, at 04:04 PM by Scott Fitzgerald -
Changed lines 47-53 from:
(:include SDLibrarySeeAlsoIncludes :)
to:
* [[SD | SD library]]
* [[SDCardNotes | Notes on using SD cards]]
* [[Tutorial/Datalogger | DataLogger]]
* [[Tutorial/DumpFile | DumpFile]]
* [[Tutorial/Files | Files]]
* [[Tutorial/ReadWrite | ReadWrite]]
* [[Tutorial/CardInfo | CardInfo]]
March 18, 2011, at 04:00 PM by Scott Fitzgerald -
Changed lines 43-47 from:
''NB: the Sparkfun shield was recently updated. Older versions look similar, but were lacking a connection to the 3.3V bus and did not have the onboard hex inverter.''
to:
''NB: the Sparkfun shield was recently updated. Older versions look similar, but were lacking a connection to the 3.3V bus and did not have the onboard hex inverter.''

!!!See Also:

(:include SDLibrarySeeAlsoIncludes :)
March 18, 2011, at 03:58 PM by Scott Fitzgerald -
Added lines 32-33:
%height=300px%[[Attach:arduinoEthernetShieldSD.jpg | Attach:arduinoEthernetShieldSD.jpg]]
Added line 37:
%height=400px%[[Attach:aadafruitSDBoard.jpg | Attach:aadafruitSDBoard.jpg]]
Added line 41:
%height=300px%[[Attach:sparkfunSDShield.jpg | Attach:sparkfunSDShield.jpg]]
March 16, 2011, at 05:03 PM by Scott Fitzgerald -
Changed lines 4-5 from:
The communication between the microcontroller and the SD card uses [[Reference/SPI | SPI]], which takes place on digital pins 11, 12, and 13 (on most Arduino boards) or 50, 51, and 52 (Arduino Mega). Additionally, another pin must be used to select the SD card. This can be the hardware SS pin - pin 10 (on most Arduino boards) or pin 53 (on the Mega) - or another pin specified in the call to SD.begin(). '''Note that even if you don't use the hardware SS pin, it must be left as an output or the SD library won't work. Different boards use different pins for this functionality, so be sure you’ve selected the correct pin in SD.begin(). '''
to:
The communication between the microcontroller and the SD card uses [[Reference/SPI | SPI]], which takes place on digital pins 11, 12, and 13 (on most Arduino boards) or 50, 51, and 52 (Arduino Mega). Additionally, another pin must be used to select the SD card. This can be the hardware SS pin - pin 10 (on most Arduino boards) or pin 53 (on the Mega) - or another pin specified in the call to SD.begin(). '''Note that even if you don't use the hardware SS pin, it must be left as an output or the SD library won't work. Different boards use different pins for this functionality, so be sure you’ve selected the correct pin in SD.begin().'''

Not all the functions are listed on the main SD library page, because they are part of the library's utility functions.
Changed lines 9-10 from:
(NB : whenever we refer to the SD card, we’re talking about SD and microSD sizes, as well as SD and SDHD formats)
to:
(NB : whenever referring to the SD card, it means SD and microSD sizes, as well as SD and SDHD formats)
Added lines 18-19:
'''Linux''': With a SD card inserted, open a terminal window. At the prompt, type @@df@@, and press enter. The windows will report the device name of your SD card, it should look something like /dev/sdb1. Unmount the SD card, but leave it in the computer. Type @@sudo mkdosfs -F 16 /dev/sdb1@@, replacing the device name with yours. Remove the SD card and replace it to verify it works.
Changed lines 21-22 from:
FAT file systems have a limitation when it comes to naming conventions. You must use the 8.3 format, so that file names look like “NAME001.EXT”, where “NAME001” is an 8 character string, and “EXT” is a 3 character extension. People commonly use the extensions .TXT and .LOG. It is possible to have a shorter file name (for example, mydata.txt, or time.log), but you cannot use longer file names. [[http://en.wikipedia.org/wiki/8.3_filename | Read more on the 8.3 convention.]]
to:
FAT file systems have a limitation when it comes to naming conventions. You must use the 8.3 format, so that file names look like “NAME001.EXT”, where “NAME001” is an 8 character or fewer string, and “EXT” is a 3 character extension. People commonly use the extensions .TXT and .LOG. It is possible to have a shorter file name (for example, mydata.txt, or time.log), but you cannot use longer file names. [[http://en.wikipedia.org/wiki/8.3_filename | Read more on the 8.3 convention.]]
Changed lines 26-27 from:
You need to make sure you close a file before opening a new one. It is only possible to have one file open at a time.
to:
Make sure to close a file before opening a new one. It is only possible to have one file open at a time.
March 14, 2011, at 01:50 AM by Scott Fitzgerald -
Added lines 27-29:
'''Arduino Ethernet Shield'''
The Ethernet Shield comes with an SD card slot onboard. The shield fits on top of your Arduino. Because the Ethernet module uses pin 10, the CS pin for the SD card has been moved to pin 4. Make sure you use SD.begin(4) to use the SD card functionality.
Deleted lines 32-34:
'''Arduino Ethernet Shield'''
The Ethernet Shield comes with an SD card slot onboard. The shield fits on top of your Arduino. Because the Ethernet module uses pin 10, the CS pin for the SD card has been moved to pin 4. Make sure you use SD.begin(4) to use the SD card functionality.
March 10, 2011, at 07:11 PM by Scott Fitzgerald -
Changed lines 1-2 from:
!!SD Library
to:
!!Some things to keep in mind when using the SD Library
Deleted lines 3-5:

The SD library allows for reading from and writing to SD cards, e.g. on the Arduino Ethernet Shield. It is built on [[http://code.google.com/p/sdfatlib/ | sdfatlib]] by William Greiman. The library supports FAT16 and FAT32 file systems on standard SD cards and SDHC cards. It only supports one open file at a time and only uses short 8.3 file names. 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. "/filename.txt" is equivalent to "filename.txt").
March 10, 2011, at 07:09 PM by Scott Fitzgerald -
Changed lines 4-7 from:
The SD library allows for reading from and writing to SD cards, e.g. on the Arduino Ethernet Shield. It is built on sdfatlib by William Greiman. The library supports FAT16 and FAT32 file systems on standard SD cards and SDHC cards. It only supports one open file at a time and only uses short 8.3 file names. 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. "/filename.txt" is equivalent to "filename.txt").

The communication between the microcontroller and the SD card uses SPI, which takes place on digital pins 11, 12, and 13 (on most Arduino boards) or 50, 51, and 52 (Arduino Mega). Additionally, another pin must be used to select the SD card. This can be the hardware SS pin - pin 10 (on most Arduino boards) or pin 53 (on the Mega) - or another pin specified in the call to SD.begin(). '''Note that even if you don't use the hardware SS pin, it must be left as an output or the SD library won't work. Different boards use different pins for this functionality, so be sure you’ve selected the correct pin in SD.begin(). '''
to:
The SD library allows for reading from and writing to SD cards, e.g. on the Arduino Ethernet Shield. It is built on [[http://code.google.com/p/sdfatlib/ | sdfatlib]] by William Greiman. The library supports FAT16 and FAT32 file systems on standard SD cards and SDHC cards. It only supports one open file at a time and only uses short 8.3 file names. 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. "/filename.txt" is equivalent to "filename.txt").

The communication between the microcontroller and the SD card uses [[Reference/SPI | SPI]], which takes place on digital pins 11, 12, and 13 (on most Arduino boards) or 50, 51, and 52 (Arduino Mega). Additionally, another pin must be used to select the SD card. This can be the hardware SS pin - pin 10 (on most Arduino boards) or pin 53 (on the Mega) - or another pin specified in the call to SD.begin(). '''Note that even if you don't use the hardware SS pin, it must be left as an output or the SD library won't work. Different boards use different pins for this functionality, so be sure you’ve selected the correct pin in SD.begin(). '''
Changed lines 16-17 from:
''NB: OSX places a number of “hidden” files on the device when it formats a drive. To format a SD car without the extra files on OSX, follow these notes on Ladyada’s site.''
to:
''NB: OSX places a number of “hidden” files on the device when it formats a drive. To format a SD car without the extra files on OSX, [[http://forums.adafruit.com/viewtopic.php?f=31&t=7108%23p34846 | follow these notes]] on Ladyada’s site.''
Changed lines 19-20 from:
FAT file systems have a limitation when it comes to naming conventions. You must use the 8.3 format, so that file names look like “NAME001.EXT”, where “NAME001” is an 8 character string, and “EXT” is a 3 character extension. People commonly use the extensions .TXT and .LOG. If you’re so inclined, read more on the 8.3 convention.
to:
FAT file systems have a limitation when it comes to naming conventions. You must use the 8.3 format, so that file names look like “NAME001.EXT”, where “NAME001” is an 8 character string, and “EXT” is a 3 character extension. People commonly use the extensions .TXT and .LOG. It is possible to have a shorter file name (for example, mydata.txt, or time.log), but you cannot use longer file names. [[http://en.wikipedia.org/wiki/8.3_filename | Read more on the 8.3 convention.]]
Changed lines 22-25 from:
When you use FILE_WRITE, it doesn't write to the card until you flush() or close(). Whenever you open a file, be sure to close it to save your data.

You also need to make sure you close a file before opening a new one. It is only possible to have one file open at a time. (sorry multitaskers!)
to:
When you use file.write(), it doesn't write to the card until you flush() or close(). Whenever you open a file, be sure to close it to save your data.

You need to make sure you close a file before opening a new one. It is only possible to have one file open at a time.
Changed lines 27-28 from:
There are a number of different shields that support SD cards. We will briefly talk about three of them.
to:
There are a number of different shields that support SD cards. This list is not exclusive, but are commonly used.
March 10, 2011, at 07:03 PM by Scott Fitzgerald - First Draft
Added lines 1-37:
!!SD Library
!!!Overview

The SD library allows for reading from and writing to SD cards, e.g. on the Arduino Ethernet Shield. It is built on sdfatlib by William Greiman. The library supports FAT16 and FAT32 file systems on standard SD cards and SDHC cards. It only supports one open file at a time and only uses short 8.3 file names. 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. "/filename.txt" is equivalent to "filename.txt").

The communication between the microcontroller and the SD card uses SPI, which takes place on digital pins 11, 12, and 13 (on most Arduino boards) or 50, 51, and 52 (Arduino Mega). Additionally, another pin must be used to select the SD card. This can be the hardware SS pin - pin 10 (on most Arduino boards) or pin 53 (on the Mega) - or another pin specified in the call to SD.begin(). '''Note that even if you don't use the hardware SS pin, it must be left as an output or the SD library won't work. Different boards use different pins for this functionality, so be sure you’ve selected the correct pin in SD.begin(). '''

!!!Formatting/Preparing the card
(NB : whenever we refer to the SD card, we’re talking about SD and microSD sizes, as well as SD and SDHD formats)

You’ll need a SD reader and computer to format your card properly. The library supports the FAT16 and FAT32 filesystems, but use FAT16 when possible. The process to format is fairly straightforward.

'''Windows''' : right click on your card’s directory and choose “Format” from the drop down. Make sure you choose FAT as the filesystem.

'''OSX''' : Open Disk Utility (located in Applications>Utilities). Choose the Card, click on the erase tab, select MS-DOS(FAT) as the Format, and click Erase.
''NB: OSX places a number of “hidden” files on the device when it formats a drive. To format a SD car without the extra files on OSX, follow these notes on Ladyada’s site.''

!!!File Naming
FAT file systems have a limitation when it comes to naming conventions. You must use the 8.3 format, so that file names look like “NAME001.EXT”, where “NAME001” is an 8 character string, and “EXT” is a 3 character extension. People commonly use the extensions .TXT and .LOG. If you’re so inclined, read more on the 8.3 convention.

!!!Opening/Closing files
When you use FILE_WRITE, it doesn't write to the card until you flush() or close(). Whenever you open a file, be sure to close it to save your data.

You also need to make sure you close a file before opening a new one. It is only possible to have one file open at a time. (sorry multitaskers!)

!!!Different Shields/boards
There are a number of different shields that support SD cards. We will briefly talk about three of them.

'''Adafruit Micro-SD breakout Board'''
This board supports Micro-SD cards, ans you’ll need to wire it up before you can use it. On the board, connect GND to ground, 5v to 5v, CLK to Pin 13 on your Arduino, DO to pin 12, DI to pin 11, and CS to pin 10. If you are already using pin 10, you can use a different pin, as long as you remember to change the pin in SD.begin().

'''Arduino Ethernet Shield'''
The Ethernet Shield comes with an SD card slot onboard. The shield fits on top of your Arduino. Because the Ethernet module uses pin 10, the CS pin for the SD card has been moved to pin 4. Make sure you use SD.begin(4) to use the SD card functionality.

'''Sparkfun SD Shield'''
The Sparkfun shield fits on your Arduino and uses pin 8 for CS. You will need use SD.begin(8) to use the card.
''NB: the Sparkfun shield was recently updated. Older versions look similar, but were lacking a connection to the 3.3V bus and did not have the onboard hex inverter.''

Share