hey guys.
i have a code that recieved chars from hyperterminal convert it to string and write it on text file
when i use the monitor instead of hyperterminal it work but when i switch to hyper it dosent work
I can not find the problem in the code
I would be happy if you could help
Thanks in advance.
#include <SPI.h>
#include <SD.h>
char inData;
String dataString;
File dataFile();
void setup()
{
Serial.begin(9600);
while (!Serial.available()); // wait for serial port to connect. Needed for native USB port only
if (!SD.begin(4)) // see if the card is present and can be initialized.
{
Serial.println("initialization failed!");
while (1); // don't do anything more.
}
}
void loop()
{
if (Serial.available())
{
while (Serial.available() > 0)
{
pinMode(3,HIGH);
dataString = "";
inData = Serial.read();
dataString += String(inData);
/*if (inData == '\n')
{
dataString += "\n";
}*/
// 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.print(dataString);
dataFile.close();
// print to the serial port too:
Serial.print(dataString);
}
// if the file isn't open, pop up an error:
else
{
Serial.println("error opening datalog.txt");
}
}
}
}