Arduino community--
I'm looking to use my Yun as a data logging platform for data being emitted by a serial source. I keep having hangs and other unexpected lost characters at a rate of 50 bytes/second, and my suspicion is that the bridge library is getting saturated somehow. At extremely slow transmission speeds this does not appear to happen.
What is the preferred way to stream data from the serial port to a file on the SD card? Are the file libraries considered stable?
My current code:
/**********************************************
* Logs everything it hears on pin 10 to a file
*/
#include <FileIO.h>
#include <SoftwareSerial.h>
// SoftwareSerial mySerial(10, 11); // RX, TX
SoftwareSerial mySerial(10, 11); // RX, TX
void setup()
{
// put your setup code here, to run once:
// Setup Bridge (needed every time we communicate with the Arduino Yún)
Bridge.begin();
Serial.begin(115200);
while(!Serial); // wait for Serial port to connect.
Serial.println("File Write Script example\n\n");
FileSystem.begin();
mySerial.begin(57600);
mySerial.println("Listening on pin 10");
}
char buff[1000];
void loop()
{
int cycleStart = millis();
Serial.println( "Opening file...");
File thefile = FileSystem.open("/mnt/sd/log4.csv", FILE_APPEND);
Serial.println( "Entering loop...");
while( millis() - cycleStart < 10000 )
{
while(mySerial.available())
{
// thefile.write(mySerial.read() );
int l = mySerial.readBytes( buff, 999 );
Serial.write((uint8_t *)buff, l);
thefile.write((uint8_t *)buff, l );
}
}
cycleStart = millis();
Serial.println( "Closing file...");
thefile.close();
return;
}