Go Down

Topic: gps.encode() always returning false (Read 4048 times) previous topic - next topic

omerjerk

Jun 26, 2013, 08:17 am Last Edit: Jun 26, 2013, 02:54 pm by omerjerk Reason: 1
I've an Arduino Duemilanove and Radix UP501 GPS Module.
I've connected Tx of module to pin 10 of arduino. Vcc of module to 5V of arduino and Ground of module to ground of arduino.

this is my code :
Quote

#include <TinyGPS.h>

/*
The circuit:
* RX is digital pin 10 (connect to TX of other device)
* TX is digital pin 11 (connect to RX of other device)  */

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX
TinyGPS gps;

unsigned long fix_age;
long lat, lon;
int c;

void setup()  
{
 // Open serial communications and wait for port to open:
 Serial.begin(4800);
 while (!Serial) {
   ; // wait for serial port to connect. Needed for Leonardo only
 }


 Serial.println("Goodnight moon!");

 // set the data rate for the SoftwareSerial port
 mySerial.begin(4800);
}

void loop() // run over and over
{
 if (mySerial.available())
   c = mySerial.read();
   if(gps.encode(c)){
     Serial.println("Inside if condition");
     gps.get_position(&lat, &lon, &fix_age);
     Serial.print("Lat :");
     Serial.print(lat);
   }
}



The problem is that gps.encode() is always returning false.
What could be the problem. Is my GPS module derped ??

PaulS

Is the GPS connected to the mySerial instance? If so, what is the purpose of this code:
Code: [Select]
  mySerial.println("Hello, world?");
Are you really expecting the GPS to reply to that?

Are you sure that mySerial.available() ever returns a non-zero value? If so, what does mySerial.read() return?

omerjerk


Is the GPS connected to the mySerial instance? If so, what is the purpose of this code:
Code: [Select]
  mySerial.println("Hello, world?");
Are you really expecting the GPS to reply to that?

Are you sure that mySerial.available() ever returns a non-zero value? If so, what does mySerial.read() return?


Sorry . I put that line by mistake ..  Now I removed it.
And as I said I've connected the Tx of GPS module to pin 10 of arduino (pin 10 being my software serial Rx).

And mySerial.available() is always returning non-zero i.e. it's always true.
Only the gps.encode() is always returning false.

PaulS

Quote
And mySerial.available() is always returning non-zero i.e. it's always true.
Only the gps.encode() is always returning false.

Have you printed the data received from the GPS? Does it make sense? Care to share it?

If the GPS is not a 4800 baud device, for instance, it will send data that TinyGPS doesn't recognize, so of course  gps.encode() will never return true.

omerjerk



Have you printed the data received from the GPS? Does it make sense? Care to share it?

If the GPS is not a 4800 baud device, for instance, it will send data that TinyGPS doesn't recognize, so of course  gps.encode() will never return true.


The data which is received from the GPS contains random characters .  It is unreadable .
This is the link to the datasheet of the module : http://www.anglia.com/fastrax/datasheets/UP501.pdf

wildbill

Quote

The data which is received from the GPS contains random characters .  It is unreadable .


A likely cause is that the baud rate is incorrect. The datasheet you linked to mentions 9600 baud as the default.

omerjerk



A likely cause is that the baud rate is incorrect. The datasheet you linked to mentions 9600 baud as the default.


I changed the Baud Rate to 9600. Now the characters are readable but gps.encode() is still false.

PaulS

Quote
The data which is received from the GPS contains random characters .  It is unreadable .

But, you expect that some how, some way, TinyGPS will be able to make sense of it. How?

omerjerk


But, you expect that some how, some way, TinyGPS will be able to make sense of it. How?


should I assume that the problem is in my hardware ??

PaulS

Quote
should I assume that the problem is in my hardware ??

Not until you've followed up on wildbill's comment.

omerjerk

And one thing is that the output from the GPS starts from
$GPGSA


omerjerk


Not until you've followed up on wildbill's comment.


I changed the baud rate to 9600 already.

wildbill

You're missing braces in your code. The if that checks for my serial.available only effects the read. If there is nothing to read - a likely situation, the existing contents of c will be passed again. Tiny GPS will be baffled.

omerjerk


You're missing braces in your code. The if that checks for my serial.available only effects the read. If there is nothing to read - a likely situation, the existing contents of c will be passed again. Tiny GPS will be baffled.


Same situation even after placing the braces.

omerjerk

these are the kinda ouputes that I'm getting from the GPS module :


$GPRMC,125243.539,V,,,,,0.00,0.00,2603,,*

$GPGGA,125318.539,,,,,0,0,,,M,,M,,*4B

$GPGSA,A,1,,,,,,,,,,,,,,,*1E


Could the reason be that I'm inside my home and the GPS isn't directly below the sky ?



Go Up