Pages: [1] 2 3   Go Down
Author Topic: gps.encode() always returning false  (Read 3585 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ??
« Last Edit: June 26, 2013, 07:54:07 am by omerjerk » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50524
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is the GPS connected to the mySerial instance? If so, what is the purpose of this code:
Code:
  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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is the GPS connected to the mySerial instance? If so, what is the purpose of this code:
Code:
  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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50524
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 71
Posts: 3744
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50524
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ??
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50524
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
should I assume that the problem is in my hardware ??
Not until you've followed up on wildbill's comment.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

I changed the baud rate to 9600 already.
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 71
Posts: 3744
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?


Logged

Pages: [1] 2 3   Go Up
Jump to: