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?