Go Down

Topic: code problem open SD card <Solved> (Read 195 times) previous topic - next topic

IamFof

Mar 21, 2017, 01:18 am Last Edit: Mar 21, 2017, 08:19 pm by IamFof
Guys and gals

I recently opened a thread (https://forum.arduino.cc/index.php?topic=462445.0) regarding problems I was encountering with this project.  Many thanks, all, for the help and pointers.

I do, however, still have one problem, which I hope one of you Gurus will be able to show me the error of my ways.

The sketch is a group of functions to handle the SD card, which when working 100%, will be ported to the main sketch.  I am developing the functions on a Uno, but I will have to use a Mega, for the project, as I need more pins than the Uno can supply.

On power up, the sketch waits for the SD card to be inserted and init_sw pressed.  It then proceeds to check the card, open the file and write the column headers, for the .csv file.  30 seconds later it writes the sensor data, which it keeps doing every 30 secs.  15 mins in the final version.

If I want to check the data, I press init_sw again, which closes the file and blocks the sketch, until I press init_sw again.  At this point it would just carry on from where it left off.

It didn't, and using Serial.println I realised that it couldn't write to the file as I had omitted to reopen the it.

As I had no info on commands that SDFat used, but with a recollection that SDFat was "built on" SD and seemed to redirect some of its commands, I tried:
Code: [Select]
SD.open(myData, FILE_WRITE);
This brought up a very intuative, for a newby, error message:
Code: [Select]
C:\Electronics\Arduino\Arduino Projects\Solar Shed\Functions in preparation\SD_Card_Routine_With_Array_V4_Forum\SD_Card_Routine_With_Array_V4_Forum.ino: In function 'void RemoveCard()':

SD_Card_Routine_With_Array_V4_Forum:165: error: no matching function for call to 'SdFat::open(File&, int)'

     SD.open(myData, FILE_WRITE);

                               ^

C:\Electronics\Arduino\Arduino Projects\Solar Shed\Functions in preparation\SD_Card_Routine_With_Array_V4_Forum\SD_Card_Routine_With_Array_V4_Forum.ino:165:31: note: candidates are:

In file included from C:\Utilities\Arduino\libraries\SdFat\src/FatLib/FatLib.h:24:0,

                 from C:\Utilities\Arduino\libraries\SdFat\src/SdFat.h:28,

                 from C:\Electronics\Arduino\Arduino Projects\Solar Shed\Functions in preparation\SD_Card_Routine_With_Array_V4_Forum\SD_Card_Routine_With_Array_V4_Forum.ino:29:

C:\Utilities\Arduino\libraries\SdFat\src/FatLib/FatFileSystem.h:82:8: note: File FatFileSystem::open(const char*, uint8_t)

   File open(const char *path, uint8_t mode = FILE_READ) {

        ^

C:\Utilities\Arduino\libraries\SdFat\src/FatLib/FatFileSystem.h:82:8: note:   no known conversion for argument 1 from 'File' to 'const char*'

C:\Utilities\Arduino\libraries\SdFat\src/FatLib/FatFileSystem.h:93:8: note: File FatFileSystem::open(const String&, uint8_t)

   File open(const String &path, uint8_t mode = FILE_READ) {

        ^

C:\Utilities\Arduino\libraries\SdFat\src/FatLib/FatFileSystem.h:93:8: note:   no known conversion for argument 1 from 'File' to 'const String&'

Using library SPI at version 1.0 in folder: C:\Users\iamfof\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.17\libraries\SPI
Using library SdFat at version 2015.4.26 in folder: C:\Utilities\Arduino\libraries\SdFat
exit status 1
no matching function for call to 'SdFat::open(File&, int)'



I then decided to try a different tack, so I called the InitCard() function, instead, but even that wouldn't open the file.  It ran with no errors.

Can anyone shine a light on this for me?

TIA

Fof

PaulS

Quote
As I had no info on commands that SDFat used, but with a recollection that SDFat was "built on" SD and seemed to redirect some of its commands, I tried:
You have that backwards. SD was based on an older version of SdFat.

Quote
This brought up a very intuative, for a newby, error message:
If the message was intuitive, then you should have had a forehead-slapping moment, and fixed the code. So, why did you not do that?

If you failed to #include a ! in that statement, then I'm happy to explain what you might have done wrong. Of course, the "might" would become "did" if you had posted ALL of your code.

What does the attached code represent?
The art of getting good answers lies in asking good questions.

IamFof

@Paul

The comment about the error message was just a tongue-in-cheek comment.  Sorry if you didn't get that.

As I said in the thread, this is a suite of functions to handle and store data to the SD card, which will be ported into the main sketch when it is working.  I develop my functions as free standing modules, which I keep for reuse in later sketches.

As the sketch is >12k I had to attach it, which I did.  This the whole of the SD sketch.

Fof

septillion

As the sketch is >12k I had to attach it, which I did.  This the whole of the SD sketch.
Then that's a good indication you should go back to basics and try a simpler version of your sketch (aka, comment out most of the code) to see where you go wrong ;)
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

IamFof

@septillion

This sketch is a variant on an earlier one, where, after reinsterting the cards, I reset the Uno.  This sketch works perfectly, but causes the readings to go out of time sync with the earlier readings, as resetting the Arduino restarts the 15 min timer.  The only difference between the 2 sketches is
Code: [Select]


[u][b]Requiring Reset[/b][/u]

void RemoveCard()
     
     {
          if ((cardIsInAndReady_Flag == 1) & (cardIsIn_Flag == 1) & (digitalRead (init_sw) == 0))
          {
               while (digitalRead (init_sw) == 0)
               {
                    RedLEDFlash();                                                             // Flash RED LED until switch is released                         
               }
               myData.close();                                                                 // close the file:
               while(digitalRead (init_sw) == 1)
               {
                   RedLEDFlash();                                                              // Flash the RED LED till the card is inserted and Reset pressed
               }
          }
     }


[b][u]Current version[/u][/b]

void RemoveCard()

{                                                                         
  if ((cardIsInAndReady_Flag == 1) & (cardIsIn_Flag == 1) & (digitalRead (init_sw) == 0))
  {
    while (digitalRead (init_sw) == 0)
    {
      RedLEDFlash();                                                                 // Flash RED LED until switch is released
    }
    myData.close();                                                                  // close the file:
    while (digitalRead (init_sw) == 1)
    {
      RedLEDFlash();                                                                 // Flash the RED LED till the card is inserted and Reset pressed
    }
    delay(500);
    SD.open(myData, FILE_WRITE);
//    InitCard();
  }
}


This sketch does 99% of what it should do, apart from opening the file on the card. All I am trying to do at this moment is identify the 1 or 2 lines of code, which I would need, to replace the SD.open(myData, FILE_WRITE), that would enable the file, on the SD, card, to be opened from within the sketch.  The SD.open(myData, FILE_WRITE) is the line giving the error message.  The commented out //InitCard() was an attempt to see if I could open the file by reentering the Init routine.

I have Googled and searched the SDFat examples and have tried various methods, but none of them work.  Hence my asking you guys, who know one hell of a lot more than I do.

Fof

PaulS

myData's type is not defined in the snippets, but, since it appears on the left of the . where the close() method is called, it is safe to assume that it is an instance of the File class, and was returned at some point by SD.open().

As you will have observed from the successful call to SD.open(), open() takes the NAME of the file, not an instance of the File class.
The art of getting good answers lies in asking good questions.

IamFof

@Paul

Thank you. 

How I forgot, or did not see the fact that I had already used this command, I cannot explain.  Just put it down to a 72yr old brain-fart and lack of experience.

Again.  Thank you.

Fof

ps Thread closed.

Go Up