Arduino Micro SD卡模块使用指南-Arduino中文社区 - Powered by Discuz! Archiver

王大富 发表于 2021-2-15 10:15

Arduino Micro SD卡模块使用指南






/*
* MOSI - pin 11

** MISO - pin 12

** CLK - pin 13

** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)

*/

#include <SPI.h>
#include <SD.h>
File myFile;
void setup() {
Serial.begin(9600);
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
}
Serial.println("initialization done.");
myFile = SD.open("test.txt", FILE_WRITE); // open the file. note that only one file can be open at a time, so you have to close this one before opening another.
if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3."); // if the file opened okay, write to it:
    myFile.close(); // close the file:
    Serial.println("done.");
} else {
    Serial.println("error opening test.txt"); // if the file didn't open, print an error:
}
myFile = SD.open("test.txt"); // re-open the file for reading:
if (myFile) {
    Serial.println("test.txt:");
    while (myFile.available()) {
      Serial.write(myFile.read()); // read from the file until there's nothing else in it:
    }
    myFile.close();
} else {
    Serial.println("error opening test.txt");
}
}

void loop() {
// nothing happens after setup
}

Creeper666 发表于 2021-2-16 11:20

合着LZ是想锻炼我信息提取和英文水平呢

王大富 发表于 2021-2-17 14:38

主要是为了记录一下自己做过的东西
页: [1]
查看完整版本: Arduino Micro SD卡模块使用指南