Code doesnt save every string to SD Card.

Hello,

im using a ESP32 and already wrote Code to save strings to the SD Card.

Now my function changed a bit and i get a pointer to the array, instead of just the array.

The header String in the setup() gets saved to the SD card no problem, but the actual datastring doesnt get saved. Both are Strings, both use the same function to save, but the header saves onto the SD card and the datastring doesnt.

Its kind of a big project so i will just post the function, the setup and the class.

I thank you in advance for helping me with my problem :slight_smile:

Here is the setup():

void setup() {
  Serial.begin(115200);

  p_EKG_state_1 = &EKG_state_1;

  pinMode(CS_Pin, OUTPUT);
  if(!SD.begin(CS_Pin))
    {
      Serial.println("Card failed or not present");
    }

  EKG_data_transmision.matrixData = SD.open("/data.csv", FILE_APPEND);  //erstelle data.csv datei

  if(EKG_data_transmision.matrixData)
    {
    String header = "ID; Value;";
    EKG_data_transmision.matrixData.println(header);
    EKG_data_transmision.matrixData.close();
    Serial.println(header);
    Serial.println("card init sucess");
    }
  else
    {
    Serial.println("Couldnt open vector data file");
    }
  

}

Here is the function where everything should go down.

bool  EKG_data_transmision::write_matrix_to_SD(unsigned short *array_pointer) 
{

   if(!SD.begin(CS_Pin))
  {
    Serial.println("Card failed or not present");
    return 1;
  }
  matrixData = SD.open("/data.csv", FILE_APPEND);  //erstelle data.csv datei
  
  if(matrixData)
  {
    //sd karte immer noch da und schau ob data.csv exisitiert
    
    while(matrix_coloum < 3070)
    {
      if(matrix_coloum == 1024 || matrix_coloum == 2048)
      {
          header = "ID; Value;\n";
          matrixData.println(header);   
      }
      dataString = String(matrix_coloum) + "; " + "\n"; // + String(*array_pointer) 
      matrixData.println(dataString);
      //Serial.println("This is datastring:");
      Serial.println(dataString);
      array_pointer++;
      matrix_coloum++;
    } 
    
  }
   
  else{
    Serial.println("Error writing to file !");
}
  matrixData.close(); // close the file
  
  return 0;
}

Here is the class

#include "Arduino.h"
#include <WiFi.h>
#include "SD.h"
#include "SPI.h"
#include <vector>
#include <string>


class EKG_data_transmision
{
  private:
    
    String dataString;
    String header;
    unsigned short matrix_coloum = 0;
    
    
    
  public:
    EKG_data_transmision();

    File matrixData;

    //Def Funktions:
    bool write_matrix_to_SD(unsigned short *array_pointer);
    bool delete_matrix_from_SD(unsigned int record);
    bool send_record_to_DB(unsigned int record);
    bool connect_wifi(char* ssid, char *password);
    unsigned int count_record_from_SD();
    unsigned int get_last_record_from_SD();

    void set_sendingprogress(unsigned int record);
    unsigned int get_sendingprogress(unsigned int record);
    void set_wifi_password(char* password);
    char* get_wifi_password();
    void set_wifi_ssid(char* ssid);
    char* get_wifi_ssid();

};

If i try to write matrixdata.write() instead of matrixdata.println() i get this error:

sketch\EKG_data_transimission.cpp: In member function 'bool EKG_data_transmision::write_matrix_to_SD(short unsigned int*)':

EKG_data_transimission.cpp:32:34: error: no matching function for call to 'fs::File::write(String&)'

           matrixData.write(header);   

                                  ^

In file included from C:\Users\Valentin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SD\src/SD.h:17:0,

                 from sketch\EKG_data_transmision.h:3,

                 from sketch\EKG_data_transimission.cpp:2:

C:\Users\Valentin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\FS\src/FS.h:54:12: note: candidate: virtual size_t fs::File::write(uint8_t)

     size_t write(uint8_t) override;

            ^

C:\Users\Valentin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\FS\src/FS.h:54:12: note:   no known conversion for argument 1 from 'String' to 'uint8_t {aka unsigned char}'

C:\Users\Valentin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\FS\src/FS.h:55:12: note: candidate: virtual size_t fs::File::write(const uint8_t*, size_t)

     size_t write(const uint8_t *buf, size_t size) override;

            ^

C:\Users\Valentin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\FS\src/FS.h:55:12: note:   candidate expects 2 arguments, 1 provided

EKG_data_transimission.cpp:35:34: error: no matching function for call to 'fs::File::write(String&)'

       matrixData.write(dataString);

                                  ^

In file included from C:\Users\Valentin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SD\src/SD.h:17:0,

                 from sketch\EKG_data_transmision.h:3,

                 from sketch\EKG_data_transimission.cpp:2:

C:\Users\Valentin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\FS\src/FS.h:54:12: note: candidate: virtual size_t fs::File::write(uint8_t)

     size_t write(uint8_t) override;

            ^

C:\Users\Valentin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\FS\src/FS.h:54:12: note:   no known conversion for argument 1 from 'String' to 'uint8_t {aka unsigned char}'

C:\Users\Valentin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\FS\src/FS.h:55:12: note: candidate: virtual size_t fs::File::write(const uint8_t*, size_t)

     size_t write(const uint8_t *buf, size_t size) override;

            ^

C:\Users\Valentin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\FS\src/FS.h:55:12: note:   candidate expects 2 arguments, 1 provided

Multiple libraries were found for "WiFi.h"
 Used: C:\Users\Valentin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi
 Not used: C:\Program
Multiple libraries were found for "SD.h"
 Used: C:\Users\Valentin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SD
 Not used: C:\Program
 Not used: C:\Users\Valentin\Documents\Arduino\libraries\SD
Multiple libraries were found for "FS.h"
 Used: C:\Users\Valentin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\FS
Multiple libraries were found for "SPI.h"
 Used: C:\Users\Valentin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SPI
exit status 1
no matching function for call to 'fs::File::write(String&)'

If i try to use the SD library from Arduino instead of the esp32 libary i get this error:

C:\Users\Valentin\Documents\Arduino\libraries\SD\src/utility/Sd2PinMap.h:524:2: error: #error Architecture or board not supported.

 #error Architecture or board not supported.