alpenpower:
Ich betreibe das Mega2560-Bundle (der Schrott von Sainsmart) mit dem 3.2"-TFT mit dem TFT-Shield V1.0.
Und ich dachte bisher, das große S auf der Boardbeschriftung des Sainsmarr MEGA steht nur für "Sainsmart".
Aber das steht für "Schrott von Sainsmart"? Müßte es dann kein Dreibuchstabenkürzel wie SvS sein?
Na ja, man lernt nie aus.
Ich verwende auch ein MEGA-Board mit dem großen S wie Schrott von Sainsmart.
Allerdings mit SD-Kartenschacht auf einem Ethernet-Shield und nicht auf einem TFT.
Dieser nur leicht modifizierte Demo-Sketch zur SD-Library funktioniert auf einem Schrott-von-Sainsmart MEGA-Board völlig einwandfrei:
// include the SD library:
#include <SD.h>
// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 4;
void setup()
{
// Open serial communications and wait for port to open:
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(SS, OUTPUT); // change this to 53 on a mega
delay(10);
// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
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");
}
// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
if (!volume.init(card)) {
Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
return;
}
// print the type and size of the first FAT-type volume
uint32_t volumesize;
Serial.print("\nVolume type is FAT");
Serial.println(volume.fatType(), DEC);
Serial.println();
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
volumesize *= 512; // SD card blocks are always 512 bytes
Serial.print("Volume size (bytes): ");
Serial.println(volumesize);
Serial.print("Volume size (Kbytes): ");
volumesize /= 1024;
Serial.println(volumesize);
Serial.print("Volume size (Mbytes): ");
volumesize /= 1024;
Serial.println(volumesize);
Serial.println("\nFiles found on the card (name, date and size in bytes): ");
root.openRoot(volume);
// list all files in the card with date and size
root.ls(LS_R | LS_DATE | LS_SIZE);
}
void loop(void) {
}
Die beiden von mir geänderten Zeilen sind:
pinMode(SS, OUTPUT); // change this to 53 on a mega
delay(10);
Als Hardware-SS Pin setze ich einfach SS anstelle einer Pin-Nummer ein.
Und danach füge ich ein kleines delay von 10 Millisekunden ein.
Funktioniert einwandfrei.
alpenpower:
Die SD-Karte ist eine 2GB-Karte und kann über jeden PC gelesen werden.
Das ist kein Argument. PCs können auch Karten lesen, die mit speziellen Dateisystemen formatiert sind wie NTFS (Windows) oder EXT3 (Linux) oder sonstwas. Arduinos mit ihren einfachen Libraries können nur FAT-formatierte Karten lesen. Hast Du die Formatierung der Karte mal überprüft und sie ggf. mal frisch FAT-formatiert?
Das Chipselect muss dabei im Sketch passend eingestellt werden:
const int chipSelect = 4;
Und zwar so, dass mit dem PIN der SD-Kartenschacht auf Deinem Shield selektiert wird. Der Pin ist abhängig von der Hardware, beim Ethernet-Shield ist es D4, der den SD-Kartenschacht anwählt.