7

I'm new to Arduino and electronics. I want to make a project including SD data-logger, but I had a problem. I would appreciate if someone show me where I made a mistake.

Firstly, circuit was set up as in picture:

Hardware setup

I am using 8 Gb micro SDHC card with SD adapter. I formatted in FAT32. I can play audio files which are in appropriate format and read and the print contents of text files.

But when I want to create a new file, strange file is obtained in SD card as in pic:

Directory listing

So I reformat SD card. the code that is used while creating file is as this;

// open a new file and immediately close it:
Serial.println("Creating example.txt...");
myFile = SD.open("example.txt", FILE_WRITE);
myFile.close();

Somewhere I read SDHC card with more than 2 Gb capacity is not supported in Arduino and I bought 2 Gb SD micro with SD adaptor.

But in this case aurduino does not detect SD card. please someone help me.

7
  • 1
    Please post all of your code and format it right. (Also, if you are talking about yourself (I am, I will and so on) then capitalize the "I").
    – Avamander
    Commented Sep 22, 2015 at 20:35
  • I formatted with SD formatter 4.0 but did not make difference. Probably, aurduino doesn't support some SD cards, this problem looks like some cd driver or writer doesn't detect some compact discs. I have two micro sd one of them 8 gb micro sdhc - sandisk - this is supported reading but not supported for writing other one 2gb microsd- noname - this is not supported for reading and writing is there someone tell me mark and type of sd card to be able read and write successfully.
    – dursung
    Commented Sep 23, 2015 at 16:07
  • arduino.cc/en/Tutorial/Files this is code I work on
    – dursung
    Commented Sep 23, 2015 at 16:10
  • It sounds like you tried using a card that is too big, so it didn't work. Then you bought some cheap 2GB cards that either don't work full-stop or don't have SPI support. Bite the bullet and buy cards from a reputable retailer.
    – Majenko
    Commented Sep 23, 2015 at 16:27
  • 1
    @dursung - SDHC support mostly depends on software, so that module won't help you. Commented Nov 15, 2015 at 5:17

2 Answers 2

1

I've had similar issues with large (> 1Gb) SD cards, I've had various different problems with different cards, some things that helped me debugging the problem:

  • make sure your wires are the same length and try to use short wires
  • make sure your power supply is sufficient, sd card readers can draw up to 150mA
  • format the card in either FAT16 or FAT32 and never use "quick erase", try to use official tools (like https://www.sdcard.org/downloads/formatter_4/index.html)
  • make sure if you're the correct BAUD rate (9600) to talk to your card
  • filename support is pretty old so keep them short and don't use spaces or special characters
  • make sure the SD card is not in "write lock" mode, there's a small switch on the side of some SD cards that can prohibit writing (but will allow reading)
3
  • 1
    Note that write protection on a SD card is dependent on the socket and host honoring it; turning it on does nothing to actually prevent the host from writing successfully to the card. Commented Oct 16, 2015 at 3:31
  • 1
    Also, SD uses SPI, not UART, so "baud rate" is irrelevant, only the serial clock speed. Commented Oct 16, 2015 at 3:32
  • I've seen this exact issue before being caused by power supply brownout. There is a current spike during writes, if the voltage drops too much you get this effect. Slower/smaller cards are less prone to it because they have a smaller spike. Improving the power supply to the card fixed it.
    – Andrew
    Commented Dec 6, 2016 at 15:28
1

I have faced this problem. Try

  • If you are using multiple devices with SPI communication ignore the others by keeping their slave select HIGH
  • Never forget file.close()
1
  • If file.close() is so important wrap the file access in a class so close is always called in the destructor. Commented May 30, 2017 at 7:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.