Hi,
I made a rather complicated sketch that printed gps info to an LCD, but the altitude information kept getting corrupted randomly, so I made the simplest sketch I could to isolate the problem, and it seems to have got worse. It seems very weird to me, but hopefully someone here is clever enough to spot it, so here goes:
the code is:
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
/*
This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
It requires the use of SoftwareSerial, and assumes that you have a
4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
static const int RXPin = 2, TXPin = 3;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup()
{
Serial.begin(9600);
ss.begin(GPSBaud);
Serial.println(F("DeviceExample.ino"));
Serial.println(F("A simple demonstration of TinyGPS++ with an attached GPS module"));
Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
Serial.println(F("by Mikal Hart"));
Serial.println();
}
void loop()
{
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0)
if (gps.encode(ss.read()))
displayInfo();
if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
while(true);
}
}
void displayInfo()
{
// lcd.print (gps.altitude.meters());
Serial.print(F("altitude: "));
if (gps.location.isValid())
{
Serial.print(gps.altitude.meters());
Serial.print(F(","));
}
else
{
Serial.print(F("INVALID"));
}
//if (gps.altitude.meters() < 1000);
lcd.print (gps.altitude.meters()); //this caused the problems
Serial.print(F(" "));
if (gps.time.isValid())
{
if (gps.time.hour() < 10) Serial.print(F("0"));
Serial.print(gps.time.hour());
Serial.print(F(":"));
if (gps.time.minute() < 10) Serial.print(F("0"));
Serial.print(gps.time.minute());
Serial.print(F(":"));
if (gps.time.second() < 10) Serial.print(F("0"));
Serial.print(gps.time.second());
Serial.print(F("."));
if (gps.time.centisecond() < 10) Serial.print(F("0"));
Serial.print(gps.time.centisecond());
}
else
{
Serial.print(F("INVALID"));
}
Serial.println();
}
Now about 3/4 down I have commented a line with "this caused the problems". when the line is disabled, the serial monitor prints the altitude correctly. But when it is enabled, the serial monitor simple prints the altitude as "0.00".
I can't work out why the lcd print function affects the altitude value stored and printed via serial.
thanks