Arduino mega 2560 r3 + em-408 + gps shield

Hi

I've tried the example code given in TinyGps library (test_with_gps), but seems like the output in serial monitor only shows stars instead of values. anyone know how to solve it? here is the code that I used:

#include <SoftwareSerial.h>

#include <TinyGPS.h>

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

TinyGPS gps;
SoftwareSerial nss(3, 4);

static void gpsdump(TinyGPS &gps);
static bool feedgps();
static void print_float(float val, float invalid, int len, int prec);
static void print_int(unsigned long val, unsigned long invalid, int len);
static void print_date(TinyGPS &gps);
static void print_str(const char *str, int len);

void setup()
{
  Serial.begin(115200);
  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();
  Serial.println("Sats HDOP Latitude Longitude Fix  Date       Time       Date Alt     Course Speed Card  Distance Course Card  Chars Sentences Checksum");
  Serial.println("          (deg)    (deg)     Age                        Age  (m)     --- from GPS ----  ---- to London  ----  RX    RX        Fail");
  Serial.println("--------------------------------------------------------------------------------------------------------------------------------------");
}

void loop()
{
  bool newdata = false;
  unsigned long start = millis();
  
  // Every second we print an update
  while (millis() - start < 1000)
  {
    if (feedgps())
      newdata = true;
  }
  
  gpsdump(gps);
}

static void gpsdump(TinyGPS &gps)
{
  float flat, flon;
  unsigned long age, date, time, chars = 0;
  unsigned short sentences = 0, failed = 0;
  static const float LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
  
  print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 5);
  print_int(gps.hdop(), TinyGPS::GPS_INVALID_HDOP, 5);
  gps.f_get_position(&flat, &flon, &age);
  print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 9, 5);
  print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 10, 5);
  print_int(age, TinyGPS::GPS_INVALID_AGE, 5);

  print_date(gps);

  print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 8, 2);
  print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
  print_float(gps.f_speed_kmph(), TinyGPS::GPS_INVALID_F_SPEED, 6, 2);
  print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6);
  print_int(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0UL : (unsigned long)TinyGPS::distance_between(flat, flon, LONDON_LAT, LONDON_LON) / 1000, 0xFFFFFFFF, 9);
  print_float(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : TinyGPS::course_to(flat, flon, 51.508131, -0.128002), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
  print_str(flat == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON)), 6);

  gps.stats(&chars, &sentences, &failed);
  print_int(chars, 0xFFFFFFFF, 6);
  print_int(sentences, 0xFFFFFFFF, 10);
  print_int(failed, 0xFFFFFFFF, 9);
  Serial.println();
}

static void print_int(unsigned long val, unsigned long invalid, int len)
{
  char sz[32];
  if (val == invalid)
    strcpy(sz, "*******");
  else
    sprintf(sz, "%ld", val);
  sz[len] = 0;
  for (int i=strlen(sz); i<len; ++i)
    sz[i] = ' ';
  if (len > 0) 
    sz[len-1] = ' ';
  Serial.print(sz);
  feedgps();
}

static void print_float(float val, float invalid, int len, int prec)
{
  char sz[32];
  if (val == invalid)
  {
    strcpy(sz, "*******");
    sz[len] = 0;
        if (len > 0) 
          sz[len-1] = ' ';
    for (int i=7; i<len; ++i)
        sz[i] = ' ';
    Serial.print(sz);
  }
  else
  {
    Serial.print(val, prec);
    int vi = abs((int)val);
    int flen = prec + (val < 0.0 ? 2 : 1);
    flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
    for (int i=flen; i<len; ++i)
      Serial.print(" ");
  }
  feedgps();
}

static void print_date(TinyGPS &gps)
{
  int year;
  byte month, day, hour, minute, second, hundredths;
  unsigned long age;
  gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
  if (age == TinyGPS::GPS_INVALID_AGE)
    Serial.print("*******    *******    ");
  else
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d %02d:%02d:%02d   ",
        month, day, year, hour, minute, second);
    Serial.print(sz);
  }
  print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
  feedgps();
}

static void print_str(const char *str, int len)
{
  int slen = strlen(str);
  for (int i=0; i<len; ++i)
    Serial.print(i<slen ? str[i] : ' ');
  feedgps();
}

static bool feedgps()
{
  while (nss.available())
  {
    if (gps.encode(nss.read()))
      return true;
  }
  return false;
}

Moderator edit: [code] ... [/code] tags added. (Nick Gammon)

Could it be that your GPS has not been operating outdoors long enough to get an ephemeris download? Until it gets position data from the satellites it can't determine your location.

Try this sketch to see what your GPS is saying. If you don't get recognizable NEMA messages then something is wrong (baud rate, settings, etc.)

#include <SoftwareSerial.h>
SoftwareSerial nss(3, 4);
void setup()
{
  Serial.begin(115200);
  nss.begin(4800);
}

void loop()
{
   if (nss.available())
       Serial.write(nss.read());

   if (Serial.available())
       nss.write(Serial.read());
}

nothing shows up..i'm very new at this, and do not know what's going wrong

numb3rs295:
nothing shows up..i'm very new at this, and do not know what's going wrong

So your GPS module is not sending.

What exact GPS module are you using? How is it wired?

i'm using em-408 gps : GPS Receiver - EM-408 SiRF III (20 Channel) - GPS-08234 - SparkFun Electronics
connected to gps shield : SparkFun GPS Logger Shield - GPS-13750 - SparkFun Electronics?
and the gps shield is connected to arduino mega 2560 r3 : Arduino Mega 2560 R3 - DEV-11061 - SparkFun Electronics

johnwasser:

numb3rs295:
nothing shows up..i'm very new at this, and do not know what's going wrong

So your GPS module is not sending.

What exact GPS module are you using? How is it wired?

Is the switch on the shield set to DLINE, not UART?

set at DLINE mode..
however, i found another method, which used serial instead od softwareserial. i used this tutorial, since they used quite similar parts as mine : http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1283009227

however, what i didn't understand is whether to put in DLINE or UART mode, since serial used UART ports.
From my understanding, when uploading the code, used DLINE, and after that switch off the gps shield, and then change to UART, and then switch on the gps shield..

but when i change to UART, nothing shows in the serial monitor..

i've already desolder the jumper, and connect tx and rx pins to pin 15 and 14 at arduino, respectively

this is how i connect them..

johnwasser:
Is the switch on the shield set to DLINE, not UART?

UPDATED : When I changed the configuration (shown below), the serial monitor is working when run in UART mode, but still didn't get any data. At least it shows some words unlike before. So i reckon maybe i didn't get any signal because of the connection? any ideas?

or is it because of power supply?? i just use USB to computer as power supply..

i didn't know what's going wrong right know..i've tried every possible solution..

Can you be a bit clearer about what is connected to what? And post your current sketch inside code tags please? Judging by the Sparkfun site you need to be in DLINE mode and then can choose where to connect the pins.

This is my current sketch

/*
  6-8-10
  Aaron Weiss
  SparkFun Electronics
  
  Example GPS Parser based off of arduiniana.org TinyGPS examples.
  
  Parses NMEA sentences from an EM406 running at 4800bps into readable 
  values for latitude, longitude, elevation, date, time, course, and 
  speed. 
  
  For the SparkFun GPS Shield. Make sure the switch is set to DLINE.
  
  Once you get your longitude and latitude you can paste your 
  coordinates from the terminal window into Google Maps. Here is the 
  link for SparkFun's location.  
  http://maps.google.com/maps?q=40.06477,+-105.20997
  
  Uses the NewSoftSerial library for serial communication with your GPS, 
  so connect your GPS TX and RX pin to any digital pin on the Arduino, 
  just be sure to define which pins you are using on the Arduino to 
  communicate with the GPS module. 
*/ 

// In order for this sketch to work, you will need to download 
// NewSoftSerial and TinyGPS libraries from arduiniana.org and put them 
// into the hardware->libraries folder in your ardiuno directory.
// Here are the lines of code that point to those libraries.
//
//
// 28/08/2010
// I could not get the NewSoftSerial Drivers to work
// on my Arduino Mega with the Sparkfun GPS shield.
// I desoldered the 2 jumpers, then jumpered the GPS's Rx to Pin 14, Tx to Pin 15
// This is UART3 
// As PaulS pointed out, why use soft serial on a board with 4 UART's?
//
//
#include <TinyGPS.h>

//Set this value equal to the baud rate of your GPS
#define GPSBAUD 4800

// Create an instance of the TinyGPS object
TinyGPS gps;

// This is where you declare prototypes for the functions that will be 
// using the TinyGPS library.
void getgps(TinyGPS &gps);

// In the setup function, you need to initialize two serial ports; the 
// standard hardware serial port (Serial()) to communicate with your 
// terminal program and another hardware serial port (Serial3()) for your 
// GPS.
//
//

void setup()
{
  // This is the serial rate for your terminal program. It must be this 
  // fast because we need to print everything before a new sentence 
  // comes in. If you slow it down, the messages might not be valid and 
  // you will likely get checksum errors.
  Serial.begin(115200);
  //Sets baud rate of your GPS
  Serial3.begin(GPSBAUD);
  
  Serial.println("");
  Serial.println("GPS Shield QuickStart Example Sketch v12.u");
  Serial.println("       ...waiting for lock...           ");
  Serial.println("");
}

// This is the main loop of the code. All it does is check for data on 
// the RX pin of the ardiuno, makes sure the data is valid NMEA sentences, 
// then jumps to the getgps() function.
void loop()
{
  while(Serial3.available())     // While there is data on the RX pin...
  {
      int c = Serial3.read();    // load the data into a variable...
      if(gps.encode(c))      // if there is a new valid sentence...
      {
        getgps(gps);         // then grab the data.
      }
  }
}

// The getgps function will get and print the values we want.
void getgps(TinyGPS &gps)
{
  // To get all of the data into varialbes that you can use in your code, 
  // all you need to do is define variables and query the object for the 
  // data. To see the complete list of functions see keywords.txt file in 
  // the TinyGPS and NewSoftSerial libs.
  
  // Define the variables that will be used
  float latitude, longitude;
  // Then call this function
  gps.f_get_position(&latitude, &longitude);
  // You can now print variables latitude and longitude
  Serial.print("Lat/Long: "); 
  Serial.print(latitude,5); 
  Serial.print(", "); 
  Serial.println(longitude,5);
  
  // Same goes for date and time
  int year;
  byte month, day, hour, minute, second, hundredths;
  gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
  // Print data and time
  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);
  //Since month, day, hour, minute, second, and hundr
  
  // Here you can print the altitude and course values directly since 
  // there is only one value for the function
  Serial.print("Altitude (meters): "); Serial.println(gps.f_altitude());  
  // Same goes for course
  Serial.print("Course (degrees): "); Serial.println(gps.f_course()); 
  // And same goes for speed
  Serial.print("Speed(kmph): "); Serial.println(gps.f_speed_kmph());
  Serial.println();
  
  // Here you can print statistics on the sentences.
  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();
}

And this is the connection..i've identified it with different colours, which means each colour is matched with the same colour at other part..

What is it mean by "These jumpers, when disabled (solder removed), will disconnect the GPS communication lines (TX and RX) from the Arduino. This allows for the user to connect any digital line to the GPS communication lines. To use, simply disconnect the jumpers, then wire the TX and RX labeled pins on the shield to any one of the digital pins 2-13 on the shield." from : GPS Shield Hookup Guide - SparkFun Learn

Because I just de-solder the jumper, and then connect the gps shield with arduino just like what I show before. But when I read the above statement 2-3 times, I sense something wrong with my method

numb3rs295:
What is it mean by "These jumpers, when disabled (solder removed), will disconnect the GPS communication lines (TX and RX) from the Arduino. This allows for the user to connect any digital line to the GPS communication lines. To use, simply disconnect the jumpers, then wire the TX and RX labeled pins on the shield to any one of the digital pins 2-13 on the shield." from : GPS Shield Hookup Guide - SparkFun Learn

Because I just de-solder the jumper, and then connect the gps shield with arduino just like what I show before. But when I read the above statement 2-3 times, I sense something wrong with my method

There is a switch. When set to UART the RX and TX lines of the GPS are connected to D0 and D1. When set to DLINE the RX and TX lines of the GPS go through solder jumpers to D2 and D3. If you want to use pins other than D2 and D3 you have to switch to DLINE, remove the solder jumpers, AND ADD WIRES FROM THE GPS SIDE OF THE JUMPERS TO THE DATA PINS OF YOUR CHOICE.

for clarity...

hope that helps

:slight_smile: