Arduino Mega 2560 + Graphic LCD + GPS Shield + DS1307 RTC

Hye all. I'm a beginner in arduino. I need help and guidance to display some data on GLCD. I'm using Arduino Mega, 128x64 GLCD, GPS shield and RTC. All my hardware works very well on debugging. Can someone please guide me on how to do programming on saving some data that i got from the GPS receiver into a register before displays them onto GLCD. My project is Digital Alarm Clock using GPS receiver. GPS receiver works as latitude and longitude information provider as the time changes whenever we travels to another country.

I'm using TinyGPS and U8glib.

For any help, guidance and advice, Thank You Very Much in advance! :)

i made this coding but it cannot be compiled. :~

#include <SoftwareSerial.h>
#include <U8glib.h>
#include <TinyGPS.h>

U8GLIB_ST7920_128X64_4X u8g(28, 29, 30, 31, 24, 25, 26, 27, 18, 17, 16); // 8Bit Com: D0..D7: 28,29,30,31,24,25,26,27 en=18, di=17,rw=16
TinyGPS gps;
SoftwareSerial nss(2, 3);
void gpsdump(TinyGPS &gps);
bool feedgps();
void printFloat(double f, int digits = 2);
void setup()
{
  Serial.begin(115200);
  nss.begin(4800);
  
  //Print a message to the LCD.
  u8g.setFont(u8g_font_unifont);
  u8g.drawStr( 0, 22, "Hello!");
  u8g.setFont(u8g_font_unifont);
  u8g.drawStr( 0, 33, "coordinate GPS");
  //We test the version of the library
  Serial.print("Testing TinyGPS library v. ");
  Serial.println(TinyGPS::library_version());
  Serial.println(sizeof(TinyGPS));
  Serial.println();
}
void loop()
{
  bool newdata = false;
  unsigned long start = millis();
  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)
  {
     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;
 
  // Print the decimal point, but only if there are digits beyond
  if (digits > 0)
 
  // Extract digits from the remainder one at a time
  while (digits-- > 0)
  {
    remainder *= 10.0;
    int toPrint = int(remainder);
    remainder -= toPrint; 
  } 
}
 
 
void gpsdump(TinyGPS &gps)
{
  float flat, flon;
  gps.f_get_position(&flat, &flon);
  Serial.print("Lat/Long(float): ");
  printFloat(flat, 5);
  Serial.print(", ");
  printFloat(flon, 5);
  
  u8g.setFont(u8g_font_unifont);
  u8g.drawStr( 0, 40, "Lat:");
  u8g.setPrintPos(0, 45); // set where we want to begin printing
  u8g.drawStr(flat, 5); //print to five decimal places
  
  u8g.setFont(u8g_font_unifont);
  u8g.drawStr( 0, 50, "Long:");
  u8g.setPrintPos(0, 55); // set where we want to begin printing
  u8g.drawStr(flon, 5); //print to five decimal places
  
  feedgps();
}
bool feedgps()
{
  while (nss.available())
  {
    if (gps.encode(nss.read()))
      return true;
  }
  return false;
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

gps+lcd.txt (2.53 KB)

Why are you using SoftwareSerial with a Mega? use serial 1 instead. I have a GPS receiver, DHT22, BMP085, and a 4.3" GLCD from Itead Studios with the Ver 2.1 shield. Mine works well inside enough but the position will change as the sat moves overhead because of the interference due to reflections from the building... Or at least that's my and some others experience. In my experience the lat and long data is nice to look at but it's easier to get local time. because of the difficulty of always getting valid GPS time data (mine won't work anywhere but my room and the front or back doors) I use the Time Library from the playground to keep time and the GPS to refresh it periodically. I will be changing to a DS3231 RTC for the accuracy and convenience and I'll move the GPS to the background or eliminate it entirely because of the accuracy of the DS3231. The Time lib has a correction for slow or fast resonators on Arduino boards. I have tested two clone mega's and both were only seconds out in 24 hours. this is a part of the code I use for GPS, references to nss should read serial1. but it demonstrated the idea. Although you use a different method than I do the idea is the same.

 while (Serial1.available())
  {  // timing seems to be critical here, i.e. don't do lots of prints
    // or chars may be lost, resulting in "invalid" sentences
    if (gps.encode(Serial1.read()))
    {
      // gps.encode() returns true after processing a valid sentence

HTH

Doc

i made this coding but it cannot be compiled.

Oh, good. I love guessing games. Not!

Why can't it be compiled? Why don't you fix the errors?

Regarding U8glib: You must enclose the draw commands into the "picture loop". See here: http://code.google.com/p/u8glib/wiki/thelloworld

Example:

  // picture loop
  u8g.firstPage();  
  do {
    //Print a message to the LCD.
    u8g.setFont(u8g_font_unifont);
    u8g.drawStr( 0, 22, "Hello!");
    u8g.setFont(u8g_font_unifont);
    u8g.drawStr( 0, 33, "coordinate GPS");
     ...
  } while( u8g.nextPage() );

You can also use the "print()" command to draw strings on the GLCD.

Oliver

Oliver