Debian Codegraph @

app/testdata/libraries/SD_1.2.1/SD/examples/DumpFile/DumpFile.ino

raw
1 /*
2 SD card file dump
3
4 This example shows how to read a file from the SD card using the
5 SD library and send it over the serial port.
6
7 The circuit:
8 * SD card attached to SPI bus as follows:
9 ** MOSI - pin 11
10 ** MISO - pin 12
11 ** CLK - pin 13
12 ** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)
13
14 created 22 December 2010
15 by Limor Fried
16 modified 9 Apr 2012
17 by Tom Igoe
18
19 This example code is in the public domain.
20
21 */
22
23 #include <SPI.h>
24 #include <SD.h>
25
26 const int chipSelect = 4;
27
28 void setup() {
29 // Open serial communications and wait for port to open:
30 Serial.begin(9600);
31 while (!Serial) {
32 ; // wait for serial port to connect. Needed for native USB port only
33 }
34
35
36 Serial.print("Initializing SD card...");
37
38 // see if the card is present and can be initialized:
39 if (!SD.begin(chipSelect)) {
40 Serial.println("Card failed, or not present");
41 // don't do anything more:
42 while (1);
43 }
44 Serial.println("card initialized.");
45
46 // open the file. note that only one file can be open at a time,
47 // so you have to close this one before opening another.
48 File dataFile = SD.open("datalog.txt");
49
50 // if the file is available, write to it:
51 if (dataFile) {
52 while (dataFile.available()) {
53 Serial.write(dataFile.read());
54 }
55 dataFile.close();
56 }
57 // if the file isn't open, pop up an error:
58 else {
59 Serial.println("error opening datalog.txt");
60 }
61 }
62
63 void loop() {
64 }
65