GPS Software Serial Problem

Hi,

I’m fairly new to Arduino, and this is the first time I’ve tried to use SoftwareSerial. I have an Arduino ‘Skinny’ (made by SparkFun - ATMEGA168V @ 8MHz IIRC) and an EM-402 GPS module that I also bought from Sparkfun.

I’ve used some code that I found on the xbee website for their libelium GPS that is very basic. It just copies the serial data from the GPS to the hardware serial port on the Arduino (so you can see it on the host computer).

I am receiving serial data, but it is garbled. It doesn’t appear to be a baudrate mismatch, as I do occasionally receive fully formed NMEA strings (e.g. $GPGGA,212254.651,5004.3603,N,00102.8666,W,1,00,50.0,169.6,M,0000), there just appears to be random noise inserted into them.

I have a hardware serial logger, that writes serial data to a text file on an SD card. Using this, I can capture the serial datastream using the same serial settings (4800,n,8,1) without the noise, so I assume the cable and GPS are OK.

Here’s the code I’m using (original taken from here:http://www.libelium.com/squidbee/index.php?title=GPS_module )
Code to start with…

/*******************************************

  • Program for reading possition from GPS
  • module via the softwareSerial
  • M. Yarza
  • Oct 2.007 Zaragoza
    *******************************************/

// include the SoftwareSerial library
#include <SoftwareSerial.h>

// Constants
#define rxPin 2
#define txPin 3

// set up the serial port

SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

// variables
byte byteGPS = 0;
int i = 0;
int indices[13];
int cont = 0;
int conta = 0;

char inBuffer[300] = “”;

int k = 0;

void setup(){

//setup for mySerial port
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
mySerial.begin(4800);

//setup for Serial port
Serial.begin(9600);

// setup the GPS module
Serial.println(“Configuring GPS…”);
delay(1000);
mySerial.println("$PSRF100,1,4800,8,1,0*0C\n"); // configure NMEA serial
delay(100);
mySerial.println("$PSRF103,00,00,05,00\n"); // configure NMEA sentences to show only GGA sentence every 5 sec
delay(100);
mySerial.println("$PSRF103,01,00,00,00\n"); // configure NMEA sentences to not show GLL
delay(100);
mySerial.println("$PSRF103,02,00,00,00\n"); // configure NMEA sentences to not show GSA
delay(100);
mySerial.println("$PSRF103,03,00,00,00\n"); // configure NMEA sentences to not show GSV
delay(100);
mySerial.println("$PSRF103,04,00,00,00\n"); // configure NMEA sentences to not show RMC
delay(100);
mySerial.println("$PSRF103,05,00,00,00\n"); // configure NMEA sentences to not show VTG
delay(100);

// command for setting time and position
mySerial.println("$PSTMINITGPS,5004.354,N,00102.817,W,0197,14,07,2008,23,38,00\n");

// “4140.000,N” means: Latitude 41º40’00.0" North
// “00053.000,W” means: Longitude 0º53’00.0" West
// “0197” means 197 m elevation
// “22,10,2007,11,40,00” means date and time (October 22, 2.007 - 11h 40min 00sec UTC time)
}

void loop(){

byteGPS = 0;
i = 0;
while(byteGPS != 42){ // read the GGA sentence
byteGPS = mySerial.read();
inBuffer*=byteGPS; *

  • i++; *

  • }*

  • k = 1;*

  • while(inBuffer[k] != 42){*

  • Serial.print(inBuffer[k]); // write the GGA sentence*

  • k++;*

  • }*

  • Serial.println();*

  • delay(3000);*
    }
    ================================================================================
    Serial output from above…
    ================================================================================
    Configuring GPS…
    ,
    Ê6V
    [ch8710]Ï
    3
    3fñ,140708,
    4,21,06,47,267,36,03,31,268,26
    ,0.00,140708,
    FÊ6V
    [ch8710]Ï
    3
    3fñ,140708,
    3
    [ch8805]fÕò,W,0.00,140708,
    Êç
    3fÃò4.8351,W,0.00,140708,
    06,47,267,37,03,31,268,26
    5eÕó31,301.99,140708,
    &[ch8710]Ïô3
    3fñ285.21,140708,
    3
    3fñ,140708,
    Ã
    3fÃò4.8418,W,0.00,140708,
    47,267,29,03,31,268,31
    0.00,140708,
    N,00102.8418,W,2.02,334.21,140708,
    40708,
    ç
    3fÃò4.8421,W,0.00,140708,
    5,104,22,06,47,267,36,03,31,268,28
    ,140708,
    N,00102.8421,W,0.00,140708,
    FÊF&
    [ch8710]Ï
    3
    3fñ,140708,
    À8421,W,0.00,140708,
    F[ch8710]L?fÀò6,47,267,30,03,31,268,33
    .00,140708,
    ò3,N,00102.8421,W,0.00,140708,
    F&
    [ch8710]Ï
    3
    3fñ,140708,
    F&
    [ch8710]Ï
    3
    3fñ,140708,
    F[ch8710]L
    fÀò6,47,267,35,03,31,268,32
    .00,140708,
    ,00102.8421,W,0.00,140708,
    ,W,0.00,140708,
    fÕó8421,W,0.00,140708,
    04,23,06,47,267,31,03,31,268,32
    ,0.00,140708,
    ò0102.8421,W,0.00,140708,
    &
    [ch8710]Ï
    3
    3fñ,140708,
    Àß,00102.8421,W,0.00,140708,
    3eÕ7,267,36,03,31,268,35
    Ï
    3
    3fñ,140708,
    fÃò4.8421,W,0.00,140708,
    ú421,W,0.00,140708,
    ÉFÊF&
    [ch8710]Ï
    3
    3fñ,140708,
    F[ch8710]L
    3eÃ6,47,267,35,03,31,268,34
    ?ñ,
    lY[ch8805]ffÀß,00102.8421,W,0.00,140708,
    ò,140708,
    [ch8805]ffÀß,00102.8421,W,0.00,140708,
    v[ch8710]lôfÀò3,31,268,34
    [ch8710]åY3fò708,
    ô
    3fÃò4.8436,W,4.22,312.83,140708,
    efÃô.99,140708,
    g?ñW,9.33,289.17,140708,
    4,03,31,268,33
    FÊfVF[ch8710]Ï
    3
    3fñ,140708,
    3[ch8805]fÕ,W,0.00,140708,
    0102.8654,W,0.00,140708,
    [ch8710]Ï
    3
    3fñ,140708,
    [ch8805]gÀ268,33,03,33,269,32
    ,00102.8654,W,0.00,140708,
    3[ch8805]fÕ,W,0.00,140708,
    ÜfVF[ch8710]Ï
    3
    3fñ,140708,
    00102.8654,W,0.00,140708,
    6,49,268,34,03,33,269,31
    FÊfVÜ[ch8710]Ïô3Y33efÃö.53,140708,
    6,W,0.00,140708,
    4.8666,W,0.00,140708,
    5[ch711]
    3
    3fñ,140708,
    ò1,24,06,49,268,31,03,33,269,34
    e5eÃ.00,140708,
    [ch8805]Ãò4.8666,W,0.00,140708,
    Üfff[ch8710]Ï
    3
    3fñ,140708,
    666,W,0.00,140708,
    &v[ch8710]ô3eÕ9,268,31,03,33,269,31
    f[ch8710]Ï
    3
    3fñ,140708,
    F
    v
    Ü[ch8710]åô2fh[ch8730]Ö$GPGGA,212254.651,5004.3603,N,00102.8666,W,1,00,5

Try using the hardware serial port for the GPS input and the software one for the PC. The software serial is at its max at 4800 whereas the hardware serial port can easily handle this speed. The overhead of your program as well as the software serial processing could be pushing it too far and missing bits of the input stream. Using the hardware port will ensure correct processing of the stream.