Barcode not logged in SD card UART
I found the way:
#include &lt;SoftwareSerial.h&gt;
#include &lt;SPI.h&gt;
#include &lt;SD.h&gt;
#include &lt;string.h&gt;
#include &lt;Wire.h&gt;
#include &quot;RTClib.h&quot;
#define rxPin 2
#define txPin 3
RTC_DS1307 RTC;
SoftwareSerial mySerial = SoftwareSerial (rxPin, txPin);
File main_folder; // initialize folder for saving
File dataFile; // initialize sd file
const int chipSelect = 10; // CS pin on sd card module
int prev_file_indx = 0; // used for file naming
String fileName = &quot;000&quot;;
char timestamp[30];


// how much serial data we expect before a newline
const unsigned int MAX_INPUT = 50;


void dateTime(uint16_t* date, uint16_t* time) {
  DateTime now = RTC.now();
  sprintf(timestamp, &quot;%02d:%02d:%02d %2d/%2d/%2d \n&quot;, now.hour(), now.minute(), now.second(), now.month(), now.day(), now.year() - 2000);
  // return date using FAT_DATE macro to format fields
  *date = FAT_DATE(now.year(), now.month(), now.day());

  // return time using FAT_TIME macro to format fields
  *time = FAT_TIME(now.hour(), now.minute(), now.second());
}


void setup ()
{
  Serial.begin (115200);
  mySerial.begin (115200);
  Wire.begin();       
  if (!RTC.begin()) {
    return;
  }

  pinMode(10, OUTPUT);
  if (!SD.begin(chipSelect)) {
      return;
    }
    
    main_folder = SD.open(&quot;/&quot;);
    fileName = sd_saver(main_folder);
 // end of setup
    delay(1500);
    dataFile = SD.open(&quot;DATA&quot;+fileName+&quot;.csv&quot;,FILE_WRITE);
  if (dataFile) {
    Serial.println(dataFile);
    Serial.println(&quot;Writing Headers...&quot;);
    dataFile.println(&quot;FA,  Zeit&quot;);
    dataFile.close(); // close the file
    Serial.println(&quot;File closed, Headers written&quot;);
  }
 }

void process_data (const char * data)
// here to process incoming serial data after a terminator received
{ delay(500);
    SdFile::dateTimeCallback(dateTime);  
  DateTime now = RTC.now();
  sprintf(timestamp, &quot;%02d:%02d:%02d %2d/%2d/%2d \n&quot;, now.hour(), now.minute(), now.second(), now.month(), now.day(), now.year() - 2000);
     dataFile = SD.open(&quot;DATA&quot;+fileName+&quot;.csv&quot;,FILE_WRITE);
  if (dataFile) {
    Serial.println(&quot;Writing to file...&quot;);
    dataFile.print (data);
    dataFile.print(&quot;,&quot;);
    dataFile.println (timestamp);
    Serial.println (data);
    Serial.println (timestamp);
    Serial.println(&quot;Done.&quot;);
    dataFile.close();
  } else {
    Serial.println(&quot;error opening test.txt&quot;);
    delay(1000);
  }

}



void processIncomingByte (const byte inByte)
{
  static char input_line [MAX_INPUT];
  static unsigned int input_pos = 0;

  switch (inByte)
  {

    case '\n':   // end of text
      input_line [input_pos] = 0;  // terminating null byte

      // terminator reached! process input_line here ...
      process_data (input_line);

      // reset buffer for next time
      input_pos = 0;
      break;

    case '\r':   // discard carriage return
      break;

    default:
      // keep adding if not full ... allow for terminating null byte
      if (input_pos &lt; (MAX_INPUT - 1))
        input_line [input_pos++] = inByte;
      break;

  }  // end of switch

} // end of processIncomingByte

void loop() {
  delay(2000);


  // if serial data available, process it
  while (mySerial.available () &gt; 0)
  processIncomingByte (mySerial.read ());
  mySerial.write(processIncomingByte);
  delay(1000);

  // do other stuff here like testing digital input (button presses) ...

}  // end of loop



String sd_saver(File dir){
  while(true){
    // iterate all files to ensure no overwrites
    File entry = dir.openNextFile();
    if (!entry){
      break;
    }
    // naming routine
    String entry_name = entry.name();
    if ((entry_name.substring(4,7)).toInt()&gt;=prev_file_indx){
      prev_file_indx = (entry_name.substring(4,7)).toInt()+1;
      if (prev_file_indx&gt;=100){
        fileName = String(prev_file_indx);
      } else if (prev_file_indx&gt;=10){
        fileName = &quot;0&quot;+String(prev_file_indx);
      } else{
        fileName = &quot;00&quot;+String(prev_file_indx);
      }
    }
    entry.close();
  }
  return fileName;
}