SDFat library - how to get work parseInt() ?

Working libraries, libraries being ported and related hardware
stm32_discoverer
Posts: 17
Joined: Sun Jan 01, 2017 10:28 am

SDFat library - how to get work parseInt() ?

Post by stm32_discoverer » Fri Feb 17, 2017 9:34 pm

Hi, i'm trying to get an integer from an array from text file on my SD card? But in old library SD.h it was easy like

Code: Select all

myFile = SD.open("test.txt");
    if (myFile) {
        while (myFile.available() && i<len) {
            x = myFile.parseInt();
            Serial.println(x);
        }
        myFile.close();
Ok, but in SDfat.h library while compiling code there is- 'class SdFile' has no member named 'parseInt'
So, how can I get my "parseInt()"?

victor_pv
Posts: 1741
Joined: Mon Apr 27, 2015 12:12 pm

Re: SDFat library - how to get work parseInt() ?

Post by victor_pv » Fri Feb 17, 2017 9:49 pm

I think this thread may be related:
https://forum.arduino.cc/index.php?topic=326573.0

The issue is not specific to the stm core, but rather the way the sdfat library works.

stm32_discoverer
Posts: 17
Joined: Sun Jan 01, 2017 10:28 am

Re: SDFat library - how to get work parseInt() ?

Post by stm32_discoverer » Fri Feb 17, 2017 10:10 pm

yeah, I already saw this link, tried it, didn't help

victor_pv
Posts: 1741
Joined: Mon Apr 27, 2015 12:12 pm

Re: SDFat library - how to get work parseInt() ?

Post by victor_pv » Fri Feb 17, 2017 11:09 pm

stm32_discoverer wrote:yeah, I already saw this link, tried it, didn't help
So you have this:

Code: Select all

#define ARDUINO_FILE_USES_STREAM 1
in SdFat/src/SdFatConfig.h right?

What version of the sdfat library are you using?

stm32_discoverer
Posts: 17
Joined: Sun Jan 01, 2017 10:28 am

Re: SDFat library - how to get work parseInt() ?

Post by stm32_discoverer » Sat Feb 18, 2017 7:37 am

I'm using SDFat-beta from greiman

stm32_discoverer
Posts: 17
Joined: Sun Jan 01, 2017 10:28 am

Re: SDFat library - how to get work parseInt() ?

Post by stm32_discoverer » Sat Feb 18, 2017 7:43 am

But I don't see

Code: Select all

#define ARDUINO_FILE_USES_STREAM 1
in "SdFatConfig.h"

User avatar
Pito
Posts: 1627
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: SDFat library - how to get work parseInt() ?

Post by Pito » Sat Feb 18, 2017 9:49 am

Code: Select all

#include <SPI.h>
#include "SdFat.h"
SdFat SD;
const uint8_t csPin = SS;
File file;
..
  file = SD.open("stream.txt", O_RDWR|O_CREAT|O_TRUNC);
  if (!file) {
    Serial.println(F("open error"));
    return;
  }
;
..
  // Rewind the file and read the number with parseInt().
  file.seek(0);
  int i = file.parseInt();
  Serial.println(i);
  file.close();
From SdFat examples
Pukao Hats Cleaning Services Ltd.

stm32_discoverer
Posts: 17
Joined: Sun Jan 01, 2017 10:28 am

Re: SDFat library - how to get work parseInt() ?

Post by stm32_discoverer » Sat Feb 18, 2017 12:42 pm

weird, but this sketch does not read my sd card

stm32_discoverer
Posts: 17
Joined: Sun Jan 01, 2017 10:28 am

Re: SDFat library - how to get work parseInt() ?

Post by stm32_discoverer » Sat Feb 18, 2017 12:45 pm

That's my code

Code: Select all

#include <SPI.h>
#include "SdFat.h"
SdFat sd1(1);
// SdFatEX sd1(1);
const uint8_t SD1_CS = PA4;  // chip select for sd1

//SdFat sd2(2);
//// SdFatEX sd2(2);
//const uint8_t SD2_CS = PB12;   // chip select for sd2

#define errorExit(msg) errorHalt(F(msg))
#define initError(msg) initErrorHalt(F(msg))
unsigned long duration;
int my_array[1000];
int num;
int c;

void setup() {
  Serial.begin(115200);
  delay(10000);
  
  // initialize the first card
  if (!sd1.begin(SD1_CS, SD_SCK_MHZ(18))) {
    sd1.initError("sd1:");
  }

  // initialize the second card
//  if (!sd2.begin(SD2_CS, SD_SCK_MHZ(18))) {
//    sd2.initError("sd2:");
//  }
  Serial.println(F("------sd1 root-------"));
  sd1.ls();
  // set the current working directory for open() to sd2
  //sd1.chvol();
  
  File file1;
  if (!file1.open("data.txt", O_RDWR | O_CREAT | O_TRUNC)) {
    sd1.errorExit("file1");
  } 
  for (int x=0;x<1000;x++){
    parseUInt();
    Serial.println(num);
  }
    file1.close();
    Serial.println(F("Done"));
}
void loop(){}

int parseUInt () { 
  int num=-1;
  while (true) {
    int c = file1.read();
    if (c>47 && c<58) {
      if (num<0) num=0;  
      num=num*10+c-48;
    } else if (num>-1 || c==-1) return num;   
  }
}
but it doesn't compile, and gives an error message

Code: Select all

sdfat_stm32_parseint.ino: In function 'int parseUInt()':
sdfat_stm32_parseint:52: error: 'file1' was not declared in this scope
'file1' was not declared in this scope

stm32_discoverer
Posts: 17
Joined: Sun Jan 01, 2017 10:28 am

Re: SDFat library - how to get work parseInt() ?

Post by stm32_discoverer » Sat Feb 18, 2017 12:50 pm

even if I replace the function - parseUInt () to int c = file1.parseInt(); - code does not work

Post Reply