Software Serial & Parallax GPS

I am having problems outputting the raw NMEA strings coming from the Parallax GPS while using a software serial pin.

This code works great when using pin 0 and 1:

 #include <string.h>
 #include <ctype.h>

 int rxPin = 0;                    // RX PIN 
 int txPin = 1;                    // TX TX
 int byteGPS=-1;
 char linea[300] = "";
 char comandoGPR[7] = "$GPRMC";
 int cont=0;
 int bien=0;
 int conta=0;
 int indices[13];

 void setup() {
   pinMode(rxPin, INPUT);
   pinMode(txPin, OUTPUT);
   Serial.begin(4800);
   for (int i=0;i<300;i++){       // Initialize a buffer for received data
     linea[i]=' ';
   }   
 }

 void loop() {
   byteGPS=Serial.read();         // Read a byte of the serial port
   if (byteGPS == -1) {           // See if the port is empty yet
     delay(100); 
   } else {
     linea[conta]=byteGPS;        // If there is serial port data, it is put in the buffer
     conta++;                      
     Serial.print(byteGPS, BYTE); 
     if (byteGPS==13){            // If the received byte is = to 13, end of transmission
       cont=0;
       bien=0;
       for (int i=1;i<7;i++){     // Verifies if the received command starts with $GPR
         if (linea[i]==comandoGPR[i-1]){
           bien++;
         }
       }
       conta=0;                    // Reset the buffer
       for (int i=0;i<300;i++){    //  
         linea[i]=' ';             
       }                 
     }
   }
 }

and the serial monitor displays this:

And using softwareserial and pins 8 and 9:

 #include <string.h>
 #include <ctype.h>
 #include <SoftwareSerial.h>

#define rxPin 8
#define txPin 9

SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
 int byteGPS=-1;
 char linea[300] = "";
 char comandoGPR[7] = "$GPRMC";
 int cont=0;
 int bien=0;
 int conta=0;
 int indices[13];

 void setup() {
   Serial.begin(19200);
   pinMode(rxPin, INPUT);
   pinMode(txPin, OUTPUT);
   mySerial.begin(4800);
   for (int i=0;i<300;i++){       // Initialize a buffer for received data
     linea[i]=' ';
   }   
 }

 void loop() {
   byteGPS=mySerial.read();         // Read a byte of the serial port
   if (byteGPS == -1) {           // See if the port is empty yet
     delay(100); 
   } else {
     linea[conta]=byteGPS;        // If there is serial port data, it is put in the buffer
     conta++;                      
     Serial.print(byteGPS, BYTE); 
     if (byteGPS==13){            // If the received byte is = to 13, end of transmission
       digitalWrite(ledPin, LOW); 
       cont=0;
       bien=0;
       for (int i=1;i<7;i++){     // Verifies if the received command starts with $GPR
         if (linea[i]==comandoGPR[i-1]){
           bien++;
         }
       }
       conta=0;                    // Reset the buffer
       for (int i=0;i<300;i++){    //  
         linea[i]=' ';             
       }                 
     }
   }
 }

And the serial monitor prints this:

which seems to print the right data but it does not print the headers for each string and it is continuously printing horizontally.

Any suggestions will help! Thanks.

Try sticking in a delay and try using the newsoftserial library instead of the softwareserial library.

Mowcius

Using NewSoftSerial nothing displays on the serial monitor at all.

I am using the Mega with the other hardware Serial pins. I also tried changing the rx to 19 and tx to 18 with also no output on the serial monitor.

Basically I don't understand why the rx data would be different coming from the hardware serial pin than the data coming from the software serial pin...

I am using the Mega with the other hardware Serial pins.

Does the data get received if you use one of the other hardware serial ports?

I am not sure if it gets received or not. It does not print anything on the serial monitor at 4800 baud.

Is it safe to assume that you are actually plugging the GPS into the hardware serial ports that you are reading from?

Yes. When I change the program to use the SoftwareSerial library and change rx to pin 8, the SIO pin of the GPS is connected to pin 8 of the Arduino. But the tx pin specified has nothing plugged in as the Parallax has only one pin for communication.

If you have a Mega, with multiple hardware serial ports, why are you messing with software serial?

I figured that out also after I started messing with it. So I then assigned the rx and tx pins to the hardware pins 19 and 18. Well I get no output in that case either...

When using pins 18 and 19, you did switch to Serial1.available, Serial1.read, etc., didn't you?

Yes I did. but I forgot to uncomment the Serial.begin(19200) and now it works. Thanks!