Pages: [1]   Go Down
Author Topic: TinyGPS library question?  (Read 626 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi All!
I am trying to do something very basic (probably!) but can't see to be able to do it :S !
All I want is to output the Latitude and Longitude from my lassen iQ GPS, using the TinyGPS library, to the serial port (eventually I'll output it to a different port as it will be sent to the radio).
The code i'm using is below:
Code:
#include "TinyGPS.h"
TinyGPS gps;
long lat, lon;
unsigned long fix_age, time, date, speed, course;
unsigned long chars;
unsigned short sentences, failed_checksum;

void setup() {

  Serial.begin(4800);
}
void loop()
{
 // retrieves +/- lat/long in 100000ths of a degree
gps.get_position(&lat, &lon, &fix_age);

// time in hhmmsscc, date in ddmmyy
gps.get_datetime(&date, &time, &fix_age);

// returns speed in 100ths of a knot
speed = gps.speed();

// course in 100ths of a degree
course = gps.course();

Serial.println(THIS IS WHERE I WANT TO PRINT LAT & LONG!)
}

Where the Serial.println is, that is where I want to be able to say "Lat: _______, Long: ______".
Can someone please help me out!
Thanks smiley
Logged

Bremen
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try to get the library's example to work first. BTW: You will need SoftSerial if you want to output data via USB.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've tried the example library but not reading anything on serial monitor :S. I haven't got anything hooked up to pin 3 (tx on nss). If I need something attached to pin 3 where do I hook the other end up to?! Thanks
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24424
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but not reading anything on serial monitor

I'm surprised it even compiled:
Code:
Serial.println([glow]"[/glow]THIS IS WHERE I WANT TO PRINT LAT & LONG![glow]"[/glow])[glow];[/glow]
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi cuddykid! Have you solved this problem? Is everything working? I'm currently setting up Lassen IQ with Arduino Duemilanove and could really use a helping hand..
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi simhed!

Nope, haven't found a solution!! Its really annoying me and I'm desperately trying to find an answer because I'm sure this tinygps library was meant to make things easy!!
Keep me posted if you make a breakthrough, and I'll keep you posted if I do!
Thanks
Logged

Bremen
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So step back and check everything. Do you get GPS-messages from your GPS module? No: some other problem. Yes: a TinyGPS-problem.
Logged

Adelaide, South Australia
Offline Offline
Full Member
***
Karma: 0
Posts: 139
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm doing similar GPS project and although a novice in Arduino S/W land I am going to be a bit cheeky and share a few thoughts for you to consider:

1) are you sure the speed and course variables have received the GPS data? Beginner me would try running the code in debug mode and look at them to be sure they have actual data

2) I'm pretty sure the speed and course variables will need to be text format before serial.print will output them. If they're not in text format (look at them in debug mode) they'll need to be converted

3) to compose a line like LAT: xxx LONG: YYY requires four parts be either joined together or output one by one. If you do the latter only the last part should be done with serial.println (because the "ln" causes the line to end a new line to start). The first three parts would be done with just serial.print.

Now hopefully an Arduino expert or three will improve/correct my suggestion and help us both...  8-)
« Last Edit: July 01, 2010, 04:47:05 pm by ninja2 » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Right, I've succesfully got it working! Using the following code:
Code:
#include "TinyGPS.h"

TinyGPS gps;

float flat, flon;
unsigned long fix_age, time, date, speed, course;
unsigned long chars;
unsigned short sentences, failed_checksum;

void getgps(TinyGPS &gps);

void setup() {

  Serial.begin(4800);

}

void loop()

{
  if (Serial.available() > 0){  
    char c = Serial.read();

    if (gps.encode(c))
    {
      gps.f_get_position(&flat, &flon, &fix_age);
      gps.get_datetime(&date, &time, &fix_age);
      
      float falt = gps.f_altitude(); // +/- altitude in meters
      Serial.print("LAT: ");
      Serial.println(flat, 5);  
      Serial.print("LONG: ");
      Serial.println(flon, 5);
      Serial.print("TIME: ");
      Serial.println(time);
      Serial.print("ALT: ");
      Serial.println(falt);
      
    }
  }
}
« Last Edit: July 04, 2010, 09:03:45 am by cuddykid » Logged

Adelaide, South Australia
Offline Offline
Full Member
***
Karma: 0
Posts: 139
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

nice work cuddykid, working code is somehow a thing of beauty  8-)
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

was this code used with the mega btw ?
Logged

Pages: [1]   Go Up
Jump to: