TinygGPS Problem

I have an EM408 GPS
I managed to get raw data and display it to the serial monitor succesfully.
Now i have a problem using the tinyGPS library. I get nothing at all as a result in my serial monitor.

This is the code i used:

#include <TinyGPS.h>
#include <SoftwareSerial.h>

TinyGPS gps;
SoftwareSerial GPS = SoftwareSerial(2,3);  //rx,tx
byte a;
float flat, flon;
unsigned long time, date;

void setup()
{
  GPS.begin(4800);
  Serial.begin(9600);
}

void loop()
{
  
  
if(GPS.available() > 0){
  a=(byte(GPS.read()));} 
if(gps.encode(a)){
  
 gps.f_get_position(&flat, &flon);
 gps.get_datetime(&date, &time);
 Serial.print(flat);
 Serial.print(flon);
  }
}

Can anyone experienced with tinyGPS help me out?
Thanks!

Looks like if there is no character available from the GPS you process the previous character again. This is likely to cause bad messages.

if(GPS.available() > 0) {
  a=(byte(GPS.read()));
} 

if(gps.encode(a)) {
  ...
  }
}

Should look like:

  if(GPS.available() > 0) {
    a=(byte(GPS.read()));
    if(gps.encode(a)) {
      ...
      }
  }

Or more compactly:

if(GPS.available() > 0) {
  if (gps.encode(GPS.read())) {
    ...
    }
  }

Hm, you're right that maybe at first it wont receive anything. But since we're in a loop it is bound to get characters from GPS.available(), and then the magic will happen.

Anyway though, i tested both codes you sent (and thank you BTW) and no it doesn't work.

Actually, since i started this thread, i experimented again and i have opened another thread. Seems like all the trouble i receive is from gps.encode().

It doens't return true. Maybe you've seen the other thread. Anyways, here it is... http://forum.arduino.cc/index.php?topic=245178.0