sending mpu6050 serial data to sd card

I am trying to send x axis and y axis and also realtime date time data to an sd card reader.

The code for the sd card is well-known. it is:

/*
 *  Arduino SD Card Tutorial Example
 *  
 *  by Dejan Nedelkovski, www.HowToMechatronics.com
 */
#include <SD.h>
#include <SPI.h>
File myFile;
int pinCS = 10; // Pin 10 on Arduino Uno
void setup() {
    
  Serial.begin(9600);
  pinMode(pinCS, OUTPUT);
  
  // SD Card Initialization
  if (SD.begin())
  {
    Serial.println("SD card is ready to use.");
  } else
  {
    Serial.println("SD card initialization failed");
    return;
  }
  
  // Create/Open file 
  myFile = SD.open("test.txt", FILE_WRITE);
  
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.println("Writing to file...");
    // Write to file
    myFile.println("Testing text 1, 2 ,3...");
    myFile.close(); // close the file
    Serial.println("Done.");
  }
  // if the file didn't open, print an error:
  else {
    Serial.println("error opening test.txt");
  }
  // Reading the file
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("Read:");
    // Reading the whole file
    while (myFile.available()) {
      Serial.write(myFile.read());
   }
    myFile.close();
  }
  else {
    Serial.println("error opening test.txt");
  }
  
}
void loop() {
  // empty
}

Using just this code, you get the print out "Testing text: 1, 2, 3" etc. I don't want that, I want the continuous lines of rtc, X deg and y deg from my MPU to be written to the sd card. How would I modify this code to tell the mpu6050 / the serial data print from the mpu6050...to be written continuously to the sd card reader?

Can you read from the 6050 and print the readings on the Serial monitor ?

Note how similar

myFile.println("Testing text 1, 2 ,3...");

is to

Serial.println("Testing text 1, 2 ,3...");

I have no problem reading the serial data from the mpu6050 to the serial monitor. So are you saying that I need to write something like:

not this:

serial.print (xdeg);
serial.print (ydeg);

but rather:

serial.write (xdeg);
serial.write (ydeg);

something like that?

You need to write to the file, not to Serial

You first need to open the file. The SD example shows you how to do this. Then when you have data to write to the SD in a variable you use

myFile.println(nameOfVariable);

You may want to use myFile.print() and/or print a data divider such as a comma depending on your requirements.

Don't forget to close the file when done. Again the SD example shows you how

thank you. I will try that...makes complete sense. I am getting used to the syntax and concepts. I haven't programmed since college 35 years ago!