SD shield 3.0 do not save well data, here is a program to show, HELP needed plea

Here is the program attached

Here is the serial monitor in jpg file attached

:disappointed_relieved: :disappointed_relieved: :disappointed_relieved: :disappointed_relieved: :disappointed_relieved:
:cold_sweat: :cold_sweat:
:’( :’( :’( :’( :’( :’( :’( :’( :’( :’(

I Tryied with UNO and MEGA,
I already did:

----5v SD SHIELD (more error with 3.3V and I now now :slight_smile: )
—mega pin 10, 53 and pin 4, ALL OF THEM WORK the same
—more delays
—double close.
—change serial speed (all…)
— take off all jumpers from sd shield
— format 16 and 32 bits
— change 4GB for others

Data Still lossing, data and sometimes work fine for a few rows, sometimes Do not
sometimes get “noise” data

see problem.jpg attached

Really need help
Please
Tks

Datalogger-verificando_cada_dato.ino (2.22 KB)

Data Still lossing, data and sometimes work fine for a few rows, sometimes Do not sometimes get "noise" data

I can not confirm your problem, so i don't think your problem is in the software you attached. Please post your code using the code tags.

I have the same ITEAD V 3.0 shield with a 4GB card running in the top standard sized receptor. CS = 4. It is mounted on a UNO running from USB, and the shield is set to 5v. I am using IDE v 1.6.0.

I didn't use sensors, but just use jumper wires to connect A0 to 5v, A1 to 3.3v and A2 to ground. All the readings were accurate and the formatting was never broken.

I think your problem is still possibly low voltage to the shield. Can you confirm the 5v?

Even though i could run your code without problems, I would also suggest that you eliminate the concatenated String objects from your code, and just work with your data and character arrays. The Strings can cause memory leaks and create problems.

Are your glitches related to trying to remove and reinsert the card?

Hi dear cattledog
Here is the code, in tag … ;D

I gues my data goes via serial com and I can see ok at the serial monitor
(I am going to comfirm and I will make a little video in youtube, to show you), But … once I tried to open in the sd, it shows data errors like the ones in the jpg file
so, I am thinking is shoulf be some issue with sd shield
I tried almost everything.
I have no problem with data only with saving and data on sd, the power source is 4.97 and stable.
Yes, sometimes SD is corrupted when I read on pc.
I need csv data in order to get data to excel file from 4 to 6 sensors
tks
best regards
JD

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

const int chipSelect = 4;

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(19200);
  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);
  pinMode(4, 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 = "/start/";

  // 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 += ",";
        }
      }
 
 dataString += "*end*";
  // 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("ARCHIVO.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);
    
    Serial.println("ok saved on SD");
      delay(1000);
   //--------------------------------------------------------------------
   
    Serial.println("LETs read SD..."); 
      delay(1000); 
      Serial.println("");
      Serial.println("DATA ON SD");
    dataFile = SD.open("ARCHIVO.txt");
      if (dataFile) {
          while (dataFile.available()) {
                Serial.write(dataFile.read());
               }
          dataFile.close();
      }
      Serial.println("if want to extract the SD to chech, you got 5 sec-");
      Serial.println("TIENE 5 SEG para sacare la tarjeta y verificar---");
      delay(5000);
      Serial.println("");
      Serial.println("DATA FROM ADC");
  }//if dataFile está
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  }
}

Is this a correct understanding of the problem?

1) The data on the SD card is corrupted when the card is read in a PC and when the card is read by the sketch. The corruption is the same in both cases.

2) The Serial print out of dataString right after the dataFile.close and the card is written is never corrupted?

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");
  }
}

and here

I have run our sketch, using chipSelect = 4 for the itead shield and adding pinMode(10, OUTPUT) in setup to keep the SD library happy with the UNO. I believe that for the mega, you will need pinMode(53,OUTPUT).

Once again, I can run your sketch without the error you see. The serial monitor and the written card look as intended.

What happens if you put a small delay in the program?

I could reproduce some trouble, (but not identical to what you see when you read the file on the computer), when I was using a flakey usb cable, so I would encourage you to investigate issues around the power supply.

It's possible that you have a defective shield(or mega?). Do you have any other arduinos or sd modules to test with?

adding pinMode(10, OUTPUT) in setup to keep the SD library happy with the UNO. I believe that for the mega, you will need pinMode(53,OUTPUT).

The SD library sets this pin, SS, to output mode and high in the begin() call. I wrote the five year old version of SdFat that is used in SD.h.

The only time you need to set a pin to output mode and high is if the pin is chip select for another SPI device. This disables the device so it won't interfere with the SD.

There are many incorrect examples and explanations in the forumn.