Arduino SD Card Module Data Read from Arduino but not PC

Hi I am intending to use a micro SD Card Module for a datalogger project. I have read a few articles on the forum where level shifters are required by the SD Card Module for better functionality. However, my SD Card is working without it and can read and write data from the Arduino just fine.

When I write data to SD Card from the Arduino, it works. After that if I tried to read the file from Arduino, that also works. However, when I connect the SD Card module to PC and try to open the file that the data was written to, the file does not open.

Post this even if I try to read the file from the Arduino after connecting to the PC, it fails. Somehow connecting the SD card to the PC corrupts the file. I do not understand why this is happening? Is there a fix for this?

SD Card Module being used

Code for writing Data

/*
  SD card datalogger

  This example shows how to log data from three analog sensors
  to an SD card using the SD library.

  The circuit:
   analog sensors on analog ins 0, 1, and 2
   SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 10 (for MKRZero SD: SDCARD_SS_PIN)

  created  24 Nov 2010
  modified 9 Apr 2012
  by Tom Igoe

  This example code is in the public domain.

*/

#include <SPI.h>
#include <SD.h>

const int chipSelect = 10;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  }
  Serial.println("card initialized.");
}

void loop() {
  // make a string for assembling the data to log:
  String dataString = "";

  // read three sensors and append to the string:
  for (int analogPin = 0; analogPin < 3; analogPin++) {
    int sensor = analogRead(analogPin);
    dataString += String(sensor);
    if (analogPin < 2) {
      dataString += ",";
    }
  }

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  }
}

Code for reading the data

/*
  SD card file dump

  This example shows how to read a file from the SD card using the
  SD library and send it over the serial port.

  The circuit:
   SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 10 (for MKRZero SD: SDCARD_SS_PIN)

  created  22 December 2010
  by Limor Fried
  modified 9 Apr 2012
  by Tom Igoe

  This example code is in the public domain.

*/

#include <SPI.h>
#include <SD.h>

const int chipSelect = 10;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card for reading...");

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  }
  Serial.println("card initialized.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datalog.txt");

  // if the file is available, write to it:
  if (dataFile) {
    while (dataFile.available()) {
      Serial.write(dataFile.read());
    }
    dataFile.close();
  }
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  }
}

void loop() {
}

How do we find the datasheet for that blue SD? I only use red ones.
What controller is used?

How is the card formatted?
What do you see on the PC?

Card is formatted to FAT32.

On the PC you can see the file being listed but when you try to open the file you get the message that the file cannot be opened.

Sorry forgot to mention that, the controller is LVC125A

Do you have any lower level file inspection tools?

Can you create a file on the SD card from the PC and if so can you read it back on the PC and on the arduino?

Sorry there is some issue with notepad, when I opened the file with vscode it had therelavant data.

However the arduino fails to read the file after reading the SD card on the PC
Just connecting the SD card to the PC after writing also causes any future reads to fail from SD Card. But if not connected to the PC, reads work perfectly.

Try formatting the card on the arduino using The SdFat library- there is an example for formatting

Tried that, still the same problem

Did you try with another SD card?

Yes, I have tried multiple SD Cards

Did you try reading the file on another PC/Mac? Did you try with a different SD card reader on the PC? Does the SD card has a write protection mode?

Yes

Yes

I am not aware of that, what is that, how to check it?

Looks like this

image

Its a micro SD Card so doesnt have the lock. Also There is no issue with writing. It is an issue with reading after the SD card is connected to the PC. Prior to it reading also works

Ok - looks like something is defective. You need to qualify where it is.

If you only use the card on the PC air works all the time (read / write) and same goes for only Arduino but it does not work when you move from one to the other (both ways). Is that it?

This could sound like a formatting issue but as you tried that…

Do you have access to another SD card module for your arduino?

Yes exactly.

Not at the moment but the SD Card Module does not seem defective to me. I too think it might be a formatting issue, any other software I should try for formatting?

You could try this

No this also did not work. I guess I wont connect the SD Card to the PC, I do not see any other solution

I have many SD modules and different cards and never ran into such an issue.

Do you have an antivirus software running? If so Could you bless the SD card so that it does not quarantine files upon plug-in ?

I agree this seems like a peculiar issue, no antivirus running