Hello, I'm trying to get the data from a grove GPS device and save it in the SD card.
However, it seems that something is going wrong when I open the file.
Below is my code.
unsigned char buffer[512]; // buffer array for data receive over serial port
int count=0; // counter for buffer array
void loop()
{
File dataFile = FileSystem.open("/mnt/sd/GPSdatalog.txt", FILE_APPEND);
if (dataFile) {
if (SoftSerial.available()) // if date is coming from software serial port ==> data is coming from SoftSerial shield
{
while(SoftSerial.available()) // reading data into char array
{
buffer[count++]=SoftSerial.read(); // writing data into array
if (count == 512) {
dataFile.close();
break;
}
}
Serial.write(buffer,count); // if no data transmission ends, write buffer to hardware serial port
dataFile.write(buffer,count);
clearBufferArray(); // call clearBufferArray function to clear the stored data from the array
count = 0; // set counter of while loop to zero
}
dataFile.close();
}
else {
Serial.println("error opening datalog.txt");
}
if (Serial.available()) // if data is available on hardware serial port ==> data is coming from PC or notebook
SoftSerial.write(Serial.read());
}
There is two problem I can't figure out.
- I set the buffer to be in size of 512, but I only get 64 char one time.
- The file is normally opened only at the first time the when loop() is executed, then it keep failed to open the file.
The output looks like this.
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,1,1,0$GPGGA,001826.801,,,,,0,0,,,M,,M,,*4C
$GPGSA,A,1,,,,,,,,,,,,,,error opening datalog.txt
$GPGGA,001831.801,,,,,0,0,,,M,,M,,*4A
$GPGSA,A,1,,,,,,,,,,,,,,error opening datalog.txt
$GPGGA,001859.801,,,,,0,0,,,M,,M,,*44
$GPGSA,A,1,,,,,,,,,,,,,,error opening datalog.txt
$GPGGA,001928.801,,,,,0,0,,,M,,M,,*43
$GPGSA,A,1,,,,,,,,,,,,,,error opening datalog.txt
PS. I'm just testing indoor, so the GPS data is all blank.