Expected unqualified-id before '->' token

Hi everyone.
The sketch got error of: expected unqualified-id before '->' token
how to fix please?
Thanks
Adam

TFT_eSPI display;

int gpsDataBJ = 1;


void setup()
{
  Serial.begin(115200);

  display.begin();
  display.setRotation(1);
  display.fillScreen(0);
  display.setCursor(0, 0, 2);
  display.setTextColor(TFT_WHITE, TFT_BLACK);
  display.setTextSize(1);

///  gps = new GPS(GPS_SERIAL, GPS_TX, GPS_RX);
  GPS->begin(GPS_BAUD);

}

void loop()
{
  Serial.printf("%s\n", GPS->get_fix().toString().c_str());
  if (int gpsDataBJ == 1 ) {
    display.fillScreen(0);
    display.setCursor(0, 0, 2);
    Serial.printf(GPS->get_fix().toString().c_str());
    display.println(GPS->get_fix().toString().c_str());
    display.fillScreen(0);
    display.setCursor(0, 0, 2);
    display.printf("Tracking %d of %d visible\n", GPS->get_tracking_satellites(), GPS->get_visibile_satellites());
    display.printf("Status: %s\n", GPS->get_status() == 'A' ? "LOCK!" : "SEARCHING...");
    display.printf("Time: %s\n", GPS->get_fix().timestamp.toString().c_str());
    display.printf("Lat: %f\n", GPS->get_fix().latitude);
    display.printf("Lng: %f\n", GPS->get_fix().longitude);
    display.printf("Speed: %f\n", GPS->get_fix().speed);
    display.printf("Almanac: %.1f%% complete\n", GPS->get_fix().almanac.percentComplete());
  }
  delay(5000);
}

ERROR:

Arduino: 1.8.19 (Windows 7), Board: "TTGO LoRa32-OLED V1, 40MHz, 921600, None"


C:\Users\HUA.DELLV-PC\Documents\Arduino\sketch_jan07c\sketch_jan07c.ino: In function 'void setup()':

sketch_jan07c:24:6: error: expected unqualified-id before '->' token

   GPS->begin(GPS_BAUD);

      ^

C:\Users\HUA.DELLV-PC\Documents\Arduino\sketch_jan07c\sketch_jan07c.ino: In function 'void loop()':

sketch_jan07c:30:28: error: expected primary-expression before '->' token

   Serial.printf("%s\n", GPS->get_fix().toString().c_str());

                            ^

sketch_jan07c:31:7: error: expected primary-expression before 'int'

   if (int gpsDataBJ == 1 ) {

       ^

sketch_jan07c:31:7: error: expected ')' before 'int'

sketch_jan07c:34:22: error: expected primary-expression before '->' token

     Serial.printf(GPS->get_fix().toString().c_str());

                      ^

sketch_jan07c:35:24: error: expected primary-expression before '->' token

     display.println(GPS->get_fix().toString().c_str());

                        ^

sketch_jan07c:38:54: error: expected primary-expression before '->' token

     display.printf("Tracking %d of %d visible\n", GPS->get_tracking_satellites(), GPS->get_visibile_satellites());

                                                      ^

sketch_jan07c:38:86: error: expected primary-expression before '->' token

     display.printf("Tracking %d of %d visible\n", GPS->get_tracking_satellites(), GPS->get_visibile_satellites());

                                                                                      ^

sketch_jan07c:39:39: error: expected primary-expression before '->' token

     display.printf("Status: %s\n", GPS->get_status() == 'A' ? "LOCK!" : "SEARCHING...");

                                       ^

sketch_jan07c:40:37: error: expected primary-expression before '->' token

     display.printf("Time: %s\n", GPS->get_fix().timestamp.toString().c_str());

                                     ^

sketch_jan07c:41:36: error: expected primary-expression before '->' token

     display.printf("Lat: %f\n", GPS->get_fix().latitude);

                                    ^

sketch_jan07c:42:36: error: expected primary-expression before '->' token

     display.printf("Lng: %f\n", GPS->get_fix().longitude);

                                    ^

sketch_jan07c:43:38: error: expected primary-expression before '->' token

     display.printf("Speed: %f\n", GPS->get_fix().speed);

                                      ^

sketch_jan07c:44:53: error: expected primary-expression before '->' token

     display.printf("Almanac: %.1f%% complete\n", GPS->get_fix().almanac.percentComplete());

                                                     ^

exit status 1

expected unqualified-id before '->' token



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Looks like you are missing an include of the GPS library ? Probably one for the TFT display also.

You have already declared this variable so you don't need int again.

1 Like

Thank you red_car.
I modified the two places and got the same error.

#include <TFT_eSPI.h>
#include <GPS.h>

TFT_eSPI display;

int gpsDataBJ = 1;


void setup()
{
  Serial.begin(115200);

  display.begin();
  display.setRotation(1);
  display.fillScreen(0);
  display.setCursor(0, 0, 2);
  display.setTextColor(TFT_WHITE, TFT_BLACK);
  display.setTextSize(1);

///  gps = new GPS(GPS_SERIAL, GPS_TX, GPS_RX);
  GPS->begin(GPS_BAUD);

}

void loop()
{
  Serial.printf("%s\n", GPS->get_fix().toString().c_str());
  if (gpsDataBJ == 1 ) {
    display.fillScreen(0);
    display.setCursor(0, 0, 2);
    Serial.printf(GPS->get_fix().toString().c_str());
    display.println(GPS->get_fix().toString().c_str());
    display.fillScreen(0);
    display.setCursor(0, 0, 2);
    display.printf("Tracking %d of %d visible\n", GPS->get_tracking_satellites(), GPS->get_visibile_satellites());
    display.printf("Status: %s\n", GPS->get_status() == 'A' ? "LOCK!" : "SEARCHING...");
    display.printf("Time: %s\n", GPS->get_fix().timestamp.toString().c_str());
    display.printf("Lat: %f\n", GPS->get_fix().latitude);
    display.printf("Lng: %f\n", GPS->get_fix().longitude);
    display.printf("Speed: %f\n", GPS->get_fix().speed);
    display.printf("Almanac: %.1f%% complete\n", GPS->get_fix().almanac.percentComplete());
  }
  delay(5000);
}
Arduino: 1.8.19 (Windows 7), Board: "TTGO LoRa32-OLED V1, 40MHz, 921600, None"



C:\Users\HUA.DELLV-PC\Documents\Arduino\main_cpp_test\main_cpp_test.ino: In function 'void setup()':

main_cpp_test:27:6: error: expected unqualified-id before '->' token

   GPS->begin(GPS_BAUD);

      ^

C:\Users\HUA.DELLV-PC\Documents\Arduino\main_cpp_test\main_cpp_test.ino: In function 'void loop()':

main_cpp_test:33:28: error: expected primary-expression before '->' token

   Serial.printf("%s\n", GPS->get_fix().toString().c_str());

                            ^

main_cpp_test:37:22: error: expected primary-expression before '->' token

     Serial.printf(GPS->get_fix().toString().c_str());

                      ^

main_cpp_test:38:24: error: expected primary-expression before '->' token

     display.println(GPS->get_fix().toString().c_str());

                        ^

main_cpp_test:41:54: error: expected primary-expression before '->' token

     display.printf("Tracking %d of %d visible\n", GPS->get_tracking_satellites(), GPS->get_visibile_satellites());

                                                      ^

main_cpp_test:41:86: error: expected primary-expression before '->' token

     display.printf("Tracking %d of %d visible\n", GPS->get_tracking_satellites(), GPS->get_visibile_satellites());

                                                                                      ^

main_cpp_test:42:39: error: expected primary-expression before '->' token

     display.printf("Status: %s\n", GPS->get_status() == 'A' ? "LOCK!" : "SEARCHING...");

                                       ^

main_cpp_test:43:37: error: expected primary-expression before '->' token

     display.printf("Time: %s\n", GPS->get_fix().timestamp.toString().c_str());

                                     ^

main_cpp_test:44:36: error: expected primary-expression before '->' token

     display.printf("Lat: %f\n", GPS->get_fix().latitude);

                                    ^

main_cpp_test:45:36: error: expected primary-expression before '->' token

     display.printf("Lng: %f\n", GPS->get_fix().longitude);

                                    ^

main_cpp_test:46:38: error: expected primary-expression before '->' token

     display.printf("Speed: %f\n", GPS->get_fix().speed);

                                      ^

main_cpp_test:47:53: error: expected primary-expression before '->' token

     display.printf("Almanac: %.1f%% complete\n", GPS->get_fix().almanac.percentComplete());

                                                     ^

exit status 1

expected unqualified-id before '->' token



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Where did you get that code?

Try using a "." instead of "->" in the function calls.

1 Like

Hi,
Can I suggest you forget the display for the moment and use one of the example codes that came with the GPS library and the IDE Monitor.
This is a good place to start, once you have good GPS readings, then think about your display.

The key here is to develop your code in stages to prove your hardware and interfacing code.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

1 Like

I got the code here:

and changed "->" into "." and got new error:

Arduino: 1.8.19 (Windows 7), Board: "TTGO LoRa32-OLED V1, 40MHz, 921600, None"






C:\Users\HUA.DELLV-PC\Documents\Arduino\main_cpp_test\main_cpp_test.ino: In function 'void loop()':

main_cpp_test:33:25: error: 'GPS_get' was not declared in this scope

   Serial.printf("%s\n", GPS_get.fix().toString().c_str());

                         ^

main_cpp_test:37:22: error: expected primary-expression before '.' token

     Serial.printf(GPS.get_fix().toString().c_str());

                      ^

main_cpp_test:38:24: error: expected primary-expression before '.' token

     display.println(GPS.get.fix().toString().c_str());

                        ^

exit status 1

'GPS_get' was not declared in this scope



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Maybe because you put the "." in the wrong place?

GPS.get_fix()

1 Like

Thanks.
I got the GPS reading already, and like to have the path shown on a map or even just a blank LCD.
I didn't find any GPS tracker example with display yet.

Thanks.
the GPS.get_fix() got error of:

Arduino: 1.8.19 (Windows 7), Board: "TTGO LoRa32-OLED V1, 40MHz, 921600, None"

C:\Users\HUA.DELLV-PC\Documents\Arduino\main_cpp_test\main_cpp_test.ino: In function 'void loop()':

main_cpp_test:33:28: error: expected primary-expression before '.' token

   Serial.printf("%s\n", GPS.get_fix().toString().c_str());

                            ^

main_cpp_test:37:22: error: expected primary-expression before '.' token

     Serial.printf(GPS.get_fix().toString().c_str());

                      ^

main_cpp_test:38:24: error: expected primary-expression before '.' token

     display.println(GPS.get_fix().toString().c_str());

                        ^

exit status 1

expected primary-expression before '.' token



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

If you have already got the GPS working then please refer to the code that works to see what is different.

1 Like

The difference is the code above that try to make path on a display.

Are you still commenting out

///  gps = new GPS(GPS_SERIAL, GPS_TX, GPS_RX);

?

a7

Nonsense… it is complaining about the GPS code… READ the error.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.