Arduino mega and SD do not save well in SD :(

Please help needed, I spend tree days trying to guess why the arduino mega with SD shield 3.0
do not save well on sd, but it does well on serial port in my serial monitor looks

Initializing SD card…card initialized.
///1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,***
///1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,***
///1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,***
///1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,***
///1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,***
///1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,***
///1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,***
///1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,***

but in SD Looks this way :o ; see attach pic :’(
or here in text
///1,1,1,0,0,0,0,0,0,0,0,0,0,1,0,***
///1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,***
///1,1,1,0,0,0,0,0,0,0,0,0,0,1,0,***
///1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,***
///1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,***
///1,1,1,0,0,0,0,0,0,0,0,0,0,1,0,***
///1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,***
,0,0,0,0,1,1,***
///1,1,1,0,0,0,0,0,0///1,1,1,0,0,0,0,0,0,0,0,0,0,1,0,***
68,512,514,520
50///1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,***
///1,1,1,0,0,0,0,0,0///1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,***
6,347,397,45,60,62///1,1,1,0,0,0,0,0,0///1,1,1,0,0,0,0,0,0,0,0,0,0,1,0,***
///1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,***
///1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,***

please help

and this is the program

Datalogger-problem.ino (2.09 KB)

Is this the shield? http://imall.iteadstudio.com/development-platform/arduino/shields/im140726001.html

If so, I do not see a logic level converter on that board. Many SD card shields and breakout boards have problems without that converter. I know that page says it is 5 volt capable, but I don't think it is. Most SD cards don't handle 5 volts on the 3.3v inputs.

edit: Is there an IC on the bottom of that shield?

Dear Surferteam, Yes this is my shield, I have setting in 3.3V, and there is a IC on the bottom. I got 3 jumpers conected D11 D12 D13
What do you suggets?
My best regards to you :smiley:

What do you mean you have setting in 3.3V? The Mega is a 5 volt device.

You shouldn't use the jumpers to D11 to D13. Nothing on those pins on a Mega. All SPI data lines are on the ICSP connector.

Sorry, but I do not understand "I am openly secular." secular mean priest or similar? and what is the relationship with our post? :-[

Ok I will try righ now, so another question I got is: How can I removing the sd the safe way in sd logger demo?

It has nothing to do with our discussion. That is my signature for today. It is "Openly Secular Day". I celebrated 4-20. :) I celebrated Earth Day. :) I also celebrate Openly Secular Day (today, 4-23). :)

But the voltage setting I asked you about does have something to do with our discussion. Why is it set to 3.3 volts?

:D tks for teaching this! yes I got in 3.3V because i read that sd card need 3.3 volts and I guess shied take 5 volts form arduino and give 3.3 to sd in order to work well Is this correct?

The 3.3v pin on the Arduinos do not supply enough current to write to a SD card. You should select 5 volts. It does supply enough current to power the voltage regulator on the SD shield.

woow this most be the problem , You right

:) ;) :) ;) :) :D :D :D ;D ;D ;D let me try just now I am very happy :)

oH, no, still missing syncronization
look… :’(

249,242,238
220,216,218
218,212,208
254,259,248
222,217,214
199,196,199
244,249,239
240,242,238
237,238,236
187,180,190
187,181,185
185,181,181
223,226,222
202,196,193
173,170,173
214,217,214
166,161,170
184,186,191
210,211,197
198,197,188
176,176,177
195,191,185
239,245,233
230,230,229
228,227,225
177,170,179
188,189,193
190,192,197
219,220,215
170,164,171
204,205,209
162,153,163
218
218,212,159,157,155
203,208,197
174,170,166
154,151,154
239
240,242,150,150,150
197,203,192
190
187,181,158,153,148
181
146,145,144
222
202,196,193
173,170,173
214,217,214
166,161,170

This is incorrect.

const int chipSelect = 53;

That should be D10 on V3 of that shield.

const int chipSelect = 10;

Ok I will do it, and Try again... :)

i put some /// to begin and *** to end and see...

///131,128,133*** ///180,180,164*** //129,127,128*** ////133,132,131*** //172,170,160*** 1///135,130,128*** —F !( 9 ///128,127,127*** ///161,165,169*** //168,173,177*** 3,170 173,174,171 ////130,123,132*** ///181,184,174*** ///178,180,176*** ///148,141,138*** //180,182,170*** ////130,132,137*** ///181,186,176*** ///130,128,128*** ////171,175,178*** ///179,178,177*** ///180,178,171*** ///128,123,131*** ///140,134,128*** //184,188,177*** ////129,128,127*** ///150,158,158*** ///160,166,170*** /129,127,128*** /////180,181,178*** ///179,175,166*** ///168,164,155*** ///156,152,144*** /128,127,127*** ////128,126,126*** ///179,186,173*** ///143,138,134*** //130,123,132*** ////126,129,136*** //178,180,176*** ////149,153,159*** ///180,180,175*** ///162,155,147*** ///145,139,131*** /////100,97,99*** ////171,175,178*** ///179,178,177*** ///153,154,152*** ///52,38,60*** ** ///140,134,1///41,27,12*** ,177*** ///////0,0,0*** * ///150,158,158*** ///160,///0,0,0*** ///0,0,0*** ///0,0,0***

My bad. The webpage I just found shows the SD slave select is D4 on that model shield. http://wiki.iteadstudio.com/Stackable_SD_Card_shield_V3.0

const int chipSelect = 4;

ok i will do it cs=4

Hi again, In order to make it clear I have this shoth video, I guess, It will be easy way to understand what is happening to me.

Tks again for for help :wink: here es simplified code

#include <SPI.h>
#include <SD.h>

const int chipSelect = 10;
String dataString = "";

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("Initializando 'SD card'...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(chipSelect, OUTPUT);

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Falla SD, o no está presente");
    // don't do anything more:
    return;
  }
  Serial.println("SD Ok.");
}

void loop()
{
  // make a string for assembling the data to log:
  String dataString = "";

  // read three sensors and append to the string:
  for (int I = 1; I <= 10; I++) {
    dataString += String(I);
    if (I < 10) {
      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");
  }
}

I think your hardware has the slave select on D4. Check the datasheet for your board.

juandagali:
ok i will do it cs=4

Then you do this?

// change this
const int chipSelect = 10;
// to this
const int chipSelect = 4;