File tree Expand file tree Collapse file tree 2 files changed +28
-29
lines changed
Adafruit_Metro_RP2040/Arduino/Metro_RP2040_SD_Card_Test Expand file tree Collapse file tree 2 files changed +28
-29
lines changed Original file line number Diff line number Diff line change 4
4
/*
5
5
SD card read/write
6
6
7
- This example shows how to read and write data to and from an SD card file
8
- The circuit:
9
- SD card attached to SPI bus as follows:
10
- ** MISO - pin 20
11
- ** MOSI - pin 19
12
- ** CS - pin 23
13
- ** SCK - pin 18
14
-
15
- created Nov 2010
16
- by David A. Mellis
17
- modified 9 Apr 2012
18
- by Tom Igoe
19
-
20
- This example code is in the public domain.
21
-
22
- */
23
-
24
- // SPI0 pins for Metro RP2040
25
- // Pins connected to onboard SD card slot
26
- const int _MISO = 20 ;
27
- const int _MOSI = 19 ;
28
- const int _CS = 23 ;
29
- const int _SCK = 18 ;
7
+ This example shows how to read and write data to and from an SD card file
8
+ The circuit:
9
+ * SD card attached to SPI0 bus as follows:
10
+ ** MOSI - pin 19
11
+ ** MISO - pin 20
12
+ ** CLK - pin 18
13
+
14
+ created Nov 2010
15
+ by David A. Mellis
16
+ modified 9 Apr 2012
17
+ by Tom Igoe
18
+ modified 14 Feb 2023
19
+ by Liz Clark
20
+
21
+ This example code is in the public domain.
22
+
23
+ */
30
24
31
25
#include < SPI.h>
32
26
#include < SD.h>
33
27
28
+ #define SD_FAT_TYPE 3
29
+
30
+ // default CS pin is 23 for Metro RP2040
31
+ #define SD_CS_PIN 23
32
+
34
33
File myFile;
35
34
36
35
void setup () {
37
36
// Open serial communications and wait for port to open:
38
37
Serial.begin (115200 );
38
+ while (!Serial) {
39
+ ; // wait for serial port to connect. Needed for native USB port only
40
+ }
39
41
40
- Serial.print (" Initializing SD card..." );
41
42
42
- // Ensure the SPI pinout the SD card is connected to is configured properly
43
- SPI.setRX (_MISO);
44
- SPI.setTX (_MOSI);
45
- SPI.setSCK (_SCK);
43
+ Serial.print (" Initializing SD card..." );
46
44
47
- if (!SD.begin (_CS )) {
45
+ if (!SD.begin (SD_CS_PIN )) {
48
46
Serial.println (" initialization failed!" );
49
47
return ;
50
48
}
@@ -57,6 +55,7 @@ void setup() {
57
55
// if the file opened okay, write to it:
58
56
if (myFile) {
59
57
Serial.print (" Writing to test.txt..." );
58
+ myFile.println (" testing 1, 2, 3." );
60
59
myFile.println (" hello metro rp2040!" );
61
60
// close the file:
62
61
myFile.close ();
You can’t perform that action at this time.
0 commit comments