Serial.print() VS File.print()

Hy guys,
So, I have not so many experience... and my question may be very silly...

I just wanto to log data coming out form my CurrentCost energy meter.

I CAN see data coming out from CurrentCost connected to a softwareserial pin RX. Data are clean and readable.

ÿÿÿÿÿÿÿÿÿÿÿÿ 00082


203405CC020285911.0600184000000000025.6

I CAN write some info and run exemple from sdfat.

When I mesh up Serial.print(nameofvariable) and some SD operation (open file or File.print(nameofvariable)) the data came up not readable in terminal and on file. So I DO log the data on a file of the SD, but I cannot read (as human) what I've got.

ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ<&åi—?&L02h<?&'?É/* *?Å??OÉ* *?0[“?zÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ<&z?²éXt)ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ<?¬J¹?LaÉÿòÅ^??Á4 ?Id<Ó0??M"ò<Lµ??¦Lòÿÿÿÿÿÿÿ<?âË&“
zÒ&?ÿÅB<â?âÁx?

“?<&"LÁ?Á0ò^âÿÿÿÿÿÿÿÿ<Lz0“/??O zâ0K+ñ&Á?ùbLâ A
7â¡dâ[å?âââÿÿÿÿÿÿ<â?&Oat?
+ÐBO<?zòÂ"YÅ
?ÿù??Á[ÁòjÊÁ<§zÿÿÿÿÿÿÿÿÿ<O+j.Ízk2òO?
?sMz² ù<Yéòñ??ù"?5z&<?ùâzÿÿÿÿÿÿÿÿ<½Eâââñ<“
ÿ&^ L/`ù'??
M??ÇÉ?
ñÉ
?0­âLÁÿÿÿÿÿÿÿ<?

What I'm missing in my sketch:

#include <SdFat.h>
#include <SdFatUtil.h>
#include <SoftwareSerial.h>
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;
#define rxPin 4
#define txPin 300
SoftwareSerial softSerial = SoftwareSerial(rxPin,txPin);
void setup(void)
*{ *

  • pinMode(rxPin, INPUT); *

  • pinMode(txPin, OUTPUT);*

  • softSerial.begin(9750);*

  • Serial.begin(9600);*

  • Serial.println();*

  • PgmPrintln("Type any character to start");*

  • while (!Serial.available());*

  • // initialize the SD card*

  • !card.init();*

  • // initialize a FAT volume*

  • !volume.init(card);*

  • // open the root directory*

  • !root.openRoot(volume);*

  • Serial.println();*

  • Serial.println("Done");*
    }
    void loop(void){

// file.writeError = false;

  • !file.open(root, "CurrCost.log", O_CREAT | O_APPEND | O_WRITE);*

  • char someChar = softSerial.read();*

  • //char someChar = softSerial.read();*

  • Serial.print(someChar);*

  • file.write(someChar);*

  • !file.close() || file.writeError ;*
    }

Thanks in advance ;D

 !card.init();

The card.init() function is returning a value, which you are negating and then discarding. Why do you bother negating it? Don't you care whether the init() function succeeds?

 !volume.init(card);

Same questions.

!root.openRoot(volume);

Ditto.

   !file.open(root, "CurrCost.log", O_CREAT | O_APPEND | O_WRITE);

So, if the file fails to open, you try to write to it anyway. Makes perfect sense to me.

You are right, but I got the same problem with or without the file and sd error management. So I removed all the checks just to focus on my problem.

Thanks anyway.