Reading a line of separated values from SD card

Im writing a heating controller sketch and Im building it up in stages. Starting with basic control then gradually adding other things. I have all the control done but now want to read a list of variables from an SD card, and when any get changed to have them overwritten on the SD card. This was if it were switched off and back on, it would always read the latest values from the card. Im also going to be logging some data but that a seperate thing for now.

So I was thinking I could list a line of values like this in a txt file

1, 10, 13, 21, 5,

And maybe use parseint() in the sd reading part of the sketch. I only think this because Ive been googling and this seems to fit what I want. The only problem is Im not too sure on how to use it. I want to obviously read each value and save it to a variable, but does parseint() read the first characters up to the comma, then stop, and if I call parseint() again would it continue from where I left off?

Thanks in advance

but does parseint() read the first characters up to the comma, then stop, and if I call parseint() again would it continue from where I left off?

Yes.

By using parseint() will is automatically see the value as an 'int' or does it read from the SD as a certain type until I change it?

Is there a good source for parseint() details as the arduino site only says what it is used for and Ive only found examples through some forums posts.

You might find something useful in the parse example in Serial Input Basics

...R

Hi

The following procedure can parse a String and extract individual fields using any single character delimiter:

String ENDF2(const String &p_line, int &p_start, char p_delimiter) {
//Extract Next Delmited Field V2
//Extract fields from a line one at a time based on a delimiter.
//Because the line remains intact we don't fragment heap memory
//p_start would normally start as 0
//p_start increments as we move along the line
//We return p_start = -1 with the last field

  //If we have already parsed the whole line then return null
  if (p_start == -1) {
    return "";
  }

  int l_start = p_start;
  int l_index = p_line.indexOf(p_delimiter,l_start);
  if (l_index == -1) { //last field of the data line
    p_start = l_index;
    return p_line.substring(l_start);
  }
  else { //take the next field off the data line
    p_start = l_index + 1;
    return p_line.substring(l_start,l_index); //Include, Exclude
  }
} //ENDF2

Here is an example of parsing a multi-line SMS message received by a SIM800 module. Here is the SMS message String:

+CMGL: 2,"REC UNREAD","+64555111999","","15/09/07,23:31:57+48"
A second text message in realtime that goes into the sim card store.

And here is some code using ENDF2 to break up the various fields using various delimiters. Note that the second field is an integer which we extract using the String.toInt() function:

void ProcessSMSReceived(const String &p_sms) {
//We get an incoming SMS as a single String
//We need to parse it to get the sender's phone number
//and extract/action the SMS message content.

/* Example SMS messages
+CMGL: 2,"REC UNREAD","+64555111999","","15/09/07,23:31:57+48"
A second text message in realtime that goes into the sim card store.

+CMGL: 6,"REC READ","+64555111999","","15/09/05,11:34:48+48"
Hello Saturday
*/

  //parse initial fields
  int l_posn = 0;
  ENDF2(p_sms,l_posn,':'); //discard prefix +CMGL:

  if (p_sms.substring(l_posn,1) = " ")
    l_posn++;
  //
  int l_id = ENDF2(p_sms,l_posn,',').toInt(); //<<How to extract a comma delimited integer

  String l_status = ENDF2(p_sms,l_posn,','); //Includes quotes

  //parse remaining fields
  String l_phone_num = ENDF2(p_sms,l_posn,','); //Includes quotes
  ENDF2(p_sms,l_posn,'\n'); //Discard rest of line (date, time, etc)
  String l_msg = p_sms.substring(l_posn);
  l_msg.trim();
  l_msg.toUpperCase();

  //etc
}

If you read your SD file using the file.readStringUntil(’\n’) function you will have the String variable that you can pass to ENDF2 for parsing.

I hope this helps.

Cheers

Catweazle NZ

By using parseint() will is automatically see the value as an 'int'

Well, I'm sure that there is a reason that the function was not called parseSomeRandomStupidType().

or does it read from the SD as a certain type until I change it?

It? Don't use pronouns without referents.

The parseInt() method will not decide that this time, you get a float, and next time a double, and then a byte, and then a long long. It ALWAYS returns the same type, which you can look up.

Is there a good source for parseint() details as the arduino site only says what it is used for

What else do you need to know? Get off your ass and try something.

I would like to know how to use the parseint() method. Hence asking if any know a good reference source. I dont know how to structure the code to make use of it. I tried it like you said, but inevitably it didnt work. So im now back to asking the same question again.
Googling just seems to bring back completely irrelevant material and not much else.

Reading a few other things I can see that the indexOf() method would work (as CatweazleNZ mentioned) but I want to read up a bit more so I can understand whats going on.

Just in case you dont already realise Im not a coding expert.