我正在尝试使用带有Arduino Mega2560的Spark fun的SD卡模块运行一个简单的程序。这是我目前正在使用的程序:
#include <SD.h>
const int chipSelect = 10;
void setup()
{
Serial.begin(9600);
Serial.print("Initializing SD card...");
pinMode(53, OUTPUT);
digitalWrite(10, HIGH);
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
}
void loop()
{
String dataString = "";
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += ",";
}
}
File dataFile = SD.open("datalog.txt", FILE_WRITE);
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
Serial.println(dataString);
}
else {
Serial.println("error opening datalog.txt");
}
}
我收到的错误说: 初始化SD卡...卡失败或不存在 打开datalog.txt错误
答案 0 :(得分:1)
更改
pinMode(53, OUTPUT);
digitalWrite(10, HIGH);
要
pinMode(53, OUTPUT);
digitalWrite(53, HIGH);
试一试。