【发布时间】:2023-04-03 15:05:01
【问题描述】:
我正在尝试读取数据并将数据写入 SD 卡,但在代码开始时,我收到错误 Card Failed or not present。我更改了为 Arduino Uno 编写的示例代码中的引脚,但仍然给出相同的错误。我正在使用 Arduino Mega 2560。我该如何解决这个问题?我的代码在这里:
#include <SD.h>
// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 53;
void setup()
{
Serial.begin(9600);
Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(53, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
}
void loop()
{
}
【问题讨论】: