Particle Electrons & TinyGPS++ : Not Working

Below is my Particle Electron program using TinyGPS++ library. With this program, I can read and display all the data being received into the GPS module (see Command Prompt output below) however, I am unable to put the GPS received data into each of the TinyGPS parameters and print it into the screen; for example gps.location.lat(), gps.location.lng(). Hence, my long and lat is always zero when I read from the gps.location.lat() and gps.location.lng().

Lat: 0.000000
Long: 0.000000

I read somewhere that this could due to serial port conflicting and hence have to use the SoftwareSerial.h. Is this correct? Or am I simply doing something wrong here.

Here is my program…

// This #include statement was automatically added by the Particle IDE.
#include <TinyGPS++.h>

#include "Particle.h"

// The TinyGPS++ object
TinyGPSPlus gps;

void setup()
{
	Serial.begin(9600);
	Serial1.begin(9600);

    pinMode(D6, OUTPUT);
    digitalWrite(D6, LOW);
}

void loop()
{
    smartDelay(5000);
}

static void smartDelay(unsigned long ms) {
  unsigned long start = millis();

  do {
    while (Serial1.available()) {
        byte c = Serial1.read();
        Serial.print(char(c));          //##### DEBUGGER #####
        int x = gps.encode(c);
    }

  } while (millis() - start < ms);
  
   Serial.print("Lat: "); Serial.println(gps.location.lat(),6);
   Serial.print("Long: "); Serial.println(gps.location.lng(),6);
   delay(1000);
}


And this is the output for the program...
C:\Users\banana\Downloads>particle flash --usb firmware.bin

Flash success!

C:\Users\banana\Downloads>particle serial monitor
Opening serial monitor for com port: "COM4"
Serial monitor opened successfully:
056.76915,N,11405.46835,W,1,12,1.08,1106.6,M,-17.4,M,,*4F
$GNG.4,M,,*47
$GNGSA,A,3,20,21,10,15,27,13,16,08,,,,,1.67,1.05,1.30*16
$GNGSA,A,3,66,81,82,67,74,,,,,,,,1.67,1.05,1.30*1B
$GPGSV,4,1,13,08,12,324,22,10,46,246,34,13,22,043,30,15,46,072,39*7B
$GPGSV,4,2,13,16,15,263,25,20,75,252,33,21,75,123,35,24,06,116,*7A
$GPGSV,4,3,13,26,01,240,,27,39,302,33,29,03,162,16,48,29,204,*7A
$GPGSV,4,4,13,51,31,171,*4A
$GLGSV,3,1,09,65,21,042,,66,85,072,38,67,37,218,27,73,08,333,*6F
$GLGSV,3,2,09,74,11,016,16,81,70,154,30,82,54,318,23,83,05,322,*6E
$GLGSV,3,3,09,88,20,145,07*59
$GNGLL,5056.76956,N,11405.46768,W,045942.00,A,A*6C
$GNRMC,045943.00,A,5056.76998,N,11405.46761,W,0.198,,140519,,,A*77
$GNVTG,,T,,M,0.198,N,0.367,K,A*3F
$GNGGA,045943.00,5056.76998,N,11405.46761,W,1,12,1.05,1108.4,M,-17.4,M,,*47
$GNGSA,A,3,20,21,10,15,27,13,16,08,,,,,1.67,1.05,1.30*16
$GNGSA,A,3,66,81,82,67,74,,,,,,,,1.67,1.05,1.30*1B
$GPGSV,4,1,13,08,12,324,22,10,46,246,34,13,22,043,30,15,46,072,39*7B
$GPGSV,4,2,13,16,15,263,26,20,75,252,33,21,75,123,35,24,06,116,*79
$GPGSV,4,3,13,26,01,240,,27,39,302,33,29,03,162,15,48,29,204,*79
$GPGSV,4,4,13,51,31,171,*4A
$GLGSV,3,1,09,65,21,042,,66,85,072,38,67,37,218,27,73,08,333,*6F
$GLGSV,3,2,09,74,11,016,15,81,70,154,29,82,54,318,23,83,05,322,*65
$GLGSV,3,3,09,88,20,145,09*57
$GNGLL,5056.76998,N,11405.46761,W,045943.00,A,A*66
$GNRMC,045944.00,A,5056.76995,N,11405.46749,W,0.242,,140519,,,A*73
$GNVTG,,T,,M,0.242,N,0.449,K,A*30
$GNGGA,045944.00,5056.76995,N,11405.46749,W,1,12,1.05,1108.7,M,-17.4,M,,*44
$GNGSA,A,3,20,21,10,15,27,13,16,08,,,,,1.67,1.05,1.30*16
$GNGSA,A,3,66,81,82,67,74,,,,,,,,1.67,1.05,1.30*1B
$GPGSV,4,1,13,08,12,324,22,10,46,246,34,13,22,043,30,15,46,072,39*7B
$GPGSV,4,2,13,16,15,263,26,20,75,252,33,21,75,123,35,24,06,116,*79
$GPGSV,4,3,13,26,01,240,,27,39,302,33,29,03,162,16,48,29,204,*7A
$GPGSV,4,4,13,51,31,171,*4A
$GLGSV,3,1,09,65,21,042,,66,85,072,38,67,37,218,27,73,08,333,*6F
$GLGSV,3,2,09,74,11,016,17,81,70,154,29,82,54,318,24,83,05,322,*60
$GLGSV,3,3,09,88,20,145,13*5C
$GNGLL,5056.76995,N,11405.46749,W,045944.00,A,A*66
$GNRMC,045945.00,A,5056.77000,N,11405.46738,W,0.154,,140519,,,A*74
$GNVTG,,T,,M,0.154,N,0.285,K,A*32
$GNGGA,045945.00,5056.77000,N,11405.46738,W,1,12,1.05,1108.9,M,-17.4,M,,*49
$GNGSA,A,3,20,21,10,15,27,13,16,08,,,,,1.67,1.05,1.30*16
$GNGSA,A,3,66,81,82,67,74,,,,,,,,1.67,1.05,1.30*1B
$GPGSV,4,1,13,08,12,324,22,10,46,246,34,13,22,043,30,15,46,072,38*7A
$GPGSV,4,2,13,16,15,263,26,20,75,252,33,21,75,123,35,24,06,116,*79
$GPGSV,4,3,13,26,01,240,,27,39,302,33,29,03,162,15,48,29,204,*79
$GPGSV,4,4,13,51,31,171,*4A
$GLGSV,3,1,09,65,21,042,,66,85,072,38,67,37,218,27,73,08,333,*6F
$GLGSV,3,2,09,74,11,016,19,81,70,154,29,82,54,318,23,83,05,322,*69
$GLGSV,3,3,09,88,20,145,15*5A
$GNGLL,5056.77000,N,11405.46738,W,045945.00,A,A*65
$GNRMC,045946.00,A,5056.77016,N,11405.46727,W,0.136,,140519,,,A*7A
$GNVTG,,T,,M,0.136,N,0.251,K,A*3F
$GNGGA,045946.00,5056.77016,N,11405.46727,W,1,12,1.05,1109.2,M,-17.4,M,,*49
$GNGSA,A,3,20,21,10,15,27,13,16,08,,,,,1.67,1.05,1.30*16
$GNGSA,A,3,66,81,82,67,88,74,,,,,,,1.67,1.05,1.30*1B
$GPGSV,4,1,13,08,12,324,22,10,46,246,34,13,22,043,30,15,46,072,38*7A
$GPGSV,4,2,13,16,15,263,26,20,75,252,33,21,75,123,35,24,06,116,*79
$GPGSV,4,3,13,26,01,240,,27,39,302,33,29,03,162,14,48,29,204,*78
$GPGSV,4,4,13,51,31,171,*4A
$GLGSV,3,1,09,65,21,042,,66,85,072,38,67,37,218,27,73,08,333,*6F
$GLGSV,3,2,09,74,11,016,18,81,70,154,29,82,54,318,24,83,05,322,*6F
$GLGSV,3,3,09,88,20,145,15*5A
$GNGLL,5056.77016,N,11405.46727,W,045946.00,A,A*6F
$GNRMC,045947.00,A,5056.77014,N,11405.46714,W,0.112,,140519,,,A*7F
$GNVTG,,T,,M,0.112,N,0.207,K,A*3A
$GNGGA,045947.00,5056.77014,N,11405.46714,W,1,12,1.0Lat: 0.000000
Long: 0.000000
5,1109.5,M,-17.4,M,,*4D
$GNGSA,A,3,20,21,10,15,27,13,16,08,,,,,13,16,08,,,,,1.27,0.78,1.00*1A
$GNGSA,A,3,66,81,82,67,88,74,,,,,,,1.27,0.78,1.00*17
$GPGSV,4,1,13,08,12,324,23,10,46,246,35,13,22,043,31,15,46,072,40*74
$GPGSV,4,2,13,16,14,263,27,20,75,252,34,21,75,123,37,24,06,116,*7C
$GPGSV,4,3,13,26,01,240,,27,39,302,34,29,03,162,16,48,29,204,*7D
$GPGSV,4,4,13,51,31,171,*4A
$GLGSV,3,1,09,65,21,042,,66,85,072,38,67,37,218,26,73,08,333,19*66
$GLGSV,3,2,09,74,11,016,17,81,70,154,28,82,54,318,23,83,05,322,*66
$GLGSV,3,3,09,88,20,145,18*57
$GNGLL,5056.77020,N,11405.46701,W,045948.00,A,A*60
$GNRMC,045949.00,A,5056.77033,N,11405.46689,W,0.052,,140519,,,A*74
$GNVTG,,T,,M,0.052,N,0.097,K,A*34
$GNGGA,045949.00,5056.77033,N,11405.46689,W,1,12,0.78,1110.2,M,-17.4,M,,*47
$GNGSA,A,3,20,21,10,15,27,13,16,08,,,,,1.27,0.78,1.00*1A
$GNGSA,A,3,66,81,82,67,88,74,,,,,,,1.27,0.78,1.00*17
$GPGSV,4,1,13,08,12,324,23,10,46,246,35,13,22,043,31,15,46,072,39*7A
$GPGSV,4,2,13,16,14,263,27,20,75,252,34,21,75,123,36,24,06,116,*7D
$GPGSV,4,3,13,26,01,240,,27,39,302,34,29,03,162,16,48,29,204,*7D
$GPGSV,4,4,13,51,31,171,*4A
$GLGSV,3,1,09,65,21,042,,66,85,072,38,67,37,218,26,73,08,333,19*66
$GLGSV,3,2,09,74,11,016,16,81,70,154,29,82,54,318,23,83,05,322,*66
$GLGSV,3,3,09,88,20,145,19*56
$GNGLL,5056.77033,N,11405.46689,W,045949.00,A,A*62
$GNRMC,045950.00,A,5056.77041,N,11405.46684,W,0.148,,140519,,,A*7E
$GNVTG,,T,,M,0.148,N,0.274,K,A*31
$GNGGA,045950.00,5056.77041,N,11405.46684,W,1,12,0.78,1110.6,M,-17.4,M,,*43
$GNGSA,A,3,20,21,10,15,27,13,16,08,,,,,1.27,0.78,1.00*1A
$GNGSA,A,3,66,81,82,67,88,74,,,,,,,1.27,0.78,1.00*17
$GPGSV,4,1,13,08,12,324,23,10,46,246,34,13,22,043,30,15,46,072,38*7B
$GPGSV,4,2,13,16,14,263,26,20,75,252,33,21,75,123,35,24,06,116,*78
$GPGSV,4,3,13,26,01,240,,27,39,302,32,29,03,162,16,48,29,204,*7B
$GPGSV,4,4,13,51,31,171,*4A
$GLGSV,3,1,09,65,21,042,,66,85,072,38,67,37,218,25,73,08,333,19*65
$GLGSV,3,2,09,74,11,016,16,81,70,154,28,82,54,318,23,83,05,322,*67
$GLGSV,3,3,09,88,20,145,19*56
$GNGLL,5056.77041,N,11405.46684,W,045950.00,A,A*62
$GNRMC,045951.00,A,5056.77047,N,11405.46680,W,0.030,,140519,,,A*73
$GNVTG,,T,,M,0.030,N,0.056,K,A*3D
$GNGGA,045951.00,5056.77047,N,11405.46680,W,1,12,0.78,1110.8,M,-17.4,M,,*4E
$GNGSA,A,3,20,21,10,15,27,13,16,08,,,,,1.27,0.78,1.00*1A
$GNGSA,A,3,66,81,82,67,88,74,,,,,,,1.27,0.78,1.00*17
$GPGSV,4,1,13,08,12,324,23,10,46,246,34,13,22,043,30,15,46,072,38*7B
$GPGSV,4,2,13,16,14,263,26,20,75,252,33,21,75,123,35,24,06,116,*78
$GPGSV,4,3,13,26,01,240,,27,39,302,32,29,03,162,16,48,29,204,*7B
$GPGSV,4,4,13,51,31,171,*4A
$GLGSV,3,1,09,65,21,042,,66,85,072,38,67,37,218,25,73,08,333,19*65
$GLGSV,3,2,09,74,11,016,15,81,70,154,28,82,54,318,23,83,05,322,*64
$GLGSV,3,3,09,88,20,145,19*56
$GNGLL,5056.77047,N,11405.46680,W,045951.00,A,A*61
$GNRMC,045952.00,A,5056.77054,N,11405.46679,W,0.024,,140519,,,A*71
$GNVTG,,T,,M,0.024,N,0.044,K,A*3B
$GNGGA,045952.00,5056.77054,N,11405.46679,W,1,12,0.78,1110.9,M,-17.4,M,,*48
$GNGSA,A,3,20,21,10,15,27,13,16,08,,,,,1.27,0.78,1.00*1A
$GNGSA,A,3,66,81,82,67,88,74,,,,,,,1.27,0.78,1.00*17
$GPGSV,4,1,13,08,12,324,23,10,46,246,34,13,22,043,30,15,46,072,38*7B
$GPGSV,4,2,13,16,14,263,26,20,75,252,33,21,75,123,35,24,06,116,*78
$GPGSV,4,3,13,26,01,240,,27,39,302,32,29,03,162,16,48,29,204,*7B
$GPGSV,4,4,13,51,31,171,*4A
$GLGSV,3,1,09,65,21,042,06,66,85,072,38,67,37,218,25,73,08,333,19*63
$GLGSV,3,2,09,74,11,016,14,81,70,154,29,82,54,318,23,83,05,322,*64
$GLGSV,3,3,09,88,20,145,19*56
$GNGLL,5056.77054,N,11405.46679,W,045952.00,A,A*66
$GNRMC,045953.00,A,5056.77054,N,11405.46677,W,0.126,,140519,,,A*7D
$GNVTG,,T,,M,0.126,N,0.233,K,A*3A
$GNGGA,045953.00,5056.77054,N,11405.46677,W,1,12,0.78,1111.2,M,-17.4,M,,*4D
$GNGSA,A,3,20,2Lat: 0.000000
Long: 0.000000
Serial connection closed.

C:\Users\banana\Downloads>

Are you using the AssetTracker V2? The most common reason is that the standard TinyGPS++ does not respond to all of the sentences emitted by the u-blox M8. The u-blox sends out GNRMC and GNGGA, but TinyGPS++ is expecting GPRMC and GPGGA.

The easiest thing to do is use the AssetTrackerRK library that has the fix in it already. There’s a modified TinyGPS++ in it that responds to both standard PMTK (from the GlobalTop PA6H and AssetTracker V1) and the u-blox variation.

The actual code change in TinyGPS++ looks like:

  // the first term determines the sentence type
  if (curTermNumber == 0)
  {
    if (!strcmp(term, _GPRMCterm) || !strcmp(term, "GNRMC"))
      curSentenceType = GPS_SENTENCE_GPRMC;
    else if (!strcmp(term, _GPGGAterm) ||!strcmp(term, "GNGGA"))
      curSentenceType = GPS_SENTENCE_GPGGA;
    else
      curSentenceType = GPS_SENTENCE_OTHER;
2 Likes

Thanks for your feedback rickkas7

Yes I am using AssetTracker V2. I tried the 1_SimpleGPS.cpp but I came up with these error messages.

Do I have to include the library (AssetTrackerRK and Tiny GPS++ into my project? ( as shown below)

image

and

image

What device OS version are you building for?
The logging feature requires at least 0.6.0

Sorry. It is OS Ver 0.5.4.
How do I upgrade the Device OS?

I have this too…

image

Not too sure which one is the device version.

I think I figured it out.
Always a learning experience…

That is the CLI version. That's not the same as device OS.
There are also two instances of device OS you need to distinguish.
Your individual device has some device OS version installed (can be acquired via particle serial identify or Particle Console | Build your connected product or in Web IDE via the target drawer) and the (minimum) version you are targeting (builing) your binary at.
In Web IDE (and any other building tool) you can select what minimum OS version the target device must have installed in order to run your code.
Web IDE has that "hidden" in the target drawer

The drop down list (here showing Default (1.1.0)) is the setting you need to change in order to allow the toolchain to use the respective feature set supported by that version.
In your case this needs to be 0.6.0 or higher.

Normally flashing a firmware that is targeted to a version higher than what's on the device would trigger an auto-upgrade (aka Safe Mode Healer - involving multiple magenta flashing and restart cycles you shouldn't interrupt) to the required minimum OS version.
Or you use CLI particle update (in DFU Mode) to upgrade to the most recent official release version (currently 1.1.0)