VMA304 - Can't write to SD card

I ran the code suggested in this forum topic and it works fine (returns SDHC FAT32 2897 MB), but I am still not able to write to an SD Card with Arduino Uno and a VMA304 shield. I am using the following simple test code, and all I get is messages saying “error opening datalog.txt”. Sometimes it will record once, but then it just gives the error forever. Also, when I open up the SD card on my PC after running this code all I see is gibberish and huge 3 MB files that I can’t open. I have formatted the card before running the code, but each time it creates these bogus files. Can you please help me resolve this issue? I have looked all over the web with no success.

#include <SPI.h>
#include <SD.h>
int chipSelect = 10;

void setup() {
Serial.begin(9600);

Serial.print(“Initializing SD card…”);
if (!SD.begin(chipSelect)) {
Serial.println(“Card failed, or not present”);
} else {
Serial.println(“Card initialized.”);
}

Serial.println(“Starting”);
}

void loop() {
String dataString = “data”;

File dataFile = SD.open(“datalog.txt”, FILE_WRITE);
delay(2000);

if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.print("Recording: ");
Serial.println(dataString);
} else {
Serial.println(“error opening datalog.txt”);
}

delay(2000);
}

I don’t think these Velleman VMA304 shields are working correctly. I have spent many hours trying to figure out what the issue was, with no success. I tried multiple SD cards (old and new). I tried 5V and 3.3V. I tried CS pins 10 and 4. The only thing that seemed to make any improvement was adding a delay(2000); after opening the SD card, but it still didn’t resolve the issue. Finally, I bought a Seeed Studio W5500 ethernet shield with a SD card slot, and this works perfectly.

The only thing I see is where it opens datalog.txt
It doesn’t look like it is creating it.
Maybe try making the file on your computer and retry it

That open function should create the file if it doesn’t exist. It works fine with other SD card shields.

Sorry I’m still learning.
Still it’s something to try.