Using SD card with portenta h7 and portenta hat carrier

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!

Any help please?
:smiling_face_with_tear:

Hi mercala_eng, I am using that "Hat Carrier" and have the SDCard working. I think I started with this example:

C:\Users<USER>\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\4.0.10\libraries\Portenta_SDCARD\examples\TestSDCARD"

See if this works for you?

Thank you now I can use it. My problem now I can not use all the 2MB of the memory of portenta, why?

Hum, interesting, I see the H7 datasheet says there are TWO flash memories: one that is 2MB (section 1.1 Microcontroller) and another that is 16MB (section 1.2 Memory). Not sure why you can't get to the "QSPI Flash" (and only see the internal flash).

BTW, I gave up on the H7 due to other issues, I'm now using the C33 (with my Hat Carrier). You might consider upgrading to this newer design.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.