ArduCom SD Kart Uygulaması - ArduCom/Arduino-Communication-Shield GitHub Wiki

ArduCom - SD Kart Çalışma Testi


Bağlantı şeması

Uygulama Kodu:

#include <SPI.h>
#include <SD.h>

Sd2Card card;
SdVolume volume;
SdFile root;


const int chipSelect = 6;

void setup()
{
  Serial.begin(9600);
  while (!Serial) {
    ;
  }
  Serial.print("\nInitializing SD card...");
  pinMode(chipSelect, OUTPUT); 

  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(" \b \n \n ***** Test Basarili!!!   ******** ");
  }

  // 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) {

}    

ArduCom - SD Karta bilgi yazma ve okuma

#include <SPI.h>
#include <SD.h>

File myFile;

void setup()
{
  Serial.begin(9600);
  Serial.print("kart tanımlanıyor...");
  pinMode(6, OUTPUT);

  if (!SD.begin(6)) {
    Serial.println("SD kart tanımlanmadi!");
    return;
  }
  Serial.println("Tanimlanma tamamlandi.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("arduCom.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Dosyaya yaziyorum arduCom.txt...");
    myFile.println("testing 1, 2, 3.");
    // close the file:
    myFile.close();
    Serial.println("yazdim.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("Dosya acarken hata olustu arduCom.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("arduCom.txt");
  if (myFile) {
    Serial.println("arduCom.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("Dosya acarken hata olustu arduCom.txt");
  }
}

void loop()
{
 
}
⚠️ **GitHub.com Fallback** ⚠️