SD card read/write with Arduino

Hello everyone. I m from India and currently doing my final year project.
I m trying to interface an SD card with Arduino atmega8 for datalogging. I dont have any shield for the interface,since it is not affordable for me. and i m following this schematic

www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1206874649/8

I tried the DevicePrint library, File Logger library.

But watever I try , I get only the following error msg "card Failed initialising". Sad

I m using Arduino-0017 IDE in Linux.

Have you read my post: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1206874649/124#124 ?

  • How many different SD-Card have you tested (some card are much more picky than others)
  • i've had good results with two old 16mb sd-card (came with my canon digital camera) and one 256MB Card

Nandhakumar

If dataloging does not require you to access the sd card
data on your pc using a FAT.

If you just want to log data straight to and from the sd card using the arduino.

Then look at:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1259789744/0#0

Hi, i just want to test this uFAT, but i cant find the mmc1.rar from http://groups.google.com/group/micro-hacker

has anyone the files i need ?

btw, heres my idea of an Cardslot:

Its just a mini or micro SD-Cardadapter

To Nnk:

I've had problems initializing a card also, it turned out I had a bad contact between my card reader board and the header it was sitting upon. I soldered everything and it works perfectly now. You might want to verify all the electrical contacts, just to be sure.

Good luck!

Note: I use the very same circuit that you are using, except for 2 additional 100nF and 47uF capacitors between the 3.3V and GND pins next to the card (it probably works without that). I use a 2GB SD San Disk card.

Has anyone used the fat16 library SparkFun mentions?

I went back a couple of pages here but didn't see this mentioned. I am looking for a way to read files off a removable storage device. The files will have some commands. A push of the button on the arduino will cycle through the files/commands. I need to be able to read and write tot eh storage device from windows or mac. I think hooking up microSD and using that library will work.

This is Nnk again .

Thanks to carl47 and Cemath for the response . I tried the way u said in ur posts. But it did not work. I also tried re-building and re-testing the connections too.But still the same.

I am really confused and not clear on how to proceed with SD card interfacing with Arduino . Here I will tell the real need or requirement of my project and the purpose for which I need a SD card interfacing.

My project name is Tran-Duino , the purpose of the project is to track a moving vehicle,say ,a Bus using GPS and display the upcoming or the next stop names in the route by placing a display inside the Bus.

Inorder to store the latitude, longitude and location names , I will be using a SD card. The SD card will contain these information in the form of a textfile with fields separated by commas and one location name per line.

for example A line in the file may hv values like

13.119697 , 80.218537 , kolathur

Now , when the bus moves in the route , I ll get the GPS values from a GPS receiver module about the bus curent location frequently, I ll also fetch the values from the sd card , compare it , if it matches then the location name is sent to the display unit.

All these processing are done using the arduino. Now the work of the SD card is

[must be able to store values when i go to locations and get the GPS positions (for storing purpose) ]
[must be able to read from the card for comparing it with received values from GPS]

So , please tell me your suggestions on how to achieve this task. If it is possible to do this task without a shield for SD card it will be more useful.

Thanks in advance

N.Nandhakumar

Hi,
I'm new to Arduino. Tried to search for micro SD/regular SD card adapter/holder to solder it into PCB without any results. >:( :o Could somebody help me to find where to buy it?
Thanks.

Already found it at SparkFun.com :slight_smile: :wink:

Hello all,

I am relativly new to all of this (I just joined the forum 30 seconds ago), and I was wondering if I could use this to read/write Replicator G files.

I have a makerbot, and I have been trying to find a way to use it without hooking my computer up to it every time I want to print. I have found the serial commands given by the computer to initiate Build form SD, and so I wanted to set up my arduino to take an SD card with the file on it, transmit that file to my Makerbot, and then send the Build from SD command. Does this sound feasible to you all?

hi friends i am doing an data logger project i'am using the below code... when i interact with harware i could'nt inizilaise the card this is ma error could any one help me out....

#include <Spi.h>
#include <sd-reader_config.h>
#include <sd_raw.h>
#include <sd_raw_config.h>

int print_disk_info();
int sample();
int readDisk();

byte incomingByte;
void printWelcome();
long int address;
byte tempBytes[2];

void setup()
{

Serial.begin(115200);
delay(1000);

printWelcome();
if(!sd_raw_init())
{
Serial.println("MMC/SD initialization failed");
}
print_disk_info();
//sd_raw_init();
}

void loop()
{
int i;

if(Serial.available()>0)
{
incomingByte=Serial.read();

switch(incomingByte)
{
case 114:
readDisk();
break;
case 115:
sample();
break;
default:
break;
}
}
}

int sample()
{
int i,j;
int temp;
byte low;
byte high;
byte inByte;

Serial.println();
Serial.println();
Serial.println("Sampling..");
for(i=0;i<20;i=i+2)
{
if(Serial.available()>0)
{
inByte=Serial.read();
if(inByte==113) return 0;
}
temp=analogRead(0);
Serial.print(temp,DEC);
Serial.print(" ");

//Convert int to 2 bytes
low=temp&0xFF;
high=temp>>8;
// Serial.print(temp,DEC);
//Serial.print(low,DEC);
//Serial.print(high,DEC);

tempBytes[0]=low;
tempBytes[1]=high;

if(!sd_raw_write(i,tempBytes,2))
{
Serial.print("Write error");
}
//sd_raw_sync();
delay(1000);

Serial.println();

}

return 1;
}

int readDisk()
{
byte low;
byte high;
byte info[2];
int i;
int result;
Serial.println();
for(i=0;i<50;i=i+2)
{
sd_raw_read(i,info,2);

//Serial.print(info[0],DEC);
//Serial.print(" ");
//Serial.print(info[1],DEC);
low=info[0];
high=info[1];
result=high<<8;
//result<<8;
Serial.print(" ");
Serial.print(result+low,DEC);
Serial.print(" ");
}

}

void printWelcome()
{
Serial.println("------------------------");
Serial.println("Data sampling system");
Serial.println("send r to read disk");
Serial.println("send s to start sampling");
Serial.println("send q to stop sampling");
Serial.println("Ready.....");
Serial.println("-------------------------");
}

int print_disk_info()
{

struct sd_raw_info disk_info;
if(!sd_raw_get_info(&disk_info))
{
return 0;
}

Serial.println();
Serial.print("rev: ");
Serial.print(disk_info.revision,HEX);
Serial.println();
Serial.print("serial: 0x");
Serial.print(disk_info.serial,HEX);
Serial.println();
Serial.print("date: ");
Serial.print(disk_info.manufacturing_month,DEC);
Serial.println();
Serial.print(disk_info.manufacturing_year,DEC);
Serial.println();
Serial.print("size: ");
Serial.print(disk_info.capacity,DEC);
Serial.println();
Serial.print("copy: ");
Serial.print(disk_info.flag_copy,DEC);
Serial.println();
Serial.print("wr.pr.: ");
Serial.print(disk_info.flag_write_protect_temp,DEC);
Serial.print('/');
Serial.print(disk_info.flag_write_protect,DEC);
Serial.println();
Serial.print("format: ");
Serial.print(disk_info.format,DEC);
Serial.println();
Serial.print("free: ");

return 1;
}

Hi all, I was tryning without success to install a Libelium Sd Module on a Arduino Mega (ATMEGA1280) :'(. I've searched on the net for some information; everyone say that this module doesn't work with Arduino Mega and nobody has a solution :o.
So anyone tried to use this circuit and this library with Arduino Mega?
Thank you for help.

anyone make the pcb of this???

tnks

if anyone want the PCB file, send me a PM, its make on eagle software

:wink:

Hello All!
I'm am new to the Sd card phase. My question is which of the libraries and setups do you recommend for logging gps data strings to an sd card. Yes I know about Ladyadas shield and code but I am overwhelmed. I bought the sparkfun arduino sd shield without realizing it was a failed product. Through the forums I found how to wire it up and got the sparkfun code working but I'm still having small issues. So i'm coming here to find out where i should start.

Jon

I am looking for a library that solves my needs or information on how to do it. I have a project that will use asynclab's wishield and a microsd card. All I need to do is read files from an SD card. There can be any number of files on the SD card so I think uFAT is out. I can do what I want with sdlaftlib after I make my own read function. I need to be able to read a byte at a specific position in a file. The files will be created on a PC.

When I include both the wishield and sdfatlib they don't leave much memory left for the program. In fact, right now my program is 1.3k over the limit of a 368 arduino. I went through the sdfatlib and took out everything that deals with writing to files as I don't need that. I also went through my code and made sure I didn't allocate memory when I didn't need to. I got it down to 1k over the limit.

Since I just need to read from a microsd I was wondering if there is a library that takes up a smaller footprint that will do that.

I was not sucessfull in write/read SD Card using this schematics and library. Could someone give a help? I'm using an Kingston 1GB SD Card, and an Freeduino v1.0. I had connected the SD Card like this picture, but I was not sucessful.

someone might use it? (the circuit and the lib)

tnks

Just to say thanks. I got a seeeduino a couple of days ago, tried using a card holder hacked from a broken camera and couldn't get the DevicePrintDemo to work (mmc::initialize() returned 3). All the connections tested ok with a multimeter on beep but I noticed a (2k) short on one of the connections. So I took the advice elsewhere in this or parallel thread and soldered wires directly to a micro-adapter, set the + to 3v3 and it just worked - no resistors needed!!

The adapter seemed to have pin 3 connected to pin 6 internally so that saved one of the connections.

Hi,
as soon as I try and run this example I receive the following error:
My Documents\arduino-0018\libraries\SDcard\arduino sd card example.cpp:161: error: 'DEC' was not declared in this scope

This makes no sense to me as "DEC" seems to be used in the correct way throughout the example. Can anyone help?

Many thanks!

NOTE: I'm using Arduino_0018 and the "libraries" folder is not within the "hardware" folder, does this matter?

Hi to all,

This is N.Nandhakumar again. After a lot of struggle I have purchased the EM-406a GPS module, Adafruit GPS shield V1.1, Freeduino ATMega328 for my project.
I soldered the GPS shield , interfaced it with the Arduino and the GPS logged data successfully into the SD card.
Now, I have a problem. I want to read back the logged data from the log file stored in SD card for doing some processing, comparison with the data. I made use of SdFat library's SdFatRead example code and I was able to read back the file contents .

/*
 * This sketch reads and prints the file
 * PRINT00.TXT created by SdFatPrint.pde or
 * WRITE00.TXT created by SdFatWrite.pde
 */
#include <SdFat.h>
#include <SdFatUtil.h>

Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;

// store error strings in flash to save RAM
#define error(s) error_P(PSTR(s))
void error_P(const char *str)
{
  PgmPrint("error: ");
  SerialPrintln_P(str);
  if (card.errorCode()) {
    PgmPrint("SD error: ");
    Serial.print(card.errorCode(), HEX);
    Serial.print(',');
    Serial.println(card.errorData(), HEX);
  }
  while(1);
}
void setup(void)
{
  Serial.begin(9600);
  Serial.println();
  Serial.println("type any character to start");
  while (!Serial.available());
  Serial.println();
  
  // initialize the SD card
  if (!card.init()) error("card.init");
  
  // initialize a FAT volume
  if (!volume.init(card)) error("volume.init");
  
  // open the root directory
  if (!root.openRoot(volume)) error("openRoot");
  
  // open a file
  if (file.open(root, "PRINT00.TXT", O_READ)) {
    Serial.println("Opened PRINT00.TXT");
  }
  else if (file.open(root, "WRITE00.TXT", O_READ)) {
    Serial.println("Opened WRITE00.TXT");    
  }
  else{
    error("file.open");
  }
  Serial.println();
  
  // copy file to serial port
  int16_t n;
  uint8_t buf[7];// nothing special about 7, just a lucky number.
  while ((n = file.read(buf, sizeof(buf))) > 0) {
    for (uint8_t i = 0; i < n; i++) Serial.print(buf[i]);
  }
  /* easier way
  int16_t c;
  while ((c = file.read()) > 0) Serial.print((char)c);
  */
  Serial.println("\nDone");
}

void loop(void) {}

The problem is that the file contents are read in raw format using uint8_t [ I googled about this datatype . But I am not clear with this datatype and how it works :frowning: ] . It will be more useful If I could read the data from the file in char or string format .

I searched for a better way to convert the uint8_t data to char datatype. But I get only junk characters.

I need the forum's help to solve this issue. Please give your suggestions on this.
Please help me out. Waiting for your valuable suggestions.

My works on the project at : http://walkingwithtux.wordpress.com/2010/05/02/tran-duino-under-progress/

Regards

N.Nandhakumar :slight_smile: