具有Adafruit数据记录功能的Arduino Mega Arduino护罩不断无法初始化。我的arduino数据记录屏蔽可能有问题吗?我不认为它是SD卡,因为我将其格式化为FAT32。
#include <SPI.h>
File sdcard_file;
int CS_pin = 53;
void setup() {
Serial.begin(9600); //Setting baudrate at 9600
pinMode(CS_pin, OUTPUT); //declaring CS pin as output pin
if (SD.begin()) {
Serial.println("SD card is initialized and it is ready to use");
} else {
Serial.println("SD card is not initialized");
return;
}
sdcard_file = SD.open("data.txt", FILE_WRITE); //Looking for the data.txt in SD card
if (sdcard_file) { //If the file is found
Serial.println("Writing to file is under process");
sdcard_file.println("This data is for test"); //Writing to file
sdcard_file.close(); //Closing the file
Serial.println("Done");
} else {
Serial.println("Failed to open the file");
}
sdcard_file = SD.open("data.txt");
if (sdcard_file) {
Serial.println("Reading from the file");
while (sdcard_file.available()) {
Serial.write(sdcard_file.read());
}
sdcard_file.close();
} else {
Serial.println("Failed to open the file");
}
}
void loop() {
//Nothing in the loop
}