# Compile errors for TinyGPS++/TinyGPS++.h project

**URL:** <https://community.particle.io/t/compile-errors-for-tinygps-tinygps-h-project/23042>\
**Category:** Troubleshooting\
**Created:** [May 20, 2016, 7:08pm UTC](https://community.particle.io/t/compile-errors-for-tinygps-tinygps-h-project/23042 "2016-05-20T19:08:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bpthomas](https://avatars.discourse-cdn.com/v4/letter/b/e79b87/32.png) [@bpthomas](https://community.particle.io/u/bpthomas)\
**Post date:** [May 20, 2016, 7:08pm UTC](https://community.particle.io/t/compile-errors-for-tinygps-tinygps-h-project/23042/1 "2016-05-20T19:08:23Z")

</div>

hello,  
i am attempting to replicate a GPS\electron project: [https://github.com/InitialState/particle-electron-gps-streamer](https://github.com/InitialState/particle-electron-gps-streamer)

i have some arduino exerience, but the particle build IDE is new to me. I am having issues compiling code, and it seems like a header issue, but as far as I can tell the library is installed as needed. Can anyone see any obvious issues with this code? `/\*

```
   Adapted from the example file "FullExample" included with the TinyGPS++ library
   
*/

#include <TinyGPS++/TinyGPS++.h>

// Change GPSBaud based on GPS unit
// 9600 for Adafruit's Ultimate GPS
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

void setup()
{
  // Begin serial at 115200 Baud
  Serial.begin(115200);
  // Serial1 reads from the Electron's TX/RX
  Serial1.begin(GPSBaud);

  // Prints library version and convenient header
  Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  Serial.println(F("by Mikal Hart"));
  Serial.println();
  Serial.println(F("Sats HDOP Latitude Longitude Fix Date Time Date Alt Course Speed Card Distance Course Card Chars Sentences Checksum"));
  Serial.println(F(" (deg) (deg) Age Age (m) --- from GPS ---- ---- to London ---- RX RX Fail"));
  Serial.println(F("---------------------------------------------------------------------------------------------------------------------------------------"));
}

void loop()
{
  // Coordinates for London - you could switch these to another location
  // to see how far the Electron is from that location
  // Not necessary, but left it in because I thought it was cool!
  static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
  
// Prints values corresponding to headers inside of Setup()
  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);
  // Uses library's "distanceBetween" to calculate distance to London
  unsigned long distanceKmToLondon =
    (unsigned long)TinyGPSPlus::distanceBetween(
      gps.location.lat(),
      gps.location.lng(),
      LONDON_LAT, 
      LONDON_LON) / 1000;
  printInt(distanceKmToLondon, gps.location.isValid(), 9);

  double courseToLondon =
    TinyGPSPlus::courseTo(
      gps.location.lat(),
      gps.location.lng(),
      LONDON_LAT, 
      LONDON_LON);
  printFloat(courseToLondon, gps.location.isValid(), 7, 2);

  const char *cardinalToLondon = TinyGPSPlus::cardinal(courseToLondon);

  printStr(gps.location.isValid() ? cardinalToLondon : "***", 6);

  printInt(gps.charsProcessed(), true, 6);
  printInt(gps.sentencesWithFix(), true, 10);
  printInt(gps.failedChecksum(), true, 9);
  Serial.println();

  // Now we prepare to publish location data to our webhook

  // Make strings of the Latitude and Longitude readings
  char coord1[10];
  sprintf(coord1, "%f", (gps.location.lat(), gps.location.isValid(), 11, 6));
  char coord2[10];
  sprintf(coord2, "%f", (gps.location.lng(), gps.location.isValid(), 12, 6));
  
  // Combine these strings into the coordinate format accepted by Initial State
  char coord3[21];
  strcpy(coord3,coord1);
  strcat(coord3,",");
  strcat(coord3,coord2);
  // Print to serial to check format
  Serial.println(coord3);

  // Send the data (coord3) by calling our webhook with the Event Name "sendgps"
  Particle.publish("sendgps",coord3);
  
  // Wait 60 seconds
  smartDelay(60000);
  //}

  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS data received: check wiring"));
}
}
// This custom version of delay() ensures that the gps object
// is being "fed".

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

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);
}

static void printInt(unsigned long val, bool valid, int len)
{
  char sz[32] = " *****************";
  if (valid)
    sprintf(sz, "%ld", val);
  sz[len] = 0;
  for (int i=strlen(sz); i<len; ++i)
    sz[i] = ' ';
  if (len > 0) 
    sz[len-1] = ' ';
  Serial.print(sz);
  smartDelay(0);
}

static void printDateTime(TinyGPSDate &d, TinyGPSTime &t)
{
  if (!d.isValid())
  {
    Serial.print(F(" **********"));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
    Serial.print(sz);
  }
  
  if (!t.isValid())
  {
    Serial.print(F(" ********"));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
    Serial.print(sz);
  }

  printInt(d.age(), d.isValid(), 5);
  smartDelay(0);
}

static void printStr(const char *str, int len)
{
  int slen = strlen(str);
  for (int i=0; i<len; ++i)
    Serial.print(i<slen ? str[i] : ' ');
  smartDelay(0);
}`

```

compiler errors:

![](https://us1.discourse-cdn.com/flex026/uploads/particle/original/2X/5/52e1fdac0d4753cb737b7961bb1d8e4b8eca2c9a.png)

---

<div class="post-metadata">

**Author:** ![bpthomas](https://avatars.discourse-cdn.com/v4/letter/b/e79b87/32.png) [@bpthomas](https://community.particle.io/u/bpthomas)\
**Post date:** [May 20, 2016, 7:14pm UTC](https://community.particle.io/t/compile-errors-for-tinygps-tinygps-h-project/23042/2 "2016-05-20T19:14:31Z")

</div>

well, seems like a compiler issue, this works:

```
/*
   Adapted from the example file "FullExample" included with the TinyGPS++ library
   
*/
#pragma SPARK_NO_PREPROCESSOR
#include "Particle.h"
#include <TinyGPS++/TinyGPS++.h>

// Change GPSBaud based on GPS unit
// 9600 for Adafruit's Ultimate GPS
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

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

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);
}

static void printInt(unsigned long val, bool valid, int len)
{
  char sz[32] = " *****************";
  if (valid)
    sprintf(sz, "%ld", val);
  sz[len] = 0;
  for (int i=strlen(sz); i<len; ++i)
    sz[i] = ' ';
  if (len > 0) 
    sz[len-1] = ' ';
  Serial.print(sz);
  smartDelay(0);
}

static void printDateTime(TinyGPSDate &d, TinyGPSTime &t)
{
  if (!d.isValid())
  {
    Serial.print(F(" **********"));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
    Serial.print(sz);
  }
  
  if (!t.isValid())
  {
    Serial.print(F(" ********"));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
    Serial.print(sz);
  }

  printInt(d.age(), d.isValid(), 5);
  smartDelay(0);
}

static void printStr(const char *str, int len)
{
  int slen = strlen(str);
  for (int i=0; i<len; ++i)
    Serial.print(i<slen ? str[i] : ' ');
  smartDelay(0);
}

void setup()
{
  // Begin serial at 115200 Baud
  Serial.begin(115200);
  // Serial1 reads from the Electron's TX/RX
  Serial1.begin(GPSBaud);

  // Prints library version and convenient header
  Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  Serial.println(F("by Mikal Hart"));
  Serial.println();
  Serial.println(F("Sats HDOP Latitude Longitude Fix Date Time Date Alt Course Speed Card Distance Course Card Chars Sentences Checksum"));
  Serial.println(F(" (deg) (deg) Age Age (m) --- from GPS ---- ---- to London ---- RX RX Fail"));
  Serial.println(F("---------------------------------------------------------------------------------------------------------------------------------------"));
}

void loop()
{
  // Coordinates for London - you could switch these to another location
  // to see how far the Electron is from that location
  // Not necessary, but left it in because I thought it was cool!
  static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
  
// Prints values corresponding to headers inside of Setup()
  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);
  // Uses library's "distanceBetween" to calculate distance to London
  unsigned long distanceKmToLondon =
    (unsigned long)TinyGPSPlus::distanceBetween(
      gps.location.lat(),
      gps.location.lng(),
      LONDON_LAT, 
      LONDON_LON) / 1000;
  printInt(distanceKmToLondon, gps.location.isValid(), 9);

  double courseToLondon =
    TinyGPSPlus::courseTo(
      gps.location.lat(),
      gps.location.lng(),
      LONDON_LAT, 
      LONDON_LON);
  printFloat(courseToLondon, gps.location.isValid(), 7, 2);

  const char *cardinalToLondon = TinyGPSPlus::cardinal(courseToLondon);

  printStr(gps.location.isValid() ? cardinalToLondon : "***", 6);

  printInt(gps.charsProcessed(), true, 6);
  printInt(gps.sentencesWithFix(), true, 10);
  printInt(gps.failedChecksum(), true, 9);
  Serial.println();

  // Now we prepare to publish location data to our webhook

  // Make strings of the Latitude and Longitude readings
  char coord1[10];
  sprintf(coord1, "%f", (gps.location.lat(), gps.location.isValid(), 11, 6));
  char coord2[10];
  sprintf(coord2, "%f", (gps.location.lng(), gps.location.isValid(), 12, 6));
  
  // Combine these strings into the coordinate format accepted by Initial State
  char coord3[21];
  strcpy(coord3,coord1);
  strcat(coord3,",");
  strcat(coord3,coord2);
  // Print to serial to check format
  Serial.println(coord3);

  // Send the data (coord3) by calling our webhook with the Event Name "sendgps"
  Particle.publish("sendgps",coord3);
  
  // Wait 60 seconds
  smartDelay(60000);
  //}

  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS data received: check wiring"));
}
}
// This custom version of delay() ensures that the gps object
// is being "fed".
```

---

<div class="post-metadata">

**Author:** ![izeroman](https://avatars.discourse-cdn.com/v4/letter/i/ea666f/32.png) [@izeroman](https://community.particle.io/u/izeroman)\
**Post date:** [May 26, 2016, 8:23am UTC](https://community.particle.io/t/compile-errors-for-tinygps-tinygps-h-project/23042/3 "2016-05-26T08:23:22Z")

</div>

> [@bpthomas](#):
>
> /\*  
> Adapted from the example file "FullExample" included with the TinyGPS++ library
> 
> \*/  
> #pragma SPARK\_NO\_PREPROCESSOR  
> #include "Particle.h"  
> #include \<TinyGPS++/TinyGPS++.h\>
> 
> // Change GPSBaud based on GPS unit  
> // 9600 for Adafruit's Ultimate GPS  
> static const uint32\_t GPSBaud = 9600;
> 
> // The TinyGPS++ object  
> TinyGPSPlus gps;
> 
> static void smartDelay(unsigned long ms)  
> {  
> unsigned long start = millis();  
> do  
> {  
> while (Serial1.available())  
> gps.encode(Serial1.read());  
> } while (millis() - start \< ms);  
> }
> 
> 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);  
> }
> 
> static void printInt(unsigned long val, bool valid, int len)  
> {  
> char sz[32] = "\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*";  
> if (valid)  
> sprintf(sz, "%ld", val);  
> sz[len] = 0;  
> for (int i=strlen(sz); i\<len; ++i)  
> sz[i] = ' ';  
> if (len \> 0)  
> sz[len-1] = ' ';  
> Serial.print(sz);  
> smartDelay(0);  
> }
> 
> static void printDateTime(TinyGPSDate &d, TinyGPSTime &t)  
> {  
> if (!d.isValid())  
> {  
> Serial.print(F("\*\*\*\*\*\*\*\*\*\* "));  
> }  
> else  
> {  
> char sz[32];  
> sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());  
> Serial.print(sz);  
> }
> 
> if (!t.isValid())  
> {  
> Serial.print(F("\*\*\*\*\*\*\*\* "));  
> }  
> else  
> {  
> char sz[32];  
> sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());  
> Serial.print(sz);  
> }
> 
> printInt(d.age(), d.isValid(), 5);  
> smartDelay(0);  
> }
> 
> static void printStr(const char \*str, int len)  
> {  
> int slen = strlen(str);  
> for (int i=0; i\<len; ++i)  
> Serial.print(i\<slen ? str[i] : ' ');  
> smartDelay(0);  
> }
> 
> void setup()  
> {  
> // Begin serial at 115200 Baud  
> Serial.begin(115200);  
> // Serial1 reads from the Electron's TX/RX  
> Serial1.begin(GPSBaud);
> 
> // Prints library version and convenient header  
> Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());  
> Serial.println(F("by Mikal Hart"));  
> Serial.println();  
> Serial.println(F("Sats HDOP Latitude Longitude Fix Date Time Date Alt Course Speed Card Distance Course Card Chars Sentences Checksum"));  
> Serial.println(F(" (deg) (deg) Age Age (m) --- from GPS ---- ---- to London ---- RX RX Fail"));  
> Serial.println(F("---------------------------------------------------------------------------------------------------------------------------------------"));  
> }
> 
> void loop()  
> {  
> // Coordinates for London - you could switch these to another location  
> // to see how far the Electron is from that location  
> // Not necessary, but left it in because I thought it was cool!  
> static const double LONDON\_LAT = 51.508131, LONDON\_LON = -0.128002;
> 
> // Prints values corresponding to headers inside of Setup()  
> 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);  
> // Uses library's "distanceBetween" to calculate distance to London  
> unsigned long distanceKmToLondon =  
> (unsigned long)TinyGPSPlus::distanceBetween(  
> gps.location.lat(),  
> gps.location.lng(),  
> LONDON\_LAT,  
> LONDON\_LON) / 1000;  
> printInt(distanceKmToLondon, gps.location.isValid(), 9);
> 
> double courseToLondon =  
> TinyGPSPlus::courseTo(  
> gps.location.lat(),  
> gps.location.lng(),  
> LONDON\_LAT,  
> LONDON\_LON);  
> printFloat(courseToLondon, gps.location.isValid(), 7, 2);
> 
> const char \*cardinalToLondon = TinyGPSPlus::cardinal(courseToLondon);
> 
> printStr(gps.location.isValid() ? cardinalToLondon : "\*\*\* ", 6);
> 
> printInt(gps.charsProcessed(), true, 6);  
> printInt(gps.sentencesWithFix(), true, 10);  
> printInt(gps.failedChecksum(), true, 9);  
> Serial.println();
> 
> // Now we prepare to publish location data to our webhook
> 
> // Make strings of the Latitude and Longitude readings  
> char coord1[10];  
> sprintf(coord1, "%f", (gps.location.lat(), gps.location.isValid(), 11, 6));  
> char coord2[10];  
> sprintf(coord2, "%f", (gps.location.lng(), gps.location.isValid(), 12, 6));
> 
> // Combine these strings into the coordinate format accepted by Initial State  
> char coord3[21];  
> strcpy(coord3,coord1);  
> strcat(coord3,",");  
> strcat(coord3,coord2);  
> // Print to serial to check format  
> Serial.println(coord3);
> 
> // Send the data (coord3) by calling our webhook with the Event Name "sendgps"  
> Particle.publish("sendgps",coord3);
> 
> // Wait 60 seconds  
> smartDelay(60000);  
> //}
> 
> if (millis() \> 5000 && gps.charsProcessed() \< 10)  
> {  
> Serial.println(F("No GPS data received: check wiring"));  
> }  
> }  
> // This custom version of delay() ensures that the gps object  
> // is being "fed".

Do you have problem sending data to Initial State?
