Copy a file line by line using SMARTGPU2.

Hi arduinians!

I'm new to SMARTGPU2 and trying get some readings from temperature sensors and store their values into micro SD attached to SMARTGPU2. Every thing works fine, except file format. The current data on the file are now presented like this:

123.5 125.3 110.5 ...... 100.4 (8 readings)

The desired format should be this:

123.5
125.3
110.5
.
.
.
.
.
100.4

I've tried to get this format in many ways, and every time I've read the file in NotePad from SD I get the line of data, not a column.

My code is breafly like this:

//Variable declarations

some variables
......

char Dacq[51]; //C-style string

char S1[6], S2[6], S3[6], S4[6], S5[6], S6[6], S7[6], S8[6]; //to store the sensor's value in string //format.

.....
some code;

...
Dacq[0]='\0'; // be sure the string is empty.

strcat(Dacq, S1); strcat(Dacq, S2);.....strcat(Dacq, S81); strcat(Dacq, "\n"); //last member is the
//nonprintable character - "new line".

....some code
... test if file exists, etc.
... open file (.txt)

lcd.SDFwriteFile(Dacq, sizeof(Dacq), &writtenBytes, WORKSPACE0); //use a comand to write info into file - from library SMARTGPU2.cpp

...close file.


Some how it should work, but it does not.!!

Changing : strcat(Dacq, "\n"); by strcat(Dacq, "\n\r"); does not produce any changes in results. The same if add a zero termination to data array - strcat(Dacq, "\n\r"); strcat(Dacq, "\0");

Does any one from SMARTGPU2 experts have a solution to this problem?

Thanks in advance. :slight_smile:

So we can help you, you need to post all your code inside code tags so it looks like this:

... code here

But yes, you need to add \n characters between each of your readings.

Sorry budy.

I've posted below the code.

Just some coments about the errors I still getting.

The data line is shown like this: 29.3328.3224.5834.24 (note here were ignored all "\n" ¿?!!)

The second thing I noted is the pointer has freezed on 35 bytes, it does not increment as expected. I can`t find the error here.

Thanks in advance for any asistence.

Formato_File.ino (4.14 KB)

Don't attach the code, post it directly in the forum so we can read it.

Please read the "how to post to this forum" thread.

Here is his code:

#include <SMARTGPU2.h>
SMARTGPU2 lcd;             //create our object called LCD

char Dacq[35], Spointer[4];   //data vector we must save on microSD
unsigned long pointer=0;
const int numReadings = 10; 
int i, Counter=0;
int Tens1, Tens2, Tens3, Tens4;      // vectors of numReadings places
float Tens1F, Tens2F, Tens3F, Tens4F;
float Tratio=20.0;
char SV1[7], SV2[7], SV3[7], SV4[7];
FILERESULT res;     //this variable that will store all SMARTGPU2 commands responses
unsigned int writtenBytes=0;

/*********************** function that reports errors and loops forever ********************************/
void die(FILERESULT response){ //if the response is different than OK, print and loop forever
  if(response!=F_OK){
     lcd.string(100, (MAX_Y_LANDSCAPE+1)-50, MAX_X_LANDSCAPE,MAX_Y_LANDSCAPE,"Error...",0);
    while(1);  
  }
}

/*********************************************************/
void setup() {
  // put your setup code here, to run once:
  lcd.init();  //configure the serial and pinout of arduino board for SMARTGPU2 support
  lcd.start(); //initialize the SMARTGPU2 processor
  lcd.baudChange(BAUD5);           //set high baud for advanced applications
  lcd.orientation(LANDSCAPE_LEFT);   //set orientation as LANDSCAPE 
  
  lcd.setTextColour(YELLOW);  //Sets the font style
  lcd.setTextSize(FONT0);
  lcd.setTextBackFill(TRANS);     
}

void loop() {
  // put your main code here, to run repeatedly: 
  do {    
  for(i=0; i<numReadings; i++) {  //take 10 readings in additions
     Tens1+=analogRead(A0);
     Tens2+=analogRead(A1);
     Tens3+=analogRead(A2);
     Tens4+=analogRead(A3);
  }
  Tens1F=(Tens1/10.0)*(5.0/1023.0)*Tratio;    //average smoothing and Temperature convertions
  Tens2F=(Tens2/10.0)*(5.0/1023.0)*Tratio;
  Tens3F=(Tens3/10.0)*(5.0/1023.0)*Tratio;
  Tens4F=(Tens4/10.0)*(5.0/1023.0)*Tratio;
  
   dtostrf(Tens1F,6,2,SV1);  // float to style-C string convertion
   dtostrf(Tens2F,6,2,SV2);
   dtostrf(Tens3F,6,2,SV3);
   dtostrf(Tens4F,6,2,SV4);
   
  Dacq[0]='\0';
  strcat(Dacq, SV1); strcat(Dacq, "\n"); strcat(Dacq, SV2); strcat(Dacq, "\n"); strcat(Dacq, SV3); strcat(Dacq, "\n"); strcat(Dacq, SV4); 
  strcat(Dacq, "\n"); strcat(Dacq, "\0");  //fomating my output data line.
  
  /*******************  Saves collected data into microSD Flash memory *******************************/
        
       lcd.string(205, (MAX_Y_LANDSCAPE+1)-70, MAX_X_LANDSCAPE,MAX_Y_LANDSCAPE,"Saving...",0); //prints on SMARTGPU2 the new pointer position 
       res=lcd.SDFopenFile("Data01.txt", WRITEONLY, WORKSPACE0);  //Try to open a file Data00.txt" in the workspace block 0    
       if(res!=F_OK){                       //If the file doesn't Open is because it doesn't exist      
       res=lcd.SDFnewFile("Data01.txt");  //Creates the file 
       die(res);                        //If any error loop forever
       res=lcd.SDFopenFile("Data01.txt", WRITEONLY, WORKSPACE0);  //Try to open the created file      
       die(res);                        //If any error loop forever
        }
       sprintf (Spointer, "%04i", pointer); 
       lcd.drawRectangle(95,(MAX_Y_LANDSCAPE+1)-52, 150, (MAX_Y_LANDSCAPE+1)-37,BLUE,FILL);  
       lcd.string(100, (MAX_Y_LANDSCAPE+1)-50, MAX_X_LANDSCAPE,MAX_Y_LANDSCAPE,Spointer,0); //prints on SMARTGPU2 the current pointer position 
       delay(10);
       res=lcd.SDFsetFilePointer(pointer, WORKSPACE0); // sets a new position pointer on the file "Data00.txt" (It`s supossed)
       delay(2);
       die(res);
       res=lcd.SDFwriteFile(Dacq, sizeof(Dacq), &writtenBytes, WORKSPACE0);
       delay(10); 
       die(res);
       res=lcd.SDFsaveFile(WORKSPACE0);
       delay(2); 
       die(res);
       pointer+=sizeof(Dacq);  //increments file pointer
       lcd.SDFcloseFile(WORKSPACE0);         //Close the file --------------------
       lcd.drawRectangle(200,(MAX_Y_LANDSCAPE+1)-74, 250, (MAX_Y_LANDSCAPE+1)-54,BLUE,FILL);  // Prints total accumulated Energy 
       delay(2000);  //Every 2 seconds repeat the loop.
       Counter++;
       } while(Counter<5);
       lcd.string(201, (MAX_Y_LANDSCAPE+1)-70, MAX_X_LANDSCAPE,MAX_Y_LANDSCAPE," The end",0); //prints on SMARTGPU2 the new pointer position
       while(1);  //enless loop.
  }