Question concerning a GPS (NEO6M - red board) , a Nano and a LCD2004 I2C

Good evening, greetings from Thailand...

I am trying to build a GPS time/date/day display... and therefore, I have been reading many posts regarding GPS, possible libraries, how to write Sketches, what does the job, what does not work, ... and I have built a few sketches (by copying other's works and by trying things by myself) and ... finally I came up with a sketch which seems to suit my wishes...

BUT... (as in every story there is always something which does not work correctly), I am facing a little problem which I am not able to solve by myself...

Hence, I beg good willing Arduino wizards to rescue me...

First ... my code...

#include "LiquidCrystal_I2C.h"
#include <NMEAGPS.h>
NMEAGPS gps;
LiquidCrystal_I2C lcd(0x27, 20, 4);  // set the LCD address which is 0x27 for my LCD

#include <AltSoftSerial.h>
AltSoftSerial gpsPort;  //( 8, 9) currently using

//#include <NeoSWSerial.h> //(for testing)
//NeoSWSerial gpsPort( 8, 9 ); //(for testing)

//SoftwareSerial gpsPort( 4, 3 ); //(for testing)


char daysOfTheWeek[7][9] = { "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };

void setup() {
  lcd.init();       //initialize lcd
  lcd.backlight();  //open backlight  //
  Serial.begin(115200);
  gpsPort.begin(9600);
}

void loop() {
  // Dispatch incoming characters
  while (gps.available(gpsPort)) {
    gps_fix fix = gps.read();



    if (fix.valid.date && fix.valid.time) {
      // Shift the date/time to local time
      NeoGPS::clock_t localSeconds;
      NeoGPS::time_t localTime;



      {
        using namespace NeoGPS;

        localSeconds = (clock_t)fix.dateTime;                           // convert structure to a second count
        localSeconds += 7 * SECONDS_PER_HOUR + 0 * SECONDS_PER_MINUTE;  // shift timezone to Thailand, Chiang Mai
        localTime = localSeconds;                                       // convert back to a structure
      }



      char sz1[20];
      char sz2[20];

      sprintf(sz1, "%02d:%02d:%02d       %02d", localTime.hours, localTime.minutes, localTime.seconds, fix.satellites);

      sprintf(sz2, "%02d/%02d/20%02d", localTime.date, localTime.month, localTime.year);


      lcd.setCursor(1, 0);              // move cursor to   (0, 0)
      lcd.print("Thai Time -- S Fix");  // print message at (0, 0)
      lcd.setCursor(1, 1);              // move cursor to   (2, 1)
      lcd.print(sz1);                   // print message at (2, 1)

      lcd.setCursor(1, 2);  // move cursor to   (3, 2)
      lcd.print(" Date:");  // print message at (3, 0)
      lcd.setCursor(8, 2);  // move cursor to   (0, 3)
      lcd.print(sz2);       // print message at (0, 1)
      lcd.setCursor(5, 3);  // move cursor to   (0, 3)
      lcd.print(daysOfTheWeek[localTime.day]);
    }
  }
}

My problem is that somehow the Satellite counter does not seem to work correctly.
It works when I power up the NANO... for a couple of seconds I get 5 or 6 or 7 satellites inside my office (indoors, not really near a window) ... and then it quickly shows "0".
All what I want the LCD to show gets done correctly.
The red LED on the NEO board is happily blinking along (I guess 1x per second), meaning that it gets feed from satellites.

I tried to check if the NEO board was ok, and indeed, it is receiving a lot, as it should be.
The lines are well formed and look like any other "working" example I could see around.
--- below, the Sketch I used for testing the NEO board.

#include <SoftwareSerial.h>
SoftwareSerial ss(8, 9);

void setup()  
{ 
  Serial.begin(115200);
  ss.begin(9600);
}

void loop() {
  if (ss.available()) {
    char c = ss.read();
    Serial.write(c);
  }
}

Therefore, could somebody please help me to get the satellite counter showing the real number of satellites...

Thank you in advance,

Eric

additional info...
NeoSWSerial.h has the same effect... (shows 4-7 satellites for a few seconds and then "0")
and SoftwareSerial does the same.

GPS generally does not work indoors. Test the setup outside, where you have a clear view of the sky.

Show us the output from the GPS in the sketch.

Hey... thank you for the early reply...
Here, mine does...
I received well-formed Gps typical data ... (without any strange characters like black question marks)...

The one which should show that the GPS works?
One minute please...

There we go ...

$GPGSA,A,3,18,32,10,28,25,12,31,,,,,,2.85,1.18,2.60*04
$GPGSV,3,1,12,10,59,005,16,12,21,076,11,18,25,171,20,21,06,317,14*78
$GPGSV,3,2,12,23,57,086,16,24,05,040,,25,34,107,22,26,02,198,*76
$GPGSV,3,3,12,27,01,248,18,28,57,230,23,31,25,220,31,32,43,332,17*74
$GPGLL,1844.31079,N,09913.93880,E,152950.00,A,A*6E
$GPRMC,152951.00,A,1844.31064,N,09913.93855,E,0.408,,090524,,,A*74
$GPVTG,,T,,M,0.408,N,0.756,K,A*2B
$GPGGA,152951.00,1844.31064,N,09913.93855,E,1,07,1.18,357.8,M,-37.4,M,,*75
$GPGSA,A,3,18,32,10,28,25,12,31,,,,,,2.85,1.18,2.60*04
$GPGSV,3,1,12,10,59,005,13,12,21,076,11,18,25,171,20,21,06,317,15*7C
$GPGSV,3,2,12,23,57,086,15,24,04,040,,25,34,107,23,26,02,198,*75
$GPGSV,3,3,12,27,01,248,19,28,57,230,21,31,25,220,31,32,43,332,18*78
$GPGLL,1844.31064,N,09913.93855,E,152951.00,A,A*6B
$GPRMC,152952.00,A,1844.31057,N,09913.93838,E,0.469,,090524,,,A*7B
$GPVTG,,T,,M,0.469,N,0.868,K,A*2E
$GPGGA,152952.00,1844.31057,N,09913.93838,E,1,07,1.18,358.0,M,-37.4,M,,*7A
$GPGSA,A,3,18,32,10,28,25,12,31,,,,,,2.85,1.18,2.60*04
$GPGSV,3,1,12,10,59,005,14,12,21,076,11,18,25,171,20,21,06,317,16*78
$GPGSV,3,2,12,23,57,086,16,24,04,040,,25,35,106,22,26,02,198,*77
$GPGSV,3,3,12,27,01,248,18,28,57,230,20,31,25,220,31,32,43,332,18*78
$GPGLL,1844.31057,N,09913.93838,E,152952.00,A,A*63
$GPRMC,152953.00,A,1844.31045,N,09913.93823,E,0.393,,090524,,,A*71
$GPVTG,,T,,M,0.393,N,0.728,K,A*27
$GPGGA,152953.00,1844.31045,N,09913.93823,E,1,07,1.18,358.2,M,-37.4,M,,*70
$GPGSA,A,3,18,32,10,28,25,12,31,,,,,,2.85,1.18,2.60*04
$GPGSV,3,1,12,10,59,005,14,12,21,076,11,18,25,171,20,21,06,317,17*79
$GPGSV,3,2,12,23,57,086,15,24,04,040,,25,35,106,21,26,02,198,*77
$GPGSV,3,3,12,27,01,248,18,28,57,230,21,31,25,220,32,32,43,332,18*7A
$GPGLL,1844.31045,N,09913.93823,E,152953.00,A,A*6B
$GPRMC,152954.00,A,1844.31047,N,09913.93790,E,0.434,,090524,,,A*79
$GPVTG,,T,,M,0.434,N,0.805,K,A*2D
$GPGGA,152954.00,1844.31047,N,09913.93790,E,1,07,1.18,358.5,M,-37.4,M,,*75
$GPGSA,A,3,18,32,10,28,25,12,31,,,,,,2.85,1.18,2.60*04
$GPGSV,3,1,12,10,59,005,15,12,21,076,11,18,25,171,20,21,06,317,17*78
$GPGSV,3,2,12,23,57,086,12,24,04,040,,25,35,106,21,26,02,198,*70
$GPGSV,3,3,12,27,01,247,18,28,57,230,23,31,25,220,32,32,43,332,17*78
$GPGLL,1844.31047,N,09913.93790,E,152954.00,A,A*69
$GPRMC,152955.00,A,1844.31022,N,09913.93787,E,0.172,,090524,,,A*7A
$GPVTG,,T,,M,0.172,N,0.319,K,A*2C
$GPGGA,152955.00,1844.31022,N,09913.93787,E,1,07,1.18,358.4,M,-37.4,M,,*70
$GPGSA,A,3,18,32,10,28,25,12,31,,,,,,2.85,1.18,2.60*04
$GPGSV,3,1,12,10,59,005,16,12,21,076,10,18,25,171,21,21,06,317,17*7B
$GPGSV,3,2,12,23,57,086,12,24,04,040,,25,35,106,21,26,02,198,*70
$GPGSV,3,3,12,27,01,247,19,28,57,231,23,31,25,220,32,32,43,332,17*78
$GPGLL,1844.31022,N,09913.93787,E,152955.00,A,A*6D
$GPRMC,152956.00,A,1844.31031,N,09913.93758,E,0.324,,090524,,,A*78
$GPVTG,,T,,M,0.324,N,0.601,K,A*21

and it continues spitting out data... (as much as you want)

$GPRMC,153006.00,A,1844.31020,N,09913.93703,E,0.889,,090524,,,A*77
$GPVTG,,T,,M,0.889,N,1.647,K,A*2E
$GPGGA,153006.00,1844.31020,N,09913.93703,E,1,07,1.18,360.2,M,-37.4,M,,*7D
$GPGSA,A,3,18,32,10,28,25,12,31,,,,,,2.85,1.18,2.59*0E
$GPGSV,3,1,12,10,59,005,17,12,21,076,10,18,25,171,20,21,06,317,15*79
$GPGSV,3,2,12,23,57,086,13,24,04,040,,25,35,106,20,26,02,198,*70
$GPGSV,3,3,12,27,01,247,15,28,57,231,20,31,25,221,30,32,43,332,20*70
$GPGLL,1844.31020,N,09913.93703,E,153006.00,A,A*6D
$GPRMC,153007.00,A,1844.31007,N,09913.93713,E,0.614,,090524,,,A*78
$GPVTG,,T,,M,0.614,N,1.137,K,A*24
$GPGGA,153007.00,1844.31007,N,09913.93713,E,1,07,1.18,360.3,M,-37.4,M,,*79
$GPGSA,A,3,18,32,10,28,25,12,31,,,,,,2.85,1.18,2.59*0E
$GPGSV,3,1,12,10,59,005,18,12,21,076,11,18,25,171,21,21,06,317,16*75
$GPGSV,3,2,12,23,57,086,13,24,04,040,,25,35,106,20,26,02,198,*70
$GPGSV,3,3,12,27,01,247,14,28,57,231,19,31,25,221,31,32,43,332,20*7A
$GPGLL,1844.31007,N,09913.93713,E,153007.00,A,A*68
$GPRMC,153008.00,A,1844.31042,N,09913.93668,E,0.557,,090524,,,A*7F
$GPVTG,,T,,M,0.557,N,1.032,K,A*24
$GPGGA,153008.00,1844.31042,N,09913.93668,E,1,07,1.18,360.6,M,-37.4,M,,*7F
$GPGSA,A,3,18,32,10,28,25,12,31,,,,,,2.85,1.18,2.59*0E
$GPGSV,3,1,12,10,59,005,17,12,21,076,07,18,25,171,21,21,06,317,16*7D
$GPGSV,3,2,12,23,57,086,14,24,04,040,,25,35,106,19,26,02,198,*7D
$GPGSV,3,3,12,27,01,247,13,28,57,231,20,31,25,221,31,32,43,332,19*7D
$GPGLL,1844.31042,N,09913.93668,E,153008.00,A,A*6B
$GPRMC,153009.00,A,1844.31038,N,09913.93649,E,0.673,,090524,,,A*75
$GPVTG,,T,,M,0.673,N,1.247,K,A*21
$GPGGA,153009.00,1844.31038,N,09913.93649,E,1,07,1.18,360.8,M,-37.4,M,,*7E
$GPGSA,A,3,18,32,10,28,25,12,31,,,,,,2.85,1.18,2.59*0E
$GPGSV,3,1,12,10,59,005,18,12,21,076,07,18,25,171,21,21,06,317,14*70
$GPGSV,3,2,12,23,57,086,15,24,04,040,,25,35,106,18,26,02,198,*7D
$GPGSV,3,3,12,27,01,247,12,28,57,231,20,31,25,221,31,32,43,332,19*7C
$GPGLL,1844.31038,N,09913.93649,E,153009.00,A,A*64
$GPRMC,153010.00,A,1844.31033,N,09913.93646,E,0.530,,090524,,,A*7D
$GPVTG,,T,,M,0.530,N,0.981,K,A*25
$GPGGA,153010.00,1844.31033,N,09913.93646,E,1,07,1.18,361.0,M,-37.4,M,,*7B

The GPS is reporting extremly weak signals, very borderline for having a fix at all.

Weak signals are normally caused by;

GPS is not outside with a good view of the sky.
GPS antenna is faulty.
GPS is faulty.
Exessive nearby RF interferance.

AHA... So I will take it outside

and keep you informed....

By the way, how to see that the GPS signal is very weak?

From the GPGSV sentences;

https://w3.cs.jmu.edu/bernstdh/web/common/help/nmea-sentences.php

26 is borderline for the signal to noise ratio, you have quite a few a good bit lower than that.

Result:

Same effect outside (+/- 10 meters from the house, clear view (no trees)

after +/- 30 seconds, the satellite count was suddenly at 6 for a few seconds and then .... back to 0.

The red LED of the NEO bopard is going on and off once per second...

and the rest of the display shows the correct time and date and day...

And what did the output of the GPS look like then ?

There we go...

just a little bit of the whole output....

$GPGSV,3,1,12,10,61,009,,12,20,074,12,18,22,170,26,21,08,316,*72

$GPGSV,3,2,12,23,56,092,17,24,02,040,,25,35,103,18,26,04,197,*71

$GPGSV,3,3,12,27,00,245,,28,60,235,13,31,27,222,24,32,43,336,22*75

$GPGLL,1844.31185,N,09913.93925,E,153558.00,A,A*67

$GPRMC,153559.00,A,1844.31167,N,09913.93897,E,1.068,,090524,,,A*7E

$GPVTG,,T,,M,1.068,N,1.979,K,A*2A

$GPGGA,153559.00,1844.31167,N,09913.93897,E,1,06,4.85,347.6,M,-37.4,M,,*73

$GPGSA,A,3,18,32,28,25,12,31,,,,,,,24.54,4.85,24.05*0B

$GPGSV,3,1,12,10,61,009,,12,20,074,12,18,22,170,25,21,08,316,*71

$GPGSV,3,2,12,23,56,092,17,24,02,040,,25,35,103,18,26,04,197,*71

$GPGSV,3,3,12,27,00,245,,28,60,235,13,31,27,222,24,32,43,336,23*74

$GPGLL,1844.31167,N,09913.93897,E,153559.00,A,A*62

$GPRMC,153600.00,A,1844.31162,N,09913.93868,E,0.861,,090524,,,A*74

$GPVTG,,T,,M,0.861,N,1.594,K,A*25

$GPGGA,153600.00,1844.31162,N,09913.93868,E,1,05,4.84,347.6,M,-37.4,M,,*7B

$GPGSA,A,3,18,32,28,25,31,,,,,,,,24.46,4.84,23.98*09

$GPGSV,3,1,12,10,61,009,,12,20,074,,18,22,170,25,21,08,316,*72

$GPGSV,3,2,12,23,56,092,18,24,02,040,,25,35,103,18,26,04,197,*7E

$GPGSV,3,3,12,27,00,245,,28,60,235,17,31,27,222,24,32,43,336,23*70

$GPGLL,1844.31162,N,09913.93868,E,153600.00,A,A*68

$GPRMC,153601.00,A,1844.31197,N,09913.93903,E,0.315,,090524,,,A*7B

$GPVTG,,T,,M,0.315,N,0.584,K,A*2D

$GPGGA,153601.00,1844.31197,N,09913.93903,E,1,05,1.40,347.3,M,-37.4,M,,*74

$GPGSA,A,3,18,32,28,25,31,,,,,,,,3.65,1.40,3.37*07

$GPGSV,3,1,12,10,61,009,,12,20,074,,18,22,170,25,21,08,316,*72

$GPGSV,3,2,12,23,56,092,17,24,02,040,,25,35,103,16,26,04,197,*7F

$GPGSV,3,3,12,27,00,245,,28,60,235,19,31,27,222,24,32,43,336,24*79

$GPGLL,1844.31197,N,09913.93903,E,153601.00,A,A*6F

$GPRMC,153602.00,A,1844.31209,N,09913.93890,E,0.413,,090524,,,A*76

$GPVTG,,T,,M,0.413,N,0.765,K,A*21

$GPGGA,153602.00,1844.31209,N,09913.93890,E,1,05,1.40,347.1,M,-37.4,M,,*7A

$GPGSA,A,3,18,32,28,25,31,,,,,,,,3.65,1.40,3.37*07

$GPGSV,3,1,12,10,61,009,,12,20,074,,18,22,170,25,21,08,316,*72

$GPGSV,3,2,12,23,56,092,18,24,02,040,,25,35,103,15,26,04,197,*73

$GPGSV,3,3,12,27,00,245,,28,60,235,18,31,27,222,25,32,43,336,25*78

$GPGLL,1844.31209,N,09913.93890,E,153602.00,A,A*63

$GPRMC,153603.00,A,1844.31209,N,09913.93910,E,0.175,,090524,,,A*7B

$GPVTG,,T,,M,0.175,N,0.324,K,A*25

$GPGGA,153603.00,1844.31209,N,09913.93910,E,1,05,1.40,347.2,M,-37.4,M,,*71

$GPGSA,A,3,18,32,28,25,31,,,,,,,,3.65,1.40,3.37*07

$GPGSV,3,1,12,10,61,009,,12,20,074,,18,22,170,25,21,08,316,*72

$GPGSV,3,2,12,23,56,092,17,24,02,040,,25,35,103,16,26,04,197,*7F

$GPGSV,3,3,12,27,00,245,,28,60,235,16,31,27,222,25,32,43,336,24*77

$GPGLL,1844.31209,N,09913.93910,E,153603.00,A,A*6B`


Use code tags to format code for the forum`

I see...

There are many reports of counterfeit NEO-6M modules, which function poorly or not at all. Also, could be a bad antenna or antenna connection. Post a close up, focused picture of the setup.

Indeed there have been quite a few reports on here recently with symptoms of very poorly functioning Neo6M GPSs, symtoms being weak signal issues or no reception at all.

Ok...

I have tried another Sketch found on the Forum...
GPS help - Using Arduino / Programming Questions - Arduino Forum

#include <NMEAGPS.h>
NMEAGPS gps;

//-----------------
//   Choose a serial port for the GPS device:
//
//   BEST: For a Mega, Leonardo or Due, use the extra hardware serial port
//#define gpsPort Serial1

//   2nd BEST:  For other Arduinos, use AltSoftSerial on the required pins
//                 (8&9 for an UNO)
// #include <AltSoftSerial.h>
// AltSoftSerial gpsPort;  // pin 8 to GPS TX, pin 9 to GPS RX

//   3rd BEST:  If you can't use those specific pins (are you sure?),
//                 use NeoSWSerial on any two pins @ 9600, 19200 or 38400
#include <NeoSWSerial.h>
NeoSWSerial gpsPort( 8, 9 ); // pin 10 to GPS TX, pin 11 to GPS RX (LEVEL-SHIFT!!)

//   WORST:  SoftwareSerial is NOT RECOMMENDED

//-----------------

void setup()
{
  Serial.begin(115200);
  gpsPort.begin(9600);
  Serial.println( F("GPS Start") );
}

void loop()
{
  while(gps.available( gpsPort ))//While there are characters to come from the GPS
  {
    gps_fix fix = gps.read();  // get a complete fix structure when its available

    Serial.print( F("Satellite Count:") );
    if (fix.valid.satellites)
      Serial.print( fix.satellites );

    Serial.print( F("\nLatitude:") );
    if (fix.valid.location)
      Serial.print( fix.latitude(), 6 );
    Serial.print( F("\nLongitude:") );
    if (fix.valid.location)
      Serial.print( fix.longitude(), 6 );

    Serial.print( F("\nSpeed MPH:") );
    if (fix.valid.speed)
      Serial.print( fix.speed_mph() );
    
    Serial.print( F("\nAltitude Feet:") );
    if (fix.valid.altitude)
      Serial.print( fix.altitude() * 3.28084 ); // meters to feet
    Serial.println();
  }
}

After less than 5 seconds, the board started to spit out following...
(extract)

Speed MPH:0.77

Altitude Feet:1172.90

Satellite Count:8

Latitude:18.738664

Longitude:99.232276

Speed MPH:1.02

Altitude Feet:1173.88

Satellite Count:8

Latitude:18.738660

Longitude:99.232284

Speed MPH:1.11

Altitude Feet:1174.87

Satellite Count:8

Latitude:18.738653

So it can see satellites... (here, 8)...

Hence, i can imagine that the board is OK.

So.... the fault seems to be in my sketch (the intro post)...

If anyone could have a look there...

I suspect that "interrupts" are getting cleared (disabled).

Any ideas?

Even more data, ....
here I lost a satellite...

Satellite Count:7
Latitude:18.738504
Longitude:99.232444
Speed MPH:0.46
Altitude Feet:1220.14
Satellite Count:7
Latitude:18.738508
Longitude:99.232437
Speed MPH:0.81
Altitude Feet:1219.49
Satellite Count:7
Latitude:18.738504
Longitude:99.232452
Speed MPH:0.42
Altitude Feet:1219.16
Satellite Count:6
Latitude:18.738500
Longitude:99.232460
Speed MPH:1.13
Altitude Feet:1218.18
Satellite Count:6
Latitude:18.738498

Does the time display properly in your original sketch?

Hello...

Yes, I think there is no discrepancy if I compare with my desktop or the mobile phone...
But here again, I am not able to see if there is a millisecond difference... I am too slow to see that.

I think that there is a conflict somewhere. (interrupts ?)
It is just an uneducated guess...