Pages: [1]   Go Down
Author Topic: Gps module returning erroneous and same data  (Read 190 times)
0 Members and 3 Guests are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone,

I am trying to get location and speed data from my GPS module which uses the SKYLAB SKG13C.
I am using an Arduino Uno.
The problem is that I am receiving the same Invalid Data.

Here is my code:
Code:
#include<TinyGPS.h>
#include<SoftwareSerial.h>

TinyGPS gps;

void getgps(TinyGPS &gps)
{
  float latitude, longitude;
  gps.f_get_position(&latitude, &longitude);
  Serial.print("Lat/Long: ");
  Serial.print(latitude,5);
  Serial.print(", ");
  Serial.println(longitude,5);
  int year;
  byte month, day, hour, minute, second, hundredths;
  gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
  Serial.print("Date: "); Serial.print(month, DEC); Serial.print("/");
  Serial.print(day, DEC); Serial.print("/"); Serial.print(year);
  Serial.print("  Time: "); Serial.print(hour, DEC); Serial.print(":");
  Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC);
  Serial.print("."); Serial.println(hundredths, DEC);
  Serial.print("Altitude (meters): "); Serial.println(gps.f_altitude()); 
  Serial.print("Course (degrees): "); Serial.println(gps.f_course());
  Serial.print("Speed(kmph): "); Serial.println(gps.f_speed_kmph());
  unsigned long chars;
  unsigned short sentences, failed_checksum;
  gps.stats(&chars, &sentences, &failed_checksum);
  Serial.print("Failed Checksums: ");Serial.print(failed_checksum);
  Serial.println(); Serial.println();
  Serial.print("Satellites: ");
  Serial.println(gps.satellites());
}

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

void loop()
{
  while(Serial.available())
  {
    int c = Serial.read();
    Serial.print("Inside while...: ");
    Serial.println(c);
    //if(gps.encode(c)) I have omitted this line because encode() always returns FALSE!!
    {
      getgps(gps); //Used this as I had to see the Data that was being acquired...
      delay(1000);
    }
  }
}

The module's status LED blinks every second. So I am assuming that it has acquired a Fix, but still I am receiving Wrong output.
The GPS module's TX output is connected to Arduino Uno's PIN 0 (RX), and the GND PIN is connected to Arduino's GND.

Is the problem with the GPS Antenna?
Antenna Specifications :-
  Frequency: 1575.42 MHZ
  Voltage      : 3.0-5.0V
  Gain            : 30+-3dBi

Below is the output's screenshot (as Attachment) that I get:


* output.png (157.15 KB, 1360x768 - viewed 17 times.)
Logged

New River, Arizona
Offline Offline
God Member
*****
Karma: 19
Posts: 935
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There's several things wrong with what you're trying to do, and listing them would probably cause you a lot of confusion.  So, I'm going to suggest you get the example from the author's site and use it as a starting point.

There's several reasons for this, but there are two notable that you should pay close attention to.  First, he uses SoftwareSerial so that the console port is available for you to use for debugging and testing.  Second, he doesn't have any delay() calls in there that will make you miss characters since the cpu is in a hard loop and ignoring everything else.  You can't do that kind of thing with something that is sending characters all the time.

The example is at: http://arduiniana.org/libraries/tinygps/

Now, before you tell me that you used that example and that's where you got the code from, take a closer look at what he's doing and reproduce it.  Get the darn delay() out and use SoftwareSerial.

There are other examples where people used the same library out there as well.
Logged

Trying to keep my house under control http://www.desert-home.com/

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

I understand what you instructed, but I have already tried those......
Ill elaborate a bit more on what I have tried so far.

This is the simplest code that I have tried So far... returns similar output (Output's Screenshot is attached)
Code:
#include<TinyGPS.h>
#include<SoftwareSerial.h>

TinyGPS gps;
SoftwareSerial ss(10,11); //I have Multi-checked the PIN Connections...

void setup()
{
  ss.begin(4800); //Default baudrate of SKG13C is 4800
  Serial.begin(4800); //I have tried different rates here but to no effect
}

void loop()
{
  while(ss.available())
  {
    int c = ss.read();
    Serial.println((char)c); //Explicitly Conversion to char for better analysis...
    if(gps.encode(c))
    {
      long lat, lng;
      gps.get_position(&lat,&lng);
      Serial.print("Latitude: ");
      Serial.println(lat);
      Serial.print("Longitude: ");
      Serial.println(lng);
      Serial.println();
    }

Also, the delay() function has been inserted so that the data is viewable.
If the encode() function always returns FALSE when not commented out, the function never runs...


* output.png (122.33 KB, 1360x768 - viewed 9 times.)
« Last Edit: July 30, 2014, 05:19:23 pm by atf_know_nothing » Logged

New River, Arizona
Offline Offline
God Member
*****
Karma: 19
Posts: 935
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

 That looks like you have the wrong baud rate.  I suggest that you put together a small program that just reads from the GPS pin and prints what it gets.  The sentences should make sense, and yours don't.

Just cut the code down to do a read a character from the GPS and then print it.  You should see the sentences come out with the data in it.  When you do this, attach the GPS to the sofware serial port, and use the regular serial port with the arduino IDE, don't try to use the serial port in a split mode where you have one pin hooked to the gps and expect the other one to talk to the IDE.

So, move the GPS tx pin to the software serial input pin, and try to just read from the GPS  and output it through the regular serial port.  Remember to set the baud rate of the software serial port.  You don't have that in the first code you posted, but do in the second.  Something like this:
Code:
void setup()
{
  ss.begin(4800); // your GPS should be hooked here
  Serial.begin(4800); // this is only to talk to the IDE serial monitor
                                          // you can use any baud rate you want here.
}

void loop(){
   while(ss.available()){
      int c = ss.read();
      Serial.print((char)c);
   }
}


and see what you get.  For some problems, you have to go all the way back to the very beginning.
Logged

Trying to keep my house under control http://www.desert-home.com/

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

I have tried what you said... using your code...

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

TinyGPS gps;
SoftwareSerial ss(10,11);

void setup()
{
  ss.begin(4800);
  Serial.begin(4800);
}

void loop()
{
  while(ss.available())
  {
    int c = ss.read();
    Serial.print((char)c);
    if(gps.encode(c))
    {
      Serial.println("Got Fix!!");
    }
  }
}

The output I got is Attaached Below, but makes no sense (!?)


* op.png (169.93 KB, 1360x768 - viewed 6 times.)
Logged

New River, Arizona
Offline Offline
God Member
*****
Karma: 19
Posts: 935
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

GPS sentences start with a $ and end with a carriage return, what you're getting looks like one of the baud rates is wrong.  Looking at the datasheets vs code examples for this chip I see both 4800 and 9600 being used as the rx baudrate.  So, just to set that possibility aside, put a Serial.println("Hello World"); right after the Serial.begins to be sure the IDE terminal is right, then try different baud rates for the ss.begin()

I've seen different baud rates for different chips, your problem could be something like that.
Logged

Trying to keep my house under control http://www.desert-home.com/

Leeds, England
Offline Offline
God Member
*****
Karma: 14
Posts: 596
Quick, chuck it in the bin before the boss finds out...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The GPS module's TX output is connected to Arduino Uno's PIN 0 (RX)

I don't like the sound of that. Aren't you using 0 & 1 for Serial communication with the pc?

And do you have a link to the actual gps device you are using?
Logged

Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield

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

Im Sorry about the confusing posts.... I have been trying to make it work so I have been trying different wirings.
Currently Im using PIN 10 as Receiving PIN in the Arduino, i.e the TX PIN of the GPS device is connected to PIN 10 of the Arduino.

The Serial output works fine....  please refer to my 1st post.
If I try to print anything on the Serial Monitor directly, it works fine. Like For Example:
Code:
void loop()
{
    Serial.print("XXX");
    //rest of the code;
}

The link to the Device is
http://www.graylogix.com/index.php?main_page=product_info&products_id=25

I have already tried all available Baud rates for the GPS device.
1 very important detail that I had missed in all my earlier posts is that the Device worked the first time I hooked it up with the Arduino. Now its not working, today I also got another Device(Exactly Same).
The same errors were encountered again.
Now I have got a new Antenna which I think is the last solution. (Im thinking that this antenna might be the problem)
Ill hook the new antenna and post again.

Logged

New River, Arizona
Offline Offline
God Member
*****
Karma: 19
Posts: 935
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't see any reason a powered antenna would cause the serial to mess up.  It really looks like a baud rate problem since the various lines have similarities.  However, it could be a framing error or inverted data as well.

So, I'm goiing to recommend that you switch libraries from the software serial you have to the one here:

http://arduiniana.org/libraries/newsoftserial/

unless you're absolutely certain that you have the newest architecture.  Then, you can try data inversion to see if it straightens out the framing.

Beyond that, I have no clue.
Logged

Trying to keep my house under control http://www.desert-home.com/

Pages: [1]   Go Up
Jump to: