Unexpected TinyGPS/LiquidCrystal interaction

I seem to have tripped over a small problem whilst using the TinyGPS and the LiquidCrystal libraries concurrently in the same sketch and find myself a little unclear as to why.

I have a Fastrax UP501 GPS module which I want to use as a RTC for a LCD clock. I have connected the GPS to a software serial port using the Arduino supplied library and I can happily output all the main NMEA data items - lat, lon, date, time, year, month, day, hour, minute, second - to the serial monitor.

However, as soon as I try and access any of the date or time variables with the lcd.print function the day, month and year revert to 0, 0 and 2000 on both the serial monitor and the LCD. Note that all the other data items continue to be output as expected on both the serial monitor and the LCD.

I am using arduino 1.0.3 and TinyGPS v12 running on a stock Uno. I have included a fully functional (or not as you choose to see it) sketch which should demonstrate the issue by simply commenting in/out the LiquidCrystal code.

I would be extremely grateful if anyone can provide any insight or offer suggestions as to where I might be going wrong here.

// Arduino 1.0.3
// TinyGPS v12

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

const int rxpin = 2;
const int txpin = 14;

SoftwareSerial ss(rxpin, txpin);

TinyGPS gps;

LiquidCrystal lcd(9, 8, 7, 6, 5, 4);

void setup()
{
  Serial.begin(9600);
  ss.begin(9600);
  
  lcd.begin(20,4);
  
  lcd.clear();

  lcd.setCursor(3, 1);
  lcd.print("Hello World");

}

void loop()
{
  while (ss.available())
  {
    char c = ss.read();
    // Serial.write(c);
    if (gps.encode(c))
    {
      long lat, lon;
      
      unsigned long date, time;
      unsigned long fix_age;
      
      int year;
      
      byte month, day, hour, minute, second, hundredths;
      
      gps.get_position(&lat, &lon, &fix_age);
      gps.get_datetime(&date, &time);      
      gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &fix_age);
      
      if (fix_age == TinyGPS::GPS_INVALID_AGE)
      {
        Serial.println("No fix established");
      }
      else if (fix_age > 2000)
      {
        Serial.println("Stale data");
      }
      else
      {
        
        Serial.print("Latitude: ");
        Serial.print(lat);
        Serial.print("   ");
        Serial.print("Longitude: ");
        Serial.println(lon);
        
        Serial.print("Date: ");
        Serial.print(date);
        Serial.print("   ");
        Serial.print("Time: ");
        Serial.println(time);
        
        if (day < 10) Serial.print('0');
        Serial.print(day);
        Serial.print("/");
        if (month < 10) Serial.print('0');
        Serial.print(month);
        Serial.print("/");
        Serial.print(year);
        Serial.print("   ");
        if (hour < 10) Serial.print('0');
        Serial.print(hour);
        Serial.print(":");
        if (minute < 10) Serial.print('0');
        Serial.print(minute);
        Serial.print(":");
        if (second < 10) Serial.print('0');
        Serial.print(second);
        Serial.print(" ");
        Serial.println(hundredths);
        
        Serial.print("Fix_age: ");
        Serial.println(fix_age);
        
        /*
        lcd.setCursor(0,1);
        lcd.print("UTC: ");
        if (hour < 10) lcd.print('0');
        lcd.print(hour);
        lcd.print(":");
        if (minute < 10) lcd.print('0');
        lcd.print(minute);
        lcd.print(":");
        if (second < 10) lcd.print('0');
        lcd.print(second);
        lcd.print(" ");
        
        lcd.setCursor(0,2);
        if (day < 10) lcd.print('0');
        lcd.print(day);
        lcd.print("/");
        if (month < 10) lcd.print('0');
        lcd.print(month);
        lcd.print("/");
        lcd.print(year);
        */
        
      }
    }
  }
}

Which Arduino board do you have?

The op said an Uno.

Two possibilities:-

  1. some kind of conflict between the lcd lib and the GPS lib

  2. You have power problems, those LCDs seem very power hungry.

What happens if you have both the GPS and the LCD code running but don't power the LCD.

Mark

FYI, GPS only gets reception when there is open sky so if your clock is indoors then it will get poor reception and using it as RTC would only work intermittently.

Do you have a current limit resistor on your LCD back light?