SD card - CardInfo works, but "error opening datalog.txt"

Hello,
Some annoying problem with SD card data logging.
I use the full-size SD card reader with 2 pins lines: https://aliexpress.ru/item/1889689616.html (first model) with 100% working full-size SanDisk SD-card 4Gb FAT32 with disabled “write lock switch”.
Unfortunatelly on data logging Arduino all the time return only an error: “error opening datalog.txt”
When I trying to use ArduinoIDE - Samples - SD - CardInfo - sketch works correctly and return full SD card info and show an epmty datalog.txt file.
When I trying to use ArduinoIDE - Samples - SD - Datalogger - sketch does not work correctly and return only an error “error opening datalog.txt”.
Why it can happen? How to resolve this problem?

The first step is to carefully check your wiring.

What Arduino are you using? Is it a 5V Arduino?

It appears the SD card adapter you are using is intended for 3.3V Arduinos such as the 3.3V 8MHz Pro Mini. There is no translation of the 5V Arduino CLK, CS and MOSI lines down to the 3.3V pins of the SD card. But I can't be sure that is the cause of your problems. There is a fix for that module that requires soldering in three diodes and cutting three traces. You might take a look and see if the pictures are the same as your module.

ShermanP
Thank you very much for a such fast and comprehensive answer! +rep! But...

I'm using Arduino Nano 3 (single-side board). It's a 5V Arduino and I've power SD-card-reader via 5V VCC line. I sure that this SD-card-reader module have a 5V power support.

I've connect SD-card-reader with next wiring and already tried to shake it and reconnect it:
GND -> GND
3V3 -> not connected
5V -> 5V
CS -> 10 (just to have all used pins near 10-13)
MOSI -> 11
SCK -> 13
MISO -> 12
GND -> not connected

Also I already try to:

  • for CS line use pin 4 insted of pin 10;
  • connect via both lines at SD-card-reader 1-15 and 2-16 pins;
  • another sample of a such SD-card-reader;
    with the same error result.

Can you specify - which pin can have bad wiring or soldering to act like this - CardInfo works perfectly, new file creates, but data don't writes?

The CS pin should be whatever is specified in the example.

I don't believe that module properly supports 3.3V. It has a 3.3V regulator that provides that voltage to the SD card, but CS, CLK and MOSI coming out of the Arduino are at 5V, and the module does not convert them to 3.3V.

The CardInfo example in the SD.h library doesn't have any file writing function. Which library are you using?

If any line was not connected properly, I don't think any portion of CardInfo would work. And if it can create a file, it should also be able to write to the file. So I don't know what the problem is. Have you measured the voltage on the module's 3.3V pin when writing to the card? If it sags, perhaps your power supply is inadequate. But I'm just guessing. If the module is not the problem, I don't know what else is wrong.

I use the standard ArduinoIDE - Samples - SD - libraries and samples.

To exclude possible cause of a bad wiring I've make some more tests:
A) Just run CardInfo sketch (which works good previously) with disconnecting one-by-one pins - at ALL conditions CardInfo just stop to work except disconnecting both GND pins. Thus it seems that wiring was good from the beginning.
B) Also I've try to connect to SD-card-reader lines individually 1-15 or 2-16; and to both 1-15 and 2-16 at once.
C) Also I've try 3 different types of wiring.
D) I've try CS 10 and 4 pins.
E) To exclude problems with power - I've try to use only 5V, only 3V3, both.
F) Also I've try different variations of GND and power
G) To exclude problems with SD card - I've test write-read at PC - SD-card works good.
Results the same - CardInfo sketch always working, DataLogger always makes an error on data writing to file.

At all those attempts only 1 time some data was written to SD card but writing are breaks after about 1sec with totally data written just about 3600bytes, at condition when no GND pins was connected. Later I can't repeat it.

Thus now I have 2 such SD-card-readers which return full card info, full files list, can create and delete files at card... but... can't write data to the file. :((

I posted originally about the SD module not being designed correctly to work with a 5V Arduino. Beyond that, I don't have an explanation for what you are seeing. All the lines have to be working properly even to run CardInfo.

But let me just ask again about power. How are you powering your Arduino? Do you power the SD module from the 5V pin of the Arduino?

The SD card's current draw is at a maximum when sectors are being erased and data is being written. If you only have problems when those are occurring, that suggests it might be a power problem.

I can only repeat:
E) To exclude problems with power - I've try to power SD-card-reader module from Arduino Nano power PINs with: only 5V, only 3V3, both 5V+3V3.

Don't know how to test if there are not enough power from Arduino?

How are you powering the Nano? Is it connected to USB, or are you using the Vin pin? If USB, then power is probably not the problem.

The SD module should be powered at its 5V pin unless you have a separate regulated 3.3V supply. The Nano's 3.3V pin will not provide enough current to power the SD card at the module's 3.3V pin.

The test for power problems would be to see if there is any reduced voltage, or sag, on the module's 5V pin when writing to the card. A scope provides the best view of that, but you might be able to see it with a multimeter.

Arduino Nano powered via standard USB 5V.

I already try to power SD-card-reader with 5V+3V3 at the same time with the same result. Other modules and sensors and display works good, also I try to disconnect them.

Maybe will try to test 5V with multi-meter. Thanks.

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