1

This code is just a test code to write a file to an SD card using an SD card module. When I run the code, I get this error message and I'm not sure what to do to fix the code: no matching function for call to'SDLib::SDClass::exists(SDLib::File&)'.

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

int cs = 10; 

File myTest;  

void setup()
{
  //
  char myTestName[] = "MyTest.txt";  

  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {

  }
  Serial.println("Initializing SD card...");
  Serial.println();

  pinMode(cs, OUTPUT);
  pinMode(SS, OUTPUT);
  if (!SD.begin(cs)) {
    Serial.println("SD did not initiliaze");   
    while (1) ;
  }
  Serial.println("SD initialized.");

  if (! SD.exists(myTest)){
     myTest = SD.open(myTestName, FILE_WRITE); 

     myTest.println("My 1st Line of Data");
     myTest.flush(); 
  }
  else{
    myTest = SD.open(myTestName, FILE_WRITE); 
    myTest.println("Another Line of Data"); 
    myTest.flush();

  }

  Serial.println("Done Writing");

}

void loop()
{

}

1 Answer 1

0

The function is defined as

// Methods to determine if the requested file path exists.
boolean exists(char *filepath);

Source: https://github.com/adafruit/SD/blob/master/SD.h#L90

You call it with a File object, not the filename. You probably mixed up the variable names:

File myTest;  

void setup()
{
  //
  char myTestName[] = "MyTest.txt";  

  //[...]
  if (! SD.exists(myTest)){
     myTest = SD.open(myTestName, FILE_WRITE); 
     myTest.println("My 1st Line of Data");
     myTest.flush(); 
  }
//.. 

Just exchange myTest for myTestName in the SD.exists() call.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.