What is wrong in my second program? (Solved)

I want to read a string and more floats from SD-card (SLsetup.csv) and store that values to the internal EEPROM.

First I wrote a program to read the figures from SD-card; it functions fine:

//===========================================================================
//Import parameters from SD-card (SLsetup.csv), convert them to float-variables (and put them in EEPROM on board of Arduino 2560 Mega)
void Import_parameters(){

int intN=1;
byte ASCIIvalue;
String strBuffer="";
float sngTempvalue;

//Open the file for reading:
myFile = SD.open("SLsetup.csv");
//Read projectname as string, N has to be NumberOfCharacters +2 (so including CR and LF)
for (intN=1; intN<=13; intN++)
{char in_char = myFile.read();
int intASCIIvalue = int(in_char);
strBuffer += in_char;}

Serial.print("Arduino Received: "); Serial.print(strBuffer); Serial.print("\n");
strBuffer = ""; // Clear received buffer

//Read floats
while (myFile.available()) {
char in_char = myFile.read();
strBuffer += in_char;
if (in_char=='\n') {
Serial.print("Arduino Received: "); Serial.print(strBuffer); Serial.print("\t"); Serial.print("Floatwaarde = "); Serial.print(StrToFloat(strBuffer),8); Serial.print("\n");
strBuffer = ""; // Clear received buffer
} // End if
} //End while

// close the file:
myFile.close();
} //End of function

//============================================================================
float StrToFloat(String str){
char carray[str.length() + 1]; //determine size of the array
str.toCharArray(carray, sizeof(carray)); //put str into an array
return atof(carray);
}[/color]

Lateron I made some changes, but the result is that the program comes in a loop (only the string and the first float will be read)!
//===========================================================================
//Page 26, Import parameters from SD-card (SLsetup.csv), convert them to float-variables (and put them in EEPROM on board of Arduino 2560 Mega), written on 20130531
void Import_parameters(){

int intN=1; byte ASCIIvalue; String strBuffer=""; float sngTempvalue;
char output[] = " ", charArray[]="", EOL='\n', in_char;
File myFile;
int intRow=1, intStarttime, intEndtime;

intStarttime=millis();

//Open the file for reading:
myFile = SD.open("SLsetup.csv");
//Read projectname as string, N has to be NumberOfCharacters +2 (so including CR and LF)
for (intN=1; intN<=21; intN++){
char in_char = myFile.read();
strBuffer += in_char; } //End for loop
//Store projectname to EEPROM
strBuffer.toCharArray(charArray, 21); //conversion of string (strBuffer) into characterarray. Aantal moet 2 hoger zijn dan aantal letters
Serial.print(charArray); Serial.print("\n");
EEPROM.writeBlock(0, charArray, 21);
strBuffer = ""; // Clear received buffer

//Read floats
while (myFile.available()) {
char in_char = myFile.read();
Serial.print(in_char); Serial.print("\n");
strBuffer += in_char;
if (in_char=='\n') {
//Store floats to EEPROM
EEPROM.writeFloat(intRow*4+16, StrToFloat(strBuffer));
Serial.print(StrToFloat(strBuffer)); Serial.print("\n");
intRow++;
strBuffer = ""; // Clear received buffer
} // End if
} //End while

// close the file:
myFile.close();

intEndtime = millis();
Serial.print (intEndtime - intStarttime); Serial.println();

Serial.print (EEPROM.readBlock(0, output, 19)); Serial.println();
Serial.print (EEPROM.readFloat(20)); Serial.println();
Serial.print (EEPROM.readFloat(24)); Serial.println();
Serial.print (EEPROM.readFloat(28)); Serial.println();
Serial.print (EEPROM.readFloat(32)); Serial.println();

intEndtime=millis();
Serial.print(intEndtime - intStarttime); Serial.print('\n');

} //End of function

//============================================================================
float StrToFloat(String str){
char carray[str.length() + 1]; //determine size of the array
str.toCharArray(carray, sizeof(carray)); //put str into an array
return atof(carray);
}

Start here

void Import_parameters(){

  int intN=1;
  byte ASCIIvalue;
  String strBuffer="";
  float sngTempvalue;
 
  //Open the file for reading:
  myFile = SD.open("SLsetup.csv");
  //Read projectname as string, N has to be NumberOfCharacters +2 (so including CR and LF)
  for (intN=1; intN<=13; intN++)
      {char in_char = myFile.read();

Some consistency in your code would be a good thing. Either the { goes on the same line as the statement, or it goes on a new line. Pick ONE style and stick with it. Do NOT use both styles in one program.

Whichever style you elect to use, NOTHING goes on the line after the {.

If you elect to put the { on the same line as the statement, there should be a space between the statement and the {/

Codewithoutspacesishardtoread.

char in_char = myFile.read();
      int intASCIIvalue = int(in_char);
      strBuffer += in_char;}

This is rubbish. You want to append the letter to the String, not the ASCII code for the letter as a string.

You also really don't want to be using Strings.

          Serial.print("Arduino Received: "); Serial.print(strBuffer); Serial.print("\t"); Serial.print("Floatwaarde = "); Serial.print(StrToFloat(strBuffer),8); Serial.print("\n");

It's
one
statement
per
line.
Period.
No exceptions.

Thank you Paul for your remarks to my program style.

At the moment I don't still have a feature to read a file (Setup.CSV) with first of all a string with a fixed number of characters (projectname) followed by a number of floats.

At the moment I don't still have a feature to read a file (Setup.CSV) with first of all a string with a fixed number of characters (projectname) followed by a number of floats.

I don't understand this statement.

The code you have does something. It isn't clear what that is.
The code you have produces serial output. You haven't shared that.

I solved my problem to read a string and some floats from SD-card and store them to EEPROM.

/*
Programname: **********
The hardware circuit:
-   Arduino MEGA 2560
-   SD-slot
Version:     005a (shortend version of 5)
Author:      C.W.A. Baltus
Created:     9-5-2013
Modified:    06-06-2013
*/

//================================================================================================
//Libraries
#include <EEPROMEx.h>
#include <SD.h>

//Global variables

// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 53;

//=======================================================================================================
void setup()
{
Serial.begin(9600);      // open the serial port at 9600 bps:   

pinMode(53, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");      //uitbreiden naar LCD
    // don't do anything more:
    return;
    }

Import_parameters();
}  //End of setup

//======================================================================================================
void loop(){
// Nothing within this loop
}

//======================================================================================================
//Page 26, Import parameters from SD-card (SLsetup.csv),
//First row in the file is a string (projectname), later figures are floats.
//Figures will be read as a string and converted to float-variables. 
//In the meanwhile the data has to be stored in internal EEPROM 
void Import_parameters(){

int intN=1; byte ASCIIvalue; String strBuffer=""; 
char output[] = "       ",  charArray[]="";
File myFile;
int intRow=1, intStarttime, intEndtime;
char in_char;



intStarttime=millis();

//Open the file for reading:
myFile = SD.open("SLsetup.csv");

//Step 1:Read projectname as string, N has to be Number Of Characters +2 (so including CR and LF)
//Projectname has a fixed number of characters
for (intN=1; intN<=13; intN++)
      { char in_char = myFile.read();
      int intASCIIvalue = int(in_char);
      strBuffer += in_char; }
Serial.print("Arduino Received: ");  Serial.print(strBuffer);  Serial.print("\n");
myFile.println(strBuffer);
strBuffer = ""; // Clear received buffer
 
//Step 2: Read floats
while (myFile.available()) {
    char in_char = myFile.read();
    strBuffer += in_char;
    if (in_char=='\n') {
        Serial.print("Arduino Received: "); Serial.print(strBuffer); Serial.print("\t"); Serial.print("Floatwaarde = "); Serial.print(StrToFloat(strBuffer),8); Serial.print("\n");
        //Store floats to EEPROM
        EEPROM.writeFloat(intRow*4+16, StrToFloat(strBuffer));  
        intRow++;
        strBuffer = ""; // Clear received buffer
        } // End if
}  //End while

// close the file:
myFile.close();
  
//Verify if data has been written correct
EEPROM.readBlock<char>(0, output, 13);
Serial.print (output);  Serial.println();  
Serial.print (EEPROM.readFloat(20));  Serial.println();  
Serial.print (EEPROM.readFloat(24));  Serial.println();  
Serial.print (EEPROM.readFloat(28));  Serial.println();  
Serial.print (EEPROM.readFloat(32));  Serial.println();  
Serial.print (EEPROM.readFloat(40), 8);  Serial.println();  

//Present the used time in millis
intEndtime=millis();
Serial.print("Used time = "); Serial.print(intEndtime - intStarttime); Serial.print(" ms"); Serial.print('\n');

}  //End of function

//============================================================================
float StrToFloat(String str){
  char carray[str.length() + 1]; //determine size of the array
  str.toCharArray(carray, sizeof(carray)); //put str into an array
  return atof(carray);
}

#include <EEPROMEx.h>

Hoi,
I tried to store floats in EEPROM too and started to search for a solution.

Where can I find the EEPROMEx.h and it's documentation?

Met vriendelijke groeten
O_Lampe

For EEPROMex.h see http://thijs.elenbaas.net/downloads/?did=6