SdFat and parseInt()

Hello, I am trying to use the parseInt() function (which works fine with <SD.h>) with the SdFat library.

The code data logs information to a micro SD card and was working well before I made changes today...

I added this section of code which I previously tested with the <SD.h> library.

  while (myFile.available()) {      // read from the file until there's nothing else in it:
       int x = myFile.parseInt();
       if ( x != 0){
        main_deploy_alt = x;
       }
     }
     myFile.close();// close the file:
  }

The error i get is:
Arduino: 1.8.16 (Mac OS X), Board: "SparkFun Pro Micro, ATmega32U4 (3.3V, 8 MHz)"

/Users/XXXXXXXXXX/Documents/Arduino/Data_Logger_Micro4/sd_header.ino: In function 'void sd_header()':
sd_header:19:23: error: 'class SdFile' has no member named 'parseInt'; did you mean 'print'?
int x = myFile.parseInt();
^~~~~~~~
print
Multiple libraries were found for "Wire.h"
Used: /Applications/Arduino-2.app/Contents/Java/hardware/arduino/avr/libraries/Wire
Not used: /Users/XXXXXXXX/Documents/Arduino/libraries/Wire
exit status 1
'class SdFile' has no member named 'parseInt'; did you mean 'print'?

I've been through this forum post and not had any joy with it.

I initially had 2 SdFat libraries installed, SdFat & SdFat-master. I moved both of them, downloaded the latest SdFat-master then renamed it SdFat. I also tried changing this line of code in the config file "SdFatConfig.h"

/**
 * Set INCLUDE_SDIOS nonzero to include sdios.h in SdFat.h.
 * sdios.h provides C++ style IO Streams.
 */
#ifndef INCLUDE_SDIOS
#define INCLUDE_SDIOS 1
#endif  // INCLUDE_SDIOS

If that value is 0 or 1 it returns the same error.

All I am trying to do with the addition of parseInt() to the current code is read 1 integer from the SD card on a ".txt" file before logging data to it. I can do it nicely over serial but the parseInt allows me to put the number into an Int in my code nicely.

I also unzipped the html folder as per the instructions in the library.

If anyone has any thoughts or suggestions I'd love to hear them. If it's going to be too difficult to get parseInt to work, if there is a different method to retrieve a single number from a ".txt" file then I could use that and bypass this issue altogether.

Thanks.

Clear out all the versions of SdFat that you have on your computer, and then try to add the library using the library manager.

@jaddion82052
Installation and troubleshooting is for Problems with the Arduino itself NOT your project. Therefore I have moved your post here.

I guess the library you want to use doesn't inherit behaviors from Stream. You could grab the .parseInt() function from the Stream object and adapt it to your needs.

how is myFile declared ?

this compiles fine

#include <SdFat.h>

// SDCARD_SS_PIN is defined for the built-in SD on some boards.
#ifndef SDCARD_SS_PIN
const uint8_t SD_CS_PIN = SS;
#else  // SDCARD_SS_PIN
// Assume built-in SD is used.
const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
#endif  // SDCARD_SS_PIN

// Try to select the best SD card configuration.
#if HAS_SDIO_CLASS
#define SD_CONFIG SdioConfig(FIFO_SDIO)
#elif ENABLE_DEDICATED_SPI
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI)
#else  // HAS_SDIO_CLASS
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI)
#endif  // HAS_SDIO_CLASS

#define error(s) sd.errorHalt(&Serial, F(s))


SdFat sd;
File file;

void setup() {
  Serial.begin(115200);
  if (!sd.begin(SD_CONFIG)) {
    sd.initErrorHalt(&Serial);
    return;
  }

  if (!file.open("test.csv", FILE_READ)) {
    error("open failed");
  }
  int x = file.parseInt();
  file.close();

  Serial.println(x);
}

void loop() {}

so parseInt() seems to be supported at least on compiler level. (I have not tested this live)

I did try that but unfortunately it doesn't work. Interestingly if I do download the SdFat library from library manager I then also lose myFile.flush functionality.

that does not mean anything in particular... Does it compile for you? what does not work?

Apologies I should have been more specific.

When I remove all the old SdFat libraries and install it fresh from the library monitor, I still get the same original error that 'parseInt' is not recognised;

"sd_header:19:23: error: 'class SdFile' has no member named 'parseInt'; did you mean 'print'?"

you get that with the code I posted?

I don't see the option for "SparkFun Pro Micro, ATmega32U4 (3.3V, 8 MHz)" in my IDE - may be it's specific to that board Choice. What happens if you select something else, like a MEGA. Does it compile fine?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.