Pages: [1]   Go Down
Author Topic: SD card with examples not working  (Read 654 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I’ve got a new micro SD 4GB class 4 card and adapter for an arduino SD card module. When running the datalogger arduino example, the serial monitor shows;

Initializing SD card...card initialized.
427,375,348
error opening datalog.txt
error opening datalog.txt


When running the arduino example   cardinfo  serial monitor shows:

Initializing SD card...Wiring is correct and a card is present.

Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3952607232
Volume size (Kbytes): 3859968
Volume size (Mbytes): 3769

Files found on the card (name, date and size in bytes):
DATALOG.TXT   2000-01-01 01:00:00 0



Initializing SD card...Wiring is correct and a card is present.
Card type: SDHC

Volume type is FAT16

Volume size (bytes): 3960733696
Volume size (Kbytes): 3867904
Volume size (Mbytes): 3777

Files found on the card (name, date and size in bytes):
DATALOG.TXT   2000-01-01 01:00:00 0


I think is something wrong with the microSD and adapter to work but not sure. Am I missing something? If is a problem with the SD card, which one would you recommend?
Thank you,
Javi

Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 548
Posts: 46031
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I’ve got a new micro SD 4GB class 4 card and adapter for an arduino SD card module.
The Arduino doesn't have an SD card module. Perhaps you added one. If that is the case, some information on which one and how you wired it would be useful.

Your code, too.
Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 52
Posts: 1990
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It seems your card is ok, but you do not close the file properly, therefore the 0 size there..
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, I did it wrong and did another post saying that I have also tried with a 2GB SD card, mi mistake.

The 2GB SD card isn't working either.

The SD card module I am using is:

http://www.dhgate.com/product/dhgate/124326680.html?utm_source=pla&utm_medium=GMC&utm_campaign=seepuelectronic&utm_term=124326680&f=bm|124326680|104007-ComputerComponents|GMC|Adwords|pla|seepuelectronic|GB|104007014-OtherComputerComponents|c||&gclid=CKeOh_eLy7kCFUXJtAodcB0Amg

When running the cardinfo example says that wiring is correct. The wiring is as follows:

ARDUINO              SD CARD MODULE

5V-----------------5V
D4----------------CS
D11--------------MOSI
D13--------------SCK
D12-------------MISO
GND------------GND


What can I do to close the file properly?

The code used is the arduino example datalogger, this is:

/*
  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 <SD.h>

// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
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...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
 
  // 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");
  }
  delay(4000);
}
Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 52
Posts: 1990
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It does not work on my system either (my system works fine with SdFat lib).. Card Init failed.. CS = SS = 10
UECIDE, 1.0.5, fresh formatted 4gb fat32 card.
PS: go with SdFat library, similar demos there as well..
« Last Edit: September 14, 2013, 10:24:34 am by pito » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I too am having difficulty with SD library examples.  I can use CARDINFO with out difficulty.  Then i use the DATAlogger Example, Which seems to capture appropriate lines of data, however previous files on SD are scrambled. The Datalog.txt file is present on SD. All other files on SD are un-readable.  Kinda a bummer. No modifications are made to either example.
Logged

Pages: [1]   Go Up
Jump to: