1
1
/*
2
2
SD card test
3
3
4
- This example shows how use the utility libraries on which the'
5
- SD library is based in order to get info about your SD card.
6
- Very useful for testing a card when you're not sure whether its working or not.
4
+ This example shows how use the utility libraries on which the'
5
+ SD library is based in order to get info about your SD card.
6
+ Very useful for testing a card when you're not sure whether its working or not.
7
7
8
- The circuit:
9
- * SD card attached to SPI bus as follows:
8
+ The circuit:
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
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
- created 28 Mar 2011
18
- by Limor Fried
19
- modified 9 Apr 2012
20
- by Tom Igoe
21
- */
17
+ created 28 Mar 2011
18
+ by Limor Fried
19
+ modified 9 Apr 2012
20
+ by Tom Igoe
21
+ */
22
22
// include the SD library:
23
23
#include < SPI.h>
24
24
#include < SD.h>
@@ -58,7 +58,8 @@ void setup() {
58
58
}
59
59
60
60
// print the type of card
61
- Serial.print (" \n Card type: " );
61
+ Serial.println ();
62
+ Serial.print (" Card type: " );
62
63
switch (card.type ()) {
63
64
case SD_CARD_TYPE_SD1:
64
65
Serial.println (" SD1" );
@@ -79,25 +80,30 @@ void setup() {
79
80
return ;
80
81
}
81
82
83
+ Serial.print (" Clusters: " );
84
+ Serial.println (volume.clusterCount ());
85
+ Serial.print (" Blocks x Cluster: " );
86
+ Serial.println (volume.blocksPerCluster ());
87
+
88
+ Serial.print (" Total Blocks: " );
89
+ Serial.println (volume.blocksPerCluster () * volume.clusterCount ());
90
+ Serial.println ();
82
91
83
92
// print the type and size of the first FAT-type volume
84
93
uint32_t volumesize;
85
- Serial.print (" \n Volume type is FAT" );
94
+ Serial.print (" Volume type is: FAT" );
86
95
Serial.println (volume.fatType (), DEC);
87
- Serial.println ();
88
96
89
97
volumesize = volume.blocksPerCluster (); // clusters are collections of blocks
90
98
volumesize *= volume.clusterCount (); // we'll have a lot of clusters
91
- volumesize *= 512 ; // SD card blocks are always 512 bytes
92
- Serial.print (" Volume size (bytes): " );
99
+ volumesize /= 2 ; // SD card blocks are always 512 bytes (2 blocks are 1KB)
100
+ Serial.print (" Volume size (Kb): " );
93
101
Serial.println (volumesize);
94
- Serial.print (" Volume size (Kbytes): " );
102
+ Serial.print (" Volume size (Mb): " );
95
103
volumesize /= 1024 ;
96
104
Serial.println (volumesize);
97
- Serial.print (" Volume size (Mbytes): " );
98
- volumesize /= 1024 ;
99
- Serial.println (volumesize);
100
-
105
+ Serial.print (" Volume size (Gb): " );
106
+ Serial.println ((float )volumesize / 1024.0 );
101
107
102
108
Serial.println (" \n Files found on the card (name, date and size in bytes): " );
103
109
root.openRoot (volume);
@@ -106,7 +112,5 @@ void setup() {
106
112
root.ls (LS_R | LS_DATE | LS_SIZE);
107
113
}
108
114
109
-
110
115
void loop (void ) {
111
-
112
116
}
0 commit comments