Pages: 1 [2] 3   Go Down
Author Topic: gps.encode() always returning false  (Read 3583 times)
0 Members and 1 Guest are viewing this topic.
Leeds, England
Offline Offline
God Member
*****
Karma: 16
Posts: 714
Quick, chuck it in the bin before the boss finds out...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

$GPGGA, sixth position (starting from 1!), 0=fix not available.
Logged

Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield

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

Quote
Could the reason be that I'm inside my home and the GPS isn't directly below the sky ?
Well, duh!
Logged

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

Well, duh!

???   smiley-roll-sweat

you mean yes or no ??
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 70
Posts: 3743
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For best results, a GPS unit needs an unobstructed view of the sky. You can get away with some obstruction - depending on the device, it may work near a window for example.

Try taking it outside and see if things improve. At this point I'd forget TinyGPS and just echo what the GPS is sending to serial until you get better data. Note too that it may take a while to get a decent fix for the first time.
Logged

Mid-Atlantic, USA
Offline Offline
God Member
*****
Karma: 30
Posts: 515
"Remember kids, the only difference between Science and screwing around is writing it down." - Adam Savage
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not that familiar with tinygps.h (but have a lot of familiarity dealing with NMEA sentences), so I may be way off base here. But, how is tinygps.h getting a full sentence? This bit of code (which is the only code presented in this thread, I added all but the first comment for clarity):
Code:
void loop() // run over and over
{
  if (mySerial.available())
    c = mySerial.read();     // previously declared as int, will read 1 character from SoftwareSerial
    if(gps.encode(c)){     // passes 1 character to gps.encode()
      Serial.println("Inside if condition");
      gps.get_position(&lat, &lon, &fix_age);
      Serial.print("Lat :");
      Serial.print(lat);
    }
}

Only sends one character to gps.encode(), not an entire sentence. (The issue of missing braces for the first if condition appears to have been already covered in this thread.) If tinygps.h is expected to fetch the rest of the sentence over serial (i doubt it, but I don't know), where do you tell tinygps.h what pins you are using for it's serial communication (and how would tinygps.h know whether it's a hardware serial port or SoftwareSerial)?

Logged


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

Quote
Only sends one character to gps.encode(), not an entire sentence.
True, but the TinyGPS instance is what is responsible for storing each new character in an array, and returning true or false, if the last character added is the end of the sentence.

Logged

Mid-Atlantic, USA
Offline Offline
God Member
*****
Karma: 30
Posts: 515
"Remember kids, the only difference between Science and screwing around is writing it down." - Adam Savage
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Only sends one character to gps.encode(), not an entire sentence.
True, but the TinyGPS instance is what is responsible for storing each new character in an array, and returning true or false, if the last character added is the end of the sentence.



Ok, got it. Yeah, the OP should really take it outside to get a good GPS lock.
Logged


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

I took the GPS outside and and waited for one minute still no results.
i tried another Arduino too. Now finally I think the GPS module is actually derped.
Logged

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

Quote
I took the GPS outside and and waited for one minute still no results.
It has been pointed out that a brand new, never been used, GPS can take up to 10 minutes to locate satellites and download enough data. Patience, grasshopper.
Logged

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 47
Posts: 2928
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

From the TinyGPS12.zip file found on http://arduiniana.org/libraries/tinygps/ there is a demonstration program that you might try, outside. test_with_gps_device, Change line 11 to read "SoftwareSerial nss(10, 11);", upload the code to the Arduino and take your GPS device outside, I used a laptop for my first experiments and found that it works well enough by my window. Much better outside however, your position and altitude will shift noticeably and erratically inside.
When the GPS receiver has built an ephemeris from data received from the GPS sat's it will start to display meaningful data. I currently own a Skylabs SKM53 and a U-Blox 6M and either require 4 to 6 minutes to get a position fix. Once a 'fix' is determined the device will output data as long as there are enough sat's visible and close enough for accurate reception. HTH... I attached a file that can be freely downloaded from U-Blox that will display a great deal about your GPS receiver, While written for the U-Blox product I believe that it will work with any GPS receiver. The program is quite well featured, Almost more than you need.

Doc

* u-centerSetup-6.3.1.0.exe (3478.61 KB - downloaded 21 times.)
« Last Edit: July 01, 2013, 05:27:44 am by Docedison » Logged

--> WA7EMS <--
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3080
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1.  You need to display the data being actually sent by the GPS.    then you can worry about whether it is being parsed OK.

2.  GPS devices can take a long time to start up,  particularly indoors.
Logged

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3080
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I use a program called "MiniGPS"  which allows you to connect the GPS directly to the PC ( without the arduino )   and see what it is doing.

Your GPS is working.  Thats what those  $GPSGA...    text string you have are.    But is hasn't got a position because it hasn't
collected enough data from the satellites.    Mine takes up to 20 minutes indoors.
Logged

0
Offline Offline
Sr. Member
****
Karma: 4
Posts: 289
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When a GPS is first powered up it spits out NMEA sentences but it won't have a lock on any satellites yet.  It needs at least 3 and this will take a few minutes to happen.  You will know that it has a lock when this:


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


changes to something like this:

Code:
$GPGGA,175025.530,4041.1271,N,07406.4956,W,1,05,1.8,-266.0,M,-34.2,M,,0000*48

It will happen eventually if you have a clear view of the sky but it may take several minutes.  Just walk away from it and check back after about 10 minutes.  Assuming you always have the GPS hooked to power and you just put it into sleep mode when not using it, subsequent activations should take less than a minute to get a valid fix.
Logged

Arduino Uno;
Mega328

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 504
Posts: 19106
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I just tried my digital GPS clock described here.

Powered up from cold, indoors, it took about 60 seconds to even show the correct time, and another 45 seconds to get a lock.

However within a second or so it should be spitting out correct NMEA sentences.
Logged


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

When a GPS is first powered up it spits out NMEA sentences but it won't have a lock on any satellites yet.  It needs at least 3 and this will take a few minutes to happen. 

I waited for one and a half hour.
Logged

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