1
1
/*
2
- SD card test
3
-
2
+ SD card test
3
+
4
4
This example shows how use the utility libraries on which the'
5
5
SD library is based in order to get info about your SD card.
6
6
Very useful for testing a card when you're not sure whether its working or not.
7
-
7
+
8
8
The circuit:
9
9
* SD card attached to SPI bus as follows:
10
10
** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
11
11
** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
12
12
** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
13
- ** CS - depends on your SD card shield or module.
13
+ ** CS - depends on your SD card shield or module.
14
14
Pin 4 used here for consistency with other Arduino examples
15
15
16
-
16
+
17
17
created 28 Mar 2011
18
- by Limor Fried
18
+ by Limor Fried
19
19
modified 9 Apr 2012
20
20
by Tom Igoe
21
21
*/
22
- // include the SD library:
22
+ // include the SD library:
23
+ #include < SPI.h>
23
24
#include < SD.h>
24
25
25
26
// set up variables using the SD utility library functions:
@@ -31,22 +32,22 @@ SdFile root;
31
32
// Arduino Ethernet shield: pin 4
32
33
// Adafruit SD shields and modules: pin 10
33
34
// Sparkfun SD shield: pin 8
34
- const int chipSelect = 4 ;
35
+ const int chipSelect = 4 ;
35
36
36
37
void setup ()
37
38
{
38
- // Open serial communications and wait for port to open:
39
+ // Open serial communications and wait for port to open:
39
40
Serial.begin (9600 );
40
- while (!Serial) {
41
+ while (!Serial) {
41
42
; // wait for serial port to connect. Needed for Leonardo only
42
43
}
43
44
44
45
45
46
Serial.print (" \n Initializing SD card..." );
46
47
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
47
- // Note that even if it's not used as the CS pin, the hardware SS pin
48
- // (10 on most Arduino boards, 53 on the Mega) must be left as an output
49
- // or the SD library functions will not work.
48
+ // Note that even if it's not used as the CS pin, the hardware SS pin
49
+ // (10 on most Arduino boards, 53 on the Mega) must be left as an output
50
+ // or the SD library functions will not work.
50
51
pinMode (10 , OUTPUT); // change this to 53 on a mega
51
52
52
53
@@ -59,12 +60,12 @@ void setup()
59
60
Serial.println (" * did you change the chipSelect pin to match your shield or module?" );
60
61
return ;
61
62
} else {
62
- Serial.println (" Wiring is correct and a card is present." );
63
+ Serial.println (" Wiring is correct and a card is present." );
63
64
}
64
65
65
66
// print the type of card
66
67
Serial.print (" \n Card type: " );
67
- switch (card.type ()) {
68
+ switch (card.type ()) {
68
69
case SD_CARD_TYPE_SD1:
69
70
Serial.println (" SD1" );
70
71
break ;
@@ -90,7 +91,7 @@ void setup()
90
91
Serial.print (" \n Volume type is FAT" );
91
92
Serial.println (volume.fatType (), DEC);
92
93
Serial.println ();
93
-
94
+
94
95
volumesize = volume.blocksPerCluster (); // clusters are collections of blocks
95
96
volumesize *= volume.clusterCount (); // we'll have a lot of clusters
96
97
volumesize *= 512 ; // SD card blocks are always 512 bytes
@@ -103,15 +104,15 @@ void setup()
103
104
volumesize /= 1024 ;
104
105
Serial.println (volumesize);
105
106
106
-
107
+
107
108
Serial.println (" \n Files found on the card (name, date and size in bytes): " );
108
109
root.openRoot (volume);
109
-
110
+
110
111
// list all files in the card with date and size
111
112
root.ls (LS_R | LS_DATE | LS_SIZE);
112
113
}
113
114
114
115
115
116
void loop (void ) {
116
-
117
+
117
118
}
0 commit comments