私はArduinoが初めてで、SDソケットが上にあるイーサネットシールドを持っていますが、機能していないようです。SD ライブラリの例から取った簡単なスケッチを実行してカードに関する情報を取得しようとしていますが、「card.init(SPI_HALF_SPEED, chipSelect)」の部分は常に失敗します。
ChipSelect ピンを 4 に設定し、ピン 10 を出力に設定しましたが、まだ何もありません。
私のコード:
#include <SD.h>
Sd2Card card;
SdVolume volume;
SdFile root;
const int chipSelect = 4;
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("\nInitializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT); // change this to 53 on a mega
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card is inserted?");
Serial.println("* Is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
return;
} else {
Serial.println("Wiring is correct and a card is present.");
}
// print the type of card
Serial.print("\nCard type: ");
switch(card.type()) {
case SD_CARD_TYPE_SD1:
Serial.println("SD1");
break;
case SD_CARD_TYPE_SD2:
Serial.println("SD2");
break;
case SD_CARD_TYPE_SDHC:
Serial.println("SDHC");
break;
default:
Serial.println("Unknown");
}
}
void loop(void) {
}
私が得るもの:
SD カードを初期化しています...初期化に失敗しました。確認事項: * カードが挿入されていますか? ※配線は正しいですか?* シールドまたはモジュールに合わせて chipSelect ピンを変更しましたか?
私はArduino Uno R3、イーサネットシールドを使用しています(公式のものではありません)。いくつかの SD カードで試しました: SD/SDHC、2/4/16 Gb、Sandisk/Kingston、FAT16/FAT32 でフォーマット
シールド自体に問題があるのではないかと思います (ただし、イーサネット部分は機能しています)。問題の原因を特定するにはどうすればよいですか? 助けてください!