1

My code initializes, the header (the ID; Value string) for the .csv file gets saved, but the dataString which is the most important part doesnt save to the .csv file.

I get an arraypointer to the start of the array. I dont have much experience with pointers but i dont get any errors.

The best solution would be if i could put everything into the "write matrix to SD"-function. Anyone has an idea? I am just dumbfounded because everything works perfectly without the arraypointer and i dont know what to try.

My 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");
    }


  //Serial.println(ESP.getFreeHeap());
  pinMode(LED_BUILTIN, OUTPUT); // TEST OUTPUT LED PIN

  pinMode(btn_modus.PIN, INPUT_PULLUP); // MODUSAUSWAHL TASTER
  attachInterrupt(btn_modus.PIN, isr, FALLING); // MODUS TASTER hört auf fallende Flanke und führt dann Funktion isr aus
  WiFi.begin(ssid, password); // Verbinde mit WLAN


  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); // initialisiere Zeit variablen
  EKG_state_1.set_state(1);

}

My function that writes the matrix/arraypointer to the SD

bool  EKG_data_transmision::write_matrix_to_SD(unsigned short *array_pointer) // Übertrage , unsigned short id
{

   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)
  {
    //look if data.csv exists

    while(matrix_coloum < 3071)
    {
      if(matrix_coloum == 1024 || matrix_coloum == 2048)
      {
          header = "ID; Value;\n";
          matrixData.println(header);   
      }
      dataString = String(matrix_coloum) + ";" + String(*array_pointer) + "\n"; 
      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;
}

My class with all the inits


class EKG_data_transmision
{
  private:

    String dataString;
    String header;
    unsigned short matrix_coloum = 0;



  public:
    EKG_data_transmision();

    File matrixData;

    //Definiere Funktionen:
    bool write_matrix_to_SD(unsigned short *array_pointer);
    bool delete_matrix_from_SD(unsigned int record);
2
  • How is write_matrix_to_SD() called? From the string String(matrix_coloum) + ";" + String(*array_pointer) + "\n"; you do see the matrix column number but not the value? Is it an empty value or some random invalid value? Commented Nov 28, 2019 at 16:19
  • the write matrix to SD is called from the loop. Like this EKG_data_transmision.write_matrix_to_SD(EKG_recording.array_pointer); If i serial.print the strings i can see them. They just dont get saved to the .csv file like the header with "ID; Value" Commented Nov 29, 2019 at 13:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.