Hi all,
it seems like a bug , I don't do any heavy lifting in the code, all simple stuff , and it turns out that bug is consistent all the way.
So using Arduino UNO and IDE 1.0.6 I hooked up GPS on SoftSerial lib, SD card on SPI and Serial to USB to watch traffic.
BUG:
If I include output of data to SD card, output to USB serial goes strange (different lines of data mix together).
If I turn off that part of code, all works fine and lines of data from GPS come in normal.
So here is the code:
#include <SPI.h>
#include <SoftwareSerial.h>
#include <SD.h>
//SPI SD Card Pins
//MOSI = Pin 11
//MISO = Pin 12
//SCLK = PIN 13
int CS_pin = 10;
char buffer[100];
char c;
int c_cnt=0;
int c_avail = 0;
SoftwareSerial mySerial(2, 3); // RX, TX
void setup()
{
Serial.begin(9600);
Serial.println("Initializing Card");
//CS Pin is an output
pinMode(CS_pin, OUTPUT);
digitalWrite(CS_pin, HIGH);
//Initialize Card
if (!SD.begin(CS_pin))
{
Serial.println("Card Failure");
return;
}
Serial.println("Card Ready");
File logFile = SD.open("LOG.csv", FILE_WRITE);
if (logFile)
{
logFile.close();
Serial.println("Printing to log");
}
else
{
Serial.println("Couldn't open log file");
}
mySerial.begin(9600);
mySerial.println("Hello, world?");
}
void loop()
{
c_avail = mySerial.available();
for(int i = 0 ; i < c_avail; i++){
c = mySerial.read();
buffer[c_cnt] = c;
if(c == '\r'){
//Serial.print("[R]");
continue;
}
if(c == '\n'){
//Serial.print("[N]");
buffer[c_cnt]='\0';
//Serial.println(buffer);
//> ==== BUG START ====
//> File logFile = SD.open("LOG.csv", FILE_WRITE);
//> if (logFile)
//> {
//> logFile.println(buffer);
//> logFile.close();
//> }
//> ==== BUG END ====
c_cnt=0;
Serial.println(buffer);
continue;
}
c_cnt++;
//Serial.write(c);
}
}
If the BUG code is turned off output is:
Initializing Card
Card Ready
Printing to log
$GPRMC,130841.00,V,,,,,,,170215,,,N72
$GPVTG,,,,,,,,,N30
$GPGGA,130841.00,,,,,0,00,99.99,,,,,,69
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.9930
$GPGSV,4,1,13,02,16,241,,05,52,294,,06,00,203,,07,57,054,*72
$GPGSV,4,2,13,09,30,096,,10,51,175,,13,25,286,23,20,29,164,7C
$GPGSV,4,3,13,23,02,100,,26,38,289,28,27,02,045,,28,25,161,75
$GPGSV,4,4,13,30,87,158,4B
$GPGLL,,,,,130841.00,V,N45
$GPRMC,130842.00,V,,,,,,,170215,,,N71
$GPVTG,,,,,,,,,N30
$GPGGA,130842.00,,,,,0,00,99.99,,,,,,6A
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.9930
$GPGSV,4,1,13,02,16,241,,05,52,294,,06,00,203,,07,57,054,*72
$GPGSV,4,2,13,09,30,096,,10,51,175,,13,25,286,23,20,29,164,7C
$GPGSV,4,3,13,23,02,100,,26,38,289,28,27,02,045,,28,25,161,75
$GPGSV,4,4,13,30,87,158,4B
$GPGLL,,,,,130842.00,V,N46
$GPRMC,130843.00,V,,,,,,,170215,,,N70
$GPVTG,,,,,,,,,N30
$GPGGA,130843.00,,,,,0,00,99.99,,,,,,6B
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.9930
$GPGSV,4,1,13,02,16,241,,05,52,294,,06,00,203,,07,57,054,*72
$GPGSV,4,2,13,09,30,096,,10,51,175,,13,25,286,23,20,29,164,7C
$GPGSV,4,3,13,23,02,100,,26,38,289,28,27,02,045,,28,25,161,75
$GPGSV,4,4,13,30,87,158,4B
$GPGLL,,,,,130843.00,V,N47
$GPRMC,130844.00,V,,,,,,,170215,,,N77
$GPVTG,,,,,,,,,N30
$GPGGA,130844.00,,,,,0,00,99.99,,,,,,6C
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.9930
$GPGSV,4,1,13,02,16,241,,05,52,294,,06,00,203,,07,57,054,*72
$GPGSV,4,2,13,09,30,096,,10,51,175,,13,25,286,23,20,28,164,7D
$GPGSV,4,3,13,23,02,100,,26,38,289,28,27,02,045,,28,25,161,75
$GPGSV,4,4,13,30,87,158,4B
$GPGLL,,,,,130844.00,V,N40
$GPRMC,130845.00,V,,,,,,,170215,,,N76
$GPVTG,,,,,,,,,N30
If BUG code is turned on, output is:
0,,26,38,288,25,27Initializing Card
Card Ready
Printing to log
$GPRMC,130741.00,V,,,,,,,170215,,,N7D
$GPVTG,,,,,,,,,N30
$GPGGA,130741.00,,,,,0,00,99.99,,,,,,66
$GPRMC,130742.00,V,,,,,,,170215,,,N7E
$GPVTG,,,,,,,,,N30
$GPGGA,130742.00,,,,,0,00,99.99,,,,,,65
,,30,87,164,78
$GPG$GPRMC,130743.00,V,,,,,,,170215,,,N7F
$GPVTG,,,,,,,,,N30
$GPGGA,130743.00,,,,,0,00,99.99,,,,,,64
,,30,87,164,78
$GPG$GPRMC,130744.00,V,,,,,,,170215,,,N78
$GPVTG,,,,,,,,,N30
$GPGGA,130744.00,,,,,0,00,99.99,,,,,,63
$GPRMC,130745.00,V,,,,,,,170215,,,N79
$GPVTG,,,,,,,,,N30
$GPGGA,130745.00,,,,,0,00,99.99,,,,,,62
1,,30,87,164,78
$GP$GPRMC,130746.00,V,,,,,,,170215,,,N7A
$GPVTG,,,,,,,,,N30
$GPGGA,130746.00,,,,,0,00,99.99,,,,,,61
,,30,87,164,78
$GPG$GPRMC,130747.00,V,,,,,,,170215,,,N7B
$GPVTG,,,,,,,,,N30
$GPGGA,130747.00,,,,,0,00,99.99,,,,,,60
1,30,87,164,78
$GPG$GPRMC,130748.00,V,,,,,,,170215,,,N74
$GPVTG,,,,,,,,,N30
$GPGGA,130748.00,,,,,0,00,99.99,,,,,,6F
,30,87,164,78
$GPGL$GPRMC,130749.00,V,,,,,,,170215,,,N75
$GPVTG,,,,,,,,,N30
$GPGGA,130749.00,,,,,0,00,99.99,,,,,,*6E
1,30,87,164,*78
Any hint on this?
SOLUTION:
So just to share with anyone who needs it, in my current setup solution was to change line in SoftwareSerial.h
#define _SS_MAX_RX_BUFF 256 // RX buffer size was 64
This works as is should 8)
Thanks to everyone!