Problems saving data to the sd of a depth transducer

I have a transducer CruzPro att120a that provides depths , I would like to get save data into a shield for arduino sd that I have. I give the code for depth look at the serial monitor.

byte entrada=0;
 int ent=3;
 int sal=2;

 void setup(){
 Serial.begin(9600);
 Serial1.begin(4800);

 pinMode(ent,INPUT);
 pinMode(sal,OUTPUT);
 }
 void loop(){

 if(digitalRead(ent)==LOW){
 digitalWrite(sal,HIGH);}

 else{
 digitalWrite(sal,LOW);}

 while(Serial1.available()){
 entrada=Serial1.read();
 Serial.write(entrada);}
 }

I am using the arduino mega 2560 and the seeedstudio sd card shield V4.0, i,ve tried all sd examples and don't store anything.
Thanks for your help and sorry for my english.

i,ve tried all sd examples and don't store anything.

And, so, you don't intend to show us how you tried to adapt them to your code, or tell us what the (observed) failure mode was for each example.

Well, OK. Good luck.

i have tested this sketch and does not work only initialize the card.

#include <SD.h>

byte inByte=0;
int ent=3;
int sal=2;
#define ledPin 13





// 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 = 10;


void setup(){
  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.");
  Serial1.begin(4800);

  pinMode(ent,INPUT);
  pinMode(sal,OUTPUT);
  
  
}

void loop(){
  
  if(digitalRead(ent)==LOW){
  digitalWrite(sal,HIGH);}

  else{
  digitalWrite(sal,LOW);}




File dataFile = SD.open("datalog.txt", FILE_WRITE);
  while (Serial1.available()) {    
    inByte = Serial1.read(); 
    Serial.write(inByte);}
    

    
   if (dataFile) {
   dataFile.write(inByte);
   dataFile.close();}
   
   else {
        Serial.println("error opening datalog.txt");
        }
}

I have also tried this sketch that I found herehttp://forums.adafruit.com/viewtopic.php?f=22&t=28817&p=146494#p146494

#include <SD.h>
#include <SoftwareSerial.h>
//byte inByte=0;
int ent=3;
int sal=2;
#define ledPin 13





// 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 = 10;


void setup(){
  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.");
  Serial1.begin(4800);

  pinMode(ent,INPUT);
  pinMode(sal,OUTPUT);
  
  
}

String line = "";

void loop(){
  
  if(digitalRead(ent)==LOW){
  digitalWrite(sal,HIGH);}

  else{
  digitalWrite(sal,LOW);}





File dataFile = SD.open("datalog.txt", FILE_WRITE);

  if (Serial1.available()) {
    char inByte = Serial1.read(); 
    switch (inByte) {
      case '\n':
        Serial.println(line);     //print complete line

       
        // if the file is available, write to it:
        if (dataFile) {
          dataFile.println(line);
          }  
        else {
        Serial.println("error opening datalog.txt");
        }
      line = "";                    //reset to empty string
      break;
    default: 
      line += inByte;           //append inByte to the line String
      Serial.println(inByte, HEX);
    }
  }
  dataFile.close();
}

and I get this in the serial monitor and nothing in the datalog.

PaulS:

i,ve tried all sd examples and don't store anything.

And, so, you don't intend to show us how you tried to adapt them to your code, or tell us what the (observed) failure mode was for each example.

Well, OK. Good luck.

Sorry for disturbing truth is that I'm desperate, slightly modifying the previous sketch I managed to write something on the sd card but only get strange symbols

This is the code i used

#include <SD.h>
#include <SoftwareSerial.h>
//byte inByte=0;
int ent=3;
int sal=2;
#define ledPin 13





// 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 = 10;


void setup(){
  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.");
  Serial1.begin(4800);

  pinMode(ent,INPUT);
  pinMode(sal,OUTPUT);
  
  
}

String line = "";

void loop(){
  
  if(digitalRead(ent)==LOW){
  digitalWrite(sal,HIGH);}

  else{
  digitalWrite(sal,LOW);}





File dataFile = SD.open("datalog.txt", FILE_WRITE);

  if (Serial1.available()) {
    char inByte = Serial1.read(); 
    switch (inByte) {
      case '\n':
        Serial.println(line);     //print complete line

       
        // if the file is available, write to it:
        if (dataFile) {
          dataFile.println(line);
          }  
        else {
        Serial.println("error opening datalog.txt");
        }
      line = "";                    //reset to empty string
      break;
    default: 
      line += inByte;           //append inByte to the line String
      Serial.write(inByte);
      dataFile.write(inByte);
    }
  }
  dataFile.close();
}

It's probably a bug fool because I am a newbie in this area, thanks for your help.