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

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2356|回复: 2

Arduino Micro SD卡模块使用指南

[复制链接]
发表于 2021-2-15 10:15 | 显示全部楼层 |阅读模式





/*
* 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
}
发表于 2021-2-16 11:20 | 显示全部楼层
合着LZ是想锻炼我信息提取和英文水平呢
 楼主| 发表于 2021-2-17 14:38 | 显示全部楼层
主要是为了记录一下自己做过的东西
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-12-1 05:41 , Processed in 0.068295 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表