Pages: [1]   Go Down
Author Topic: arduino gps help  (Read 2108 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 67
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

heyy,
Guys im really trying to sort out my gps problems, please help . Whenever i connect my arduino to a 5v TTL gps receiver and use the following code
Code:
#include <NewSoftSerial.h>

NewSoftSerial mySerial =  NewSoftSerial(2, 3);

#define BUFFSIZ 90 // plenty big
char buffer[BUFFSIZ];
char buffidx;

void setup()
{
 Serial.begin(4800);
 mySerial.begin(4800);
 Serial.println("\n\rNewSoftSerial + GPS test");
}

void loop()
{
 Serial.print("\n\rread: ");
 readline();
}

void readline(void) {
 char c;
 buffidx = 0; // start at begninning
 while (1) {
     c=mySerial.read();
     if (c == -1)
       continue;
     Serial.print(c,BYTE);
     if (c == '\n')
       continue;
     if ((buffidx == BUFFSIZ-1) || (c == '\r')) {
       return;
     }
     buffidx++;
 }
}


It gives me absolutely gibbrish stuff on my serial monitor that scrolls down after every few seconds , it gives stuff like:

read:   *Je')-*J@II*,
read: J 1/4 IZK+z+KIJ*-JJ*JJ1II)Z+

,etc , etc ,,,,,,,it goes on like this , what should i do to get readable information??..........Please help...........im very desperate........!! :'(
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 642
Posts: 50434
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Whenever i connect my arduino to a 5v TTL gps receiver and use the following code
The obvious things to check are that the GPS is indeed a TTL device and the baud rate. We can't help you there, since we have no idea which GPS you are using.

Another possibility is that the device uses inverted logic. There is an optional third argument for the NewSoftSerial constructor that allows it to handle inverted logic.
« Last Edit: December 11, 2010, 11:43:54 am by PaulS » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 67
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

heyy,
This is the gps i am using please help me out......http://www.rhydolabz.com/index.php?main_page=product_info&cPath=122&products_id=475
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 642
Posts: 50434
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Seems simple enough to connect, but you haven't described how you connected it.

Quote
Features

    * Single 5VDC supply @ 55 mA (typical)
    * TTL asynchronous serial interface
    * Data output Baud rate:[glow] 9600[/glow] bps(Default)
Code:
mySerial.begin([glow]4800[/glow]);
More likely to get good data if these match.
Logged

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

had garbled output like everyone else... but now...


Acquired Data
-------------
Lat/Long(10^-5 deg): 4312611, -8029204 Fix age: 298ms.
Lat/Long(float): 43.12611, -80.29204 Fix age: 415ms.
Date(ddmmyy): 130111 Time(hhmmsscc): 1090400 Fix age: 544ms.
Date: 1/13/2011  Time: 1:9:4.0  Fix age: 648ms.
Alt(cm): 22040 Course(10^-2 deg): 27382 Speed(10^-2 knots): 37
Alt(float): 220.40 Course(float): 273.82
Speed(knots): 0.37 (mph): 0.43 (mps): 0.19 (kmph): 0.69
Stats: characters: 5699 sentences: 41 failed checksum: 4
-------------


Problem was that data was INVERTED...

do this:
NewSoftSerial nss(2, 3, true);


Here is my modified code:

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

/* This sample code demonstrates the normal use of a TinyGPS object.
   It requires the use of NewSoftSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 2(rx) and 3(tx).
*/

TinyGPS gps;
NewSoftSerial nss(2, 3, true); // my gps data is inverted!!

void gpsdump(TinyGPS &gps);
bool feedgps();
void printFloat(double f, int digits = 2);

void setup()
{
  Serial.begin(4800);
  nss.begin(4800);
  
  Serial.print("Testing TinyGPS library v. "); Serial.println(TinyGPS::library_version());
  Serial.println("by Mikal Hart");
  Serial.println();
  Serial.print("Sizeof(gpsobject) = "); Serial.println(sizeof(TinyGPS));
  Serial.println();
}

void loop()
{
  bool newdata = false;
  unsigned long start = millis();

  // Every 5 seconds we print an update
  while (millis() - start < 5000)
  {
    if (feedgps())
      newdata = true;
  }
  
  if (newdata)
  {
    Serial.println("Acquired Data");
    Serial.println("-------------");
    gpsdump(gps);
    Serial.println("-------------");
    Serial.println();
  }
}

void printFloat(double number, int digits)
{
  // Handle negative numbers
  if (number < 0.0)
  {
     Serial.print('-');
     number = -number;
  }

  // Round correctly so that print(1.999, 2) prints as "2.00"
  double rounding = 0.5;
  for (uint8_t i=0; i<digits; ++i)
    rounding /= 10.0;
  
  number += rounding;

  // Extract the integer part of the number and print it
  unsigned long int_part = (unsigned long)number;
  double remainder = number - (double)int_part;
  Serial.print(int_part);

  // Print the decimal point, but only if there are digits beyond
  if (digits > 0)
    Serial.print(".");

  // Extract digits from the remainder one at a time
  while (digits-- > 0)
  {
    remainder *= 10.0;
    int toPrint = int(remainder);
    Serial.print(toPrint);
    remainder -= toPrint;
  }
}

void gpsdump(TinyGPS &gps)
{
  long lat, lon;
  float flat, flon;
  unsigned long age, date, time, chars;
  int year;
  byte month, day, hour, minute, second, hundredths;
  unsigned short sentences, failed;

  gps.get_position(&lat, &lon, &age);
  Serial.print("Lat/Long(10^-5 deg): "); Serial.print(lat); Serial.print(", "); Serial.print(lon);
  Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");
  
  feedgps(); // If we don't feed the gps during this long routine, we may drop characters and get checksum errors

  gps.f_get_position(&flat, &flon, &age);
  Serial.print("Lat/Long(float): "); printFloat(flat, 5); Serial.print(", "); printFloat(flon, 5);
  Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");

  feedgps();

  gps.get_datetime(&date, &time, &age);
  Serial.print("Date(ddmmyy): "); Serial.print(date); Serial.print(" Time(hhmmsscc): "); Serial.print(time);
  Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");

  feedgps();

  gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
  Serial.print("Date: "); Serial.print(static_cast<int>(month)); Serial.print("/"); Serial.print(static_cast<int>(day)); Serial.print("/"); Serial.print(year);
  Serial.print("  Time: "); Serial.print(static_cast<int>(hour)); Serial.print(":"); Serial.print(static_cast<int>(minute)); Serial.print(":"); Serial.print(static_cast<int>(second)); Serial.print("."); Serial.print(static_cast<int>(hundredths));
  Serial.print("  Fix age: ");  Serial.print(age); Serial.println("ms.");
  
  feedgps();

  Serial.print("Alt(cm): "); Serial.print(gps.altitude()); Serial.print(" Course(10^-2 deg): "); Serial.print(gps.course()); Serial.print(" Speed(10^-2 knots): "); Serial.println(gps.speed());
  Serial.print("Alt(float): "); printFloat(gps.f_altitude()); Serial.print(" Course(float): "); printFloat(gps.f_course()); Serial.println();
  Serial.print("Speed(knots): "); printFloat(gps.f_speed_knots()); Serial.print(" (mph): ");  printFloat(gps.f_speed_mph());
  Serial.print(" (mps): "); printFloat(gps.f_speed_mps()); Serial.print(" (kmph): "); printFloat(gps.f_speed_kmph()); Serial.println();

  feedgps();

  gps.stats(&chars, &sentences, &failed);
  Serial.print("Stats: characters: "); Serial.print(chars); Serial.print(" sentences: "); Serial.print(sentences); Serial.print(" failed checksum: "); Serial.println(failed);
}
  
bool feedgps()
{
  while (nss.available())
  {
    if (gps.encode(nss.read()))
      return true;
  }
  return false;
}
« Last Edit: January 12, 2011, 08:19:53 pm by mikecurry74 » Logged

Pages: [1]   Go Up
Jump to: