#include <SPI.h>
#include <SD.h>
// Define the new pin assignments
#define MOSI_PIN 23
#define MISO_PIN 19
#define SCK_PIN 18
#define CS_PIN 5
// DO (MISO) to GPIO 19
// GND to GND
// SCK to GPIO 18
// VCC to 3.3V
// DI (MOSI) to GPIO 23
// CS to GPIO 5
void setup() {
Serial.begin(115200);
// Initialize the SPI bus with the new pin assignments
SPI.begin(SCK_PIN, MISO_PIN, MOSI_PIN, CS_PIN);
// Initialize SD card
if (!SD.begin(CS_PIN))
{
Serial.println("Card failed, or not present");
return;
}
Serial.println("Card initialized.");
// Open a file for writing
File dataFile = SD.open("/example.txt", FILE_WRITE);
if (dataFile)
{
dataFile.println("Hello, world!");
dataFile.close();
Serial.println("Data written to file.");
}
else
{
Serial.println("Failed to open file for writing.");
}
// Open a file for reading
dataFile = SD.open("/example.txt");
if (dataFile)
{
Serial.println("Reading from file:");
while (dataFile.available())
{
Serial.write(dataFile.read());
}
dataFile.close();
}
else
{
Serial.println("Failed to open file for reading.");
}
}
void loop()
{
// Nothing to do here
}