TinyGPS

Hello!
I have a problem with tinyGPS. I tried to run FullExample and it returns viua serial good data.
I hooked up a nokia lcd to arduino and had no trouble at all with displaying longitude, latitude and distance from fixed coordinates. Now i wanted to add altitude and number of satellites and i have a problem. the numbers come out zero mostly and satellite is sometimes 27 or 30 or some strange number (it should be 8-9 as i see it in fullExample serial print). What could be the problem? My code below.

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
static char intVal [5];

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

// display
Adafruit_PCD8544 display = Adafruit_PCD8544(A3, A2, A1, A0, 13);

static const double HOME_LAT = 45.8390, HOME_LON = 16.5387;

void setup()
{
  ss.begin(GPSBaud);

  Serial.begin(9600);
  display.begin();
  display.setContrast(55);
  display.clearDisplay();

}

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(){
  display.clearDisplay();
  display.setTextSize(0);
  display.setTextColor(BLACK);
  display.setCursor(0,0);
  display.print(gps.location.lat(),6);
  display.setCursor(0,8);
  display.print(gps.location.lng(),6); 

  display.setCursor(60,0);
  display.print(gps.altitude.meters());

  display.setCursor(60,8);
  display.print(gps.satellites.value());
  
  unsigned long distanceFromHome = TinyGPSPlus::distanceBetween(
        gps.location.lat(),
        gps.location.lng(),
        HOME_LAT, 
        HOME_LON);
  display.setCursor(0,40);
  display.print((float)distanceFromHome/1000, 3);
  display.display();
}

My copy of TinyGPS has:

  // satellites used in last full GPGGA sentence
  inline unsigned short satellites() { return _numsats; }

Why are you calling the value() method on a non-class instance?

A better question, perhaps, is why does your thread title say TinyGPS, when that is not the class that you are actually using?

Does the Adafruit_PCD8544 class properly deal with unsigned longs?

I'm sorry, it's TinyGPS++. I'm bad at c and new to arduino. I took all of it from FullExample for TinyGPS++.

 printInt(gps.satellites.value(), gps.satellites.isValid(), 5);
  printInt(gps.hdop.value(), gps.hdop.isValid(), 5);
  printFloat(gps.location.lat(), gps.location.isValid(), 11, 6);
  printFloat(gps.location.lng(), gps.location.isValid(), 12, 6);
  printInt(gps.location.age(), gps.location.isValid(), 5);
  printDateTime(gps.date, gps.time);
  printFloat(gps.altitude.meters(), gps.altitude.isValid(), 7, 2);
  printFloat(gps.course.deg(), gps.course.isValid(), 7, 2);
  printFloat(gps.speed.kmph(), gps.speed.isValid(), 6, 2);
  printStr(gps.course.isValid() ? TinyGPSPlus::cardinal(gps.course.value()) : "*** ", 6);

How is your GPS configured? Have you verified that it is sending the altitude and number of satellites? Those fields are in the GGA string whereas the fields you are seeing are in the RMC string.

As I said, I tried FullExample (just modified serial speed to 9600 baud) and it works good.

Sats HDOP Latitude   Longitude   Fix  Date       Time     Date Alt    Course Speed Card  Distance Course Card  Chars Sentences Checksum
          (deg)      (deg)       Age                      Age  (m)    --- from GPS ----  ---- to London  ----  RX    RX        Fail
---------------------------------------------------------------------------------------------------------------------------------------
**** **** ********** *********** **** ********** ******** **** ****** ****** ***** ***   ******** ****** ***   0     0         0        
10   116  45.839000  16.538690   588  07/27/2015 18:24:39 703  138.80 0.00   0.02  N     1372     303.36 WNW   529   2         0        
10   116  45.839000  16.538690   594  07/27/2015 18:24:40 710  138.90 0.00   0.11  N     1372     303.36 WNW   1058  4         0        
10   108  45.839000  16.538692   603  07/27/2015 18:24:41 718  138.90 0.00   0.07  N     1372     303.36 WNW   1589  6         0        
9    108  45.839000  16.538690   615  07/27/2015 18:24:42 731  139.00 0.00   0.22  N     1372     303.36 WNW   2116  8         0        
9    108  45.839000  16.538690   627  07/27/2015 18:24:43 742  139.20 0.00   0.04  N     1372     303.36 WNW   2641  10        0        
9    108  45.839000  16.538692   634  07/27/2015 18:24:44 750  139.30 0.00   0.15  N     1372     303.36 WNW   3168  12        0        
9    108  45.839000  16.538692   642  07/27/2015 18:24:45 758  139.30 0.00   0.13  N     1372     303.36 WNW   3695  14        0

So, modify that sketch to only print, to the serial port, the things that you are interested in.

Then, add the LCD display. If adding the LCD display causes problems, then, you know more than you know now.

Ok, so I added

  Serial.println(gps.location.lat());
  Serial.println(gps.location.lng());
  Serial.println((float)gps.altitude.meters());
  Serial.println((float)gps.satellites.value());
  Serial.println((float)distanceFromHome/1000, 3);

and it prints out

45.84
16.54
0.00
0.00
0.004
45.84
16.54
0.00
0.00
0.004
45.84
16.54
0.00
0.00
0.003

Zeroes for what i want. If I get rid of the float cast it’s the same.
The example uses functions which I don’t know exactly what they do. But why would coordinates work without printFloat and altitude not?

static void printFloat(float val, bool valid, int len, int prec)
{
  if (!valid)
  {
    while (len-- > 1)
      Serial.print('*');
    Serial.print(' ');
  }
  else
  {
    Serial.print(val, prec);
    int vi = abs((int)val);
    int flen = prec + (val < 0.0 ? 2 : 1); // . and -
    flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
    for (int i=flen; i<len; ++i)
      Serial.print(' ');
  }
  smartDelay(0);
}

So i just added smart delay which is said to keep the GPS object fed.

  smartDelay(1000);
}

static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

And now it works. I tried that one before, maybe i havent waited enough.
It displays nicely now.
Thank you for taking the time to help!

Since there are two sentences the code has to collect them both and not just go running when it only gets one. That "smart delay" function is actually not very smart at all. It will work in some cases though.

Check out the NeoGPS library. It's a huge improvement over TinyGPS++.