NOT ABLE TO WRITE ON TO THE SD CARD

Hey guys, would really appreciate if anyone could help me out how to write to the micro sd card. i thought it was sd card problem so i bought a brand new 8Gb class 4 memory card, but still it says "ERROR OPENING DATALOG.TXT" ...I have even tried the example programme sd data logger but still getting the same problem..the card is getting initialized and the file is also getting created but nothing inside. Because this is also happening with the example SD data logger code i didnt post the code but if necessary ill do post. Been sitting for two days but not getting a solution. Thank for the help in advance. My first time in the forum :P

.I have even tried the example programme sd data logger but still getting the same problem…the card is getting initialized and the file is also getting created but nothing inside

Problems where the file is being created but not written can be do to power issues. I understand that the module takes more current to read/write than create the file. Which module do you have? Is it a 3.3 or 5v module? How is it being powered? If it’s a 5v module, are there level shifters?

Are you running this code? SD library data logger example

/*
  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 4

 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 = 4;

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo 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:
    return;
  }
  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");
  }
}

Hey..it is a 3.3V module and i have even tried by removing all the 5v devices and only powering this one from arduino then also it is not writing ...Yeah ...THAT IS THE CODE ...IS THERE ANYTHING I HAVE TO CHANGE OTHER THAN THE CHIP SELECT ?

IS THERE ANYTHING I HAVE TO CHANGE OTHER THAN THE CHIP SELECT ?

No. That code works if you have the correct chip select. With the wrong chip select for your module, you will get the "Card failed, or not present" error. You said that you had the "error opening datalog.txt" error.

Can you read the card with your computer and see the file present? If you delete the file, is it created again?

You appear to have a very specific problem of file created but not written.

.it is a 3.3V module and i have even tried by removing all the 5v devices and only powering this one from arduino

What do you mean by this? are you powering the module from the 3.3v pin on the Arduino? This pin can only supply 50ma and is not enough for an SD module. You will need a separate 3.3v regulator to power the module, and you will need to deal with the spi level shifting issue if you are using a 5v arduino.

It may be easier to buy a 5v module with built in level shifters. I've successfully used the Catalex micro SD module. It has built in level shifter, and it's pretty inexpensive from ebay. Stay away from modules which have a resistor network for level shifting instead of a chip.

Hey really sorry for the late reply ..yeah i have still not got a solution as in havent read your post completely yet but thought of answering it asap because i am late. Yeah i have been powering it from 3.3v arduino itself and apprently i dont see any level shifters or resistors in this module . So i think that is the problem ...could you please give me an hour ill try troubleshooting the problem with your answer and if its done ill make sure i keep this updated ! :D Sorry again .

hey i found that current supply was the problem just as you said ..now how do i supply proper current to it without burning it ?

For powering the SD module I would use a linear regulator, step down power supply module like this one http://www.ebay.com/itm/DC-5V-to-3-3V-Step-Down-Power-Supply-Module-AMS1117-3-3-LDO-800MA-/271636529896?pt=LH_DefaultDomain_0&hash=item3f3ecc82e8

The level shifting for the spi is referenced herehttp://forum.arduino.cc/index.php?topic=99169.0 Many people have used the 74LVC245 https://www.adafruit.com/products/735

As previously suggested, you can buy a 5v sd module with built in step down supply and level shifters like this one http://www.ebay.com/itm/Micro-SD-Storage-Board-Mciro-SD-TF-Card-Memory-Shield-Module-SPI-For-Arduino-EC-/221744960646?pt=LH_DefaultDomain_0&hash=item33a1079486

If it were me, I'd by the new module which integrates the power supply and level shifting.