I need to use SD card to read and write on txt files by using portenta h7 and portenta hat carrier, is there any help how to use them ? is there any tutorials on that please?
#include <SD.h>
#include <SPI.h>
File myFile;
char fileName[] = "simple.txt";
const int chipSelect = 10;
char charRead;
char pangram_1[] = "The five boxing wizards jump quickly";
char pangram_2[] = "Pack my box with five dozen liquor jugs";
char pangram_3[] = "The quick brown fox jumps over the lazy dog";
void setup()
{
Serial.begin(115200);
while (!Serial );
Serial.println("Test"); Serial.println("Simple SD Card Demo");
// Initialize SD card
if (!SD.begin()) {
Serial.println("SD card initialization failed!");
while (1);
}
// Set SPI speed
SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
// Other setup code...
}
void loop() {
// Read from a file
File file = SD.open("example.txt", FILE_READ);
if (file) {
while (file.available()) {
Serial.write(file.read());
}
file.close();
} else {
Serial.println("Error opening file for reading!");
}
// Write to a file
File file2 = SD.open("data.txt", FILE_WRITE);
if (file2) {
file2.println("Hello, SD card!");
file2.close();
} else {
Serial.println("Error opening file for writing!");
}
// Other loop code...
}
This code print
SD card initialization failed!
