#include <SD.h>
// Pin numbers for the SD card module
#define SD_CS_PIN 5 // CS pin for SD card module
// File name for testing
#define FILE_NAME "/test.txt" // File path should start with "/"
// Dummy data to be written
#define DUMMY_DATA "This is dummy data for testing."
void setup() {
Serial.begin(9600);
// Initialize SD card
if (!SD.begin(SD_CS_PIN)) {
Serial.println("Initialization failed!");
return;
}
Serial.println("Initialization done.");
// Call the function to write dummy data to SD card
writeDummyData();
}
void loop() {
// Nothing to do in the loop
}
void writeDummyData() {
// Open the file in write mode
File file = SD.open(FILE_NAME, FILE_WRITE);
// Check if the file opened successfully
if (file) {
// Write dummy data to the file
file.println(DUMMY_DATA);
Serial.println("Dummy data written to SD card.");
// Close the file
file.close();
} else {
// If the file failed to open, print an error message
Serial.println("Error opening file.");
}
}