TinyGPS++ & LiquidCrystal libraries

Hello all,

This is my first question to the forum, so bare with me. :-)

I am trying to make a GPS data transponder to send Date and Time data to a Nixie Clock I will be building shortly. The transponder will be at the attic where it can receive the GPS signals easily and will broadcast the serial data it receives with a HC-12 433Mhz serial transmitter. Which then will be received with another HC-12 in my Nixie Clock and will be used update the RTC once or twice a day. The GPS module I am using is a NEO-6M.

All this was working well, so, I decided to add an 16x2 LCD to the transponder unit to be able to see the time and satellite count etc. on it too... Then things went haywire...

At the initial test, I used the LiquidCrystal_I2C library to drive the display. The Neo6 is connected to the arduino (Nano) thru software serial (because I need the hardware serial to feed the data to the HC-12). Everything initializes OK, I have no trouble with printing an intro screen to the LCD in the setup section of the code, but whenever I print anything to it in the loop section (even an irrelevant random text) , the satellite count and the elevation data from the Neo6 starts returning 0 (zero). All the other data like, time, date and coordinates keeps feeding OK, but just these two return 0. There is nothing wrong in my code (edit: I meant "As far as I can see"). If I comment out just the lcd.print(whatever); line(s) in the loop section, the missing data starts feeding again in the serial monitor.

So, I said OK, this must be a quirk coming from the LiquidCrystal_I2C library (it is known not to play well with others) and removed the IC2 backboard from the display and connected it directly to the Arduino using the internal LiquidCrystal library. Well, nothing changed... Again, as long as I don't print anything to the LCD in the loop section, the satcount and elevation data feeds in without missing a beat, but, if I print even just one character to the LCD in the loop section, these two start feeding zeros, despite all the other data keep coming in OK.

I am at a loss here... Granted, I actually do not need these two values for my Nixie clock at all. All I need for the clock is the Time & date which keeps feeding perfectly and can be displayed on the LCD. But I really would like to display at least the satellite count on the transponder's display so that I can know whether I placed it at the right place where it can see the max number of satellites.

Anyone with a similar problem? Anyone with any sort of idea of why this is happening and how to fix it?

Thanks a lot!

Please post the code that exhibits the problem.

There is nothing wrong in my code

That is a very brave statement !

#include <Wire.h>
#include <LiquidCrystal.h>
#include "TinyGPS++.h"
#include "SoftwareSerial.h"

const int rs = 12;
const int en = 11;
const int d4 = 10;
const int d5 = 9;
const int d6 = 8;
const int d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

SoftwareSerial SoftSerial(2, 3); //RX=pin 2, TX=pin 3

TinyGPSPlus GPS;

unsigned long satcount = 0;
void setup()
{
  Serial.begin(9600);
  SoftSerial.begin(9600);
  lcd.begin(16, 2);
  Serial.println("GPS Start");
  lcd.setCursor(0, 0);
  lcd.print("GPS Transponder");
  delay (1000);
  lcd.clear();
}

void loop()
{
  while (SoftSerial.available()) //While there are characters to come from the GPS
  {
    GPS.encode(SoftSerial.read());//This feeds the serial NMEA data into the library one char at a time
  }
  if (GPS.location.isUpdated()) //This will pretty much be fired all the time anyway but will at least reduce it to only after a package of NMEA data comes in
  {
    Serial.print("Satellite Count: ");
    Serial.println(GPS.satellites.value());

    Serial.print("Latitude: ");
    Serial.println(GPS.location.lat(), 4); 
    Serial.print("Longitude: ");
    Serial.println(GPS.location.lng(), 4);

    Serial.print("Altitude Meters: ");
    Serial.println(GPS.altitude.meters());

    Serial.print("Time: ");
    Serial.print(GPS.time.hour());
    Serial.print(":");
    Serial.print(GPS.time.minute());
    Serial.print(":");
    Serial.println(GPS.time.second());

    Serial.print("Date: ");
    Serial.print(GPS.date.day());
    Serial.print("/");
    Serial.print(GPS.date.month());
    Serial.print("/");
    Serial.println(GPS.date.year());

    Serial.println("");

    satcount = GPS.satellites.value();
    lcd.setCursor(0, 0);
    lcd.print("Sat Count:");  // If I comment this,
    lcd.print(satcount);      // and this, the satcount and altitude data starts feeding correct in at the serial monitor
                              // If I uncomment them, they return zeros
  }
}

BoraY: There is nothing wrong in my code

Fair enough, then there is no point in us telling you how to fix the problem by changing your code.

srnet:
Fair enough, then there is no point in us telling you how to fix the problem by changing your code.

Ok, you’re right.
I correct that:

“As far as I can see, there is nothing wrong in my code. But I am a newbie, most probably there is something wrong with it, so, please tell me where I did wrong.”

:slight_smile:

When you chack for the GPS location being updated, and if it is print a pile of stuff to the serial monitor and screen, how do you know if the altitude and number of sats has been updated too ?

I don't know what is updated and what is not actually. That is all handled by the library by parsing a long string of data coming from the GPS in the first while() command. What I understand from the library documentation is this long data has a "start" character and an "end" character. The while() command runs from the start to the end, character by character and decodes the whole received data into usable fragments. There may be a checksum portion in this to control whether the received data is whole or partial.

What I base my assumption is that, the date, time and coordinates data never misses a beat. I even carried the thing around to see if the coordinates change, and yes they do. So, if those are available, there must be at least one or more satellite(s) that are received, but the satcount shows zero if I print anything to the LCD. If I don't print anything the satcount and the altitude returns to normal.

I don't know if I could make myself clear, English is not my first language, I may be having trouble explaning things. :-[

There are several long strings of data coming from the GPS, they are the NMEA sentences.

What happens with the library is that it reads in the RMC sentence (often appears before the GGA) and at the end of it retrieves the location (if checksum is OK) and sets the location as updated and clears the altitude and sats in preparation for the GGA sentence arriving, its the GGA that provides the altitude and sat count.

But the GGA is not read since your program goes off doing stuff, and the GGA can be missed, so altitude and sats are not updated.

Try;

if (gps.location.isUpdated() && gps.altitude.isUpdated())

Ok, now I understand what's going on much better...

Your suggestion works, kind of...

Now I can see that even if I print to the LCD the "missing" satcount and altitude actually updates from time to time, it appears I was missing that before. With this change to the code, it only prints to the serial monitor and LCD only when the altitude is updated (and location of course, but that had no problems)

Thanks for this, I really appreciate it.

I still don't get how GGA is missed only when printing to the LCD, and not when printing to the serial monitor.

I keep thinking that there must be a better way of doing this, where things do not get in the way of other stuff going on. My code is the simplest possible way, derived from the library example code. Far from being purpose built. Anyways, as the saying goes, "If it works, it ain't stupid" ;D

Thanks again! Best regards from Ankara, TA2AWX