实现效果
本次实现的是删除上一篇添加的LSLAB.txt 文件
效果图?没有啦,都删掉了哪里还有
.
.
.
.
.
.
.
.
.
.
.
.
.
.
还是有的
BOM表
Arduiino Uno *1
SD卡模块 *1
SD卡 *1
调线若干
接线
Arduino Uno <-----> Sd Card 模块
GND <-----> GND
5V <-----> +5
CS <-----> Pin 4
MOSI <-----> Pin 11
SCK <-----> Pin 13
MISO <-----> Pin 12
详细请参照 文章 Arduino Uno SD卡模块 (一)获取SDcard的信息
开源程序
这个实验还是需要下载库
下载地址: https://github.com/greiman/SdFat
具体如何操作,再次说一下,下载解压到Arduino IDE的安装路径里的库文件夹libraries
库里提供了很多SD卡模块示例程序,可以多多参考
//加载SPI库和SD库
#include <SPI.h>
#include <SD.h>
void setup()
{
Serial.begin(9600); //设置波特率
while (!Serial)
{
; // wait for serial port to connect. Needed for native USB port only
//等待串行端口连接。 仅适用于本机USB端口
}
Serial.print("Initializing SD card...");//正在初始化
//如果为非则初始化失败
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");//初始化结束
// delete the file:
Serial.println("Removing LSLAB.txt...");//串口输出 正在删除LSLAB.txt
SD.remove("LSLAB.txt"); //删除LSLAB.txt
if (SD.exists("LSLAB.txt")) { //判断LSLAB.txt文件是否存在
Serial.println("LSLAB.txt exists.");
} else {
Serial.println("LSLAB.txt doesn't exist.");
}
}
void loop() {
}
程序实现思路讲解
1.
//加载SPI库和SD库
#include <SPI.h>
#include <SD.h>
2
SD.remove("LSLAB.txt"); //删除LSLAB.txt