error: expected constructor, destructor, or type conversion before '('

Hello everyone,
I am trying an example of the library "Adafruit_gps" and all i changed in it was comment the parts related to the "softwareserial" library as the arduino im using (Arduino MKR FOX 1200) is not compatible with that library. I am getting the error:

error: expected constructor, destructor, or type conversion before '(' token SIGNAL(TIMER0_COMPA_vect) {

in my code but i am not sure what it means and what i should do. (I am a noob btw)

one more question: in the tutorial it says to connect to ports 2 and 3 but since i cant use "softwareserial" library i connected the GPS to the RX and TX ports instead (13 and 14). Do i need to add anything to the code for it to work or will it automatically detect the ports?

The full code:

// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
//
// This code just echos whatever is coming from the GPS unit to the
// serial monitor, handy for debugging!
//
// Tested and works great with the Adafruit Ultimate GPS module
// using MTK33x9 chipset
//    ------> http://www.adafruit.com/products/746
// Pick one up today at the Adafruit electronics shop 
// and help support open source hardware & software! -ada

/*#include <Adafruit_GPS.h>
#if ARDUINO >= 100
 #include <SoftwareSerial.h>
#else
  // Older Arduino IDE requires NewSoftSerial, download from:
  // http://arduiniana.org/libraries/newsoftserial/
// #include <NewSoftSerial.h>
 // DO NOT install NewSoftSerial if using Arduino 1.0 or later!
#endif */

// Connect the GPS Power pin to 5V
// Connect the GPS Ground pin to ground
// If using software serial (sketch example default):
//   Connect the GPS TX (transmit) pin to Digital 3
//   Connect the GPS RX (receive) pin to Digital 2
// If using hardware serial (e.g. Arduino Mega):
//   Connect the GPS TX (transmit) pin to Arduino RX1, RX2 or RX3
//   Connect the GPS RX (receive) pin to matching TX1, TX2 or TX3

// If using software serial, keep these lines enabled
// (you can change the pin numbers to match your wiring):
/*#if ARDUINO >= 100
  SoftwareSerial mySerial(3, 2);
#else
  NewSoftSerial mySerial(3, 2);
#endif
Adafruit_GPS GPS(&mySerial);*/
// If using hardware serial (e.g. Arduino Mega), comment
// out the above six lines and enable this line instead:
//Adafruit_GPS GPS(&Serial1);


// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO  true

// this keeps track of whether we're using the interrupt
// off by default!
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy

void setup()  
{    
  // connect at 115200 so we can read the GPS fast enuf and
  // also spit it out
  Serial.begin(115200);
  Serial.println("Adafruit GPS library basic test!");

  // 9600 NMEA is the default baud rate for MTK - some use 4800
  GPS.begin(9600);
  
  // You can adjust which sentences to have the module emit, below
  
  // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  // uncomment this line to turn on only the "minimum recommended" data for high update rates!
  //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  // uncomment this line to turn on all the available data - for 9600 baud you'll want 1 Hz rate
  //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_ALLDATA);
  
  // Set the update rate
  // Note you must send both commands below to change both the output rate (how often the position
  // is written to the serial line), and the position fix rate.
  // 1 Hz update rate
  //GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
  //GPS.sendCommand(PMTK_API_SET_FIX_CTL_1HZ);
  // 5 Hz update rate- for 9600 baud you'll have to set the output to RMC or RMCGGA only (see above)
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_5HZ);
  GPS.sendCommand(PMTK_API_SET_FIX_CTL_5HZ);
  // 10 Hz update rate - for 9600 baud you'll have to set the output to RMC only (see above)
  // Note the position can only be updated at most 5 times a second so it will lag behind serial output.
  //GPS.sendCommand(PMTK_SET_NMEA_UPDATE_10HZ);
  //GPS.sendCommand(PMTK_API_SET_FIX_CTL_5HZ);

  // Request updates on antenna status, comment out to keep quiet
  GPS.sendCommand(PGCMD_ANTENNA);

  // the nice thing about this code is you can have a timer0 interrupt go off
  // every 1 millisecond, and read data from the GPS for you. that makes the
  // loop code a heck of a lot easier!
  useInterrupt(true);
  
  delay(1000);
}

// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect) {
  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
  if (GPSECHO)
    if (c) UDR0 = c;  
    // writing direct to UDR0 is much much faster than Serial.print 
    // but only one character can be written at a time. 
}

void useInterrupt(boolean v) {
  if (v) {
    // Timer0 is already used for millis() - we'll just interrupt somewhere
    // in the middle and call the "Compare A" function above
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
    usingInterrupt = true;
  } else {
    // do not call the interrupt function COMPA anymore
    TIMSK0 &= ~_BV(OCIE0A);
    usingInterrupt = false;
  }
}


void loop()                     // run over and over again
{
   // do nothing! all reading and printing is done in the interrupt
}

Thanks in advance.

might be void SIGNAL(TIMER0_COMPA_vect) {

or

 static void SIGNAL(TIMER0_COMPA_vect) {

but not:

SIGNAL(TIMER0_COMPA_vect) {

Idahowalker:
might be

void SIGNAL(TIMER0_COMPA_vect) {

or

 static void SIGNAL(TIMER0_COMPA_vect) {

but not:

SIGNAL(TIMER0_COMPA_vect) {

?

the arduino im using (Arduino MKR FOX 1200) is not compatible

Saif_M:
in my code but i am not sure what it means and what i should do. (I am a noob btw)

As a (self-proclaimed) noob, it would probably behoove you to stick with a supported and proven hardware / software combination in order to get this working for the first time. You can experiment with changing stuff around after you have a little better idea of what you’re doing.

gfvalvo:
As a (self-proclaimed) noob, it would probably behoove you to stick with a supported and proven hardware / software combination in order to get this working for the first time. You can experiment with changing stuff around after you have a little better idea of what you’re doing.

This is good advice ! on the other matter referring to the Serial port , if you want to use a hwSerial,
this part of the code should give you some idea of what you should do

// If using hardware serial (e.g. Arduino Mega), comment
// out the above six lines and enable this line instead:
//Adafruit_GPS GPS(&Serial1);

it should then probably be "&Serial" then it know which pins you want to use (if 13 & 14 are you hwSerial pins)

Idahowalker:
might be void SIGNAL(TIMER0_COMPA_vect) {

or

 static void SIGNAL(TIMER0_COMPA_vect) {

but not:

SIGNAL(TIMER0_COMPA_vect) {

Thanks for the idea. I tried it but it didnt work unfortunately

AWOL:
?

So the function:

SIGNAL(TIMER0_COMPA_vect) {

is in the softwareserial library? if so can you tell me if there is another function to replace. Also when i remove the code:

SIGNAL(TIMER0_COMPA_vect) {

I found out that there are more errors:

/tmp/322970373/echo_copy/echo_copy.ino:98:8: error: expected constructor, destructor, or type conversion before '(' token

SIGNAL(TIMER0_COMPA_vect) {

^

/tmp/322970373/echo_copy/echo_copy.ino: In function 'void setup()':

/tmp/322970373/echo_copy/echo_copy.ino:61:3: error: 'GPS' was not declared in this scope

GPS.begin(9600);

^

/tmp/322970373/echo_copy/echo_copy.ino: At global scope:

/tmp/322970373/echo_copy/echo_copy.ino:98:7: error: expected constructor, destructor, or type conversion before '(' token

SIGNAL(TIMER0_COMPA_vect) {

^

/tmp/322970373/echo_copy/echo_copy.ino: In function 'void useInterrupt(boolean)':

/tmp/322970373/echo_copy/echo_copy.ino:111:5: error: 'OCR0A' was not declared in this scope

OCR0A = 0xAF;

^

/tmp/322970373/echo_copy/echo_copy.ino:112:5: error: 'TIMSK0' was not declared in this scope

TIMSK0 |= _BV(OCIE0A);

^

/tmp/322970373/echo_copy/echo_copy.ino:112:19: error: 'OCIE0A' was not declared in this scope

TIMSK0 |= _BV(OCIE0A);

^

/tmp/322970373/echo_copy/echo_copy.ino:112:25: error: '_BV' was not declared in this scope

TIMSK0 |= _BV(OCIE0A);

^

/tmp/322970373/echo_copy/echo_copy.ino:116:5: error: 'TIMSK0' was not declared in this scope

TIMSK0 &= ~_BV(OCIE0A);

^

/tmp/322970373/echo_copy/echo_copy.ino:116:20: error: 'OCIE0A' was not declared in this scope

TIMSK0 &= ~_BV(OCIE0A);

^

/tmp/322970373/echo_copy/echo_copy.ino:116:26: error: '_BV' was not declared in this scope

TIMSK0 &= ~_BV(OCIE0A);

^

exit status 1

So the function ... is in the softwareserial library?

Is that a question or a statement?

I do not see the SIGNAL() macro in the SoftwareSerial library.

OP: I really think you need to go back and read reply #4. or, test. some other way, that the SoftwareSerial library is compatible with the board you are using.

I use an Adafruit Ultimate GPS in the following fashion on a Uno, a Mega and Mino Pro. I changed the way it operates on a DUE, STM32 and ESP32:

Showing relevant code for GPS.

#include <MsTimer2.h>
#include <Adafruit_GPS.h>

//pin3 to GPS rx - yellow wire
//pin2 to GPS tx - orange wire
SoftwareSerial mySerial(3, 2);
Adafruit_GPS GPS(&mySerial);


void setup() {

  GPS.begin(9600);

  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); // has speed n altitude
  // Note you must send both commands below to change both the output rate (how often the position
  // is written to the serial line), and the position fix rate.
  // 1 Hz update rate
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
  GPS.sendCommand(PMTK_API_SET_FIX_CTL_1HZ);
  //turn off antenna data being sent
  GPS.sendCommand("$PGCMD,33,0*6D/r/n");
  //speed threshold level
  //0/0.2/0.4/0.5/0.8/1.0/1.5/2.0 m/s
  //GPS.sendCommand("$PMTK397,0.2*3F/r/n");

 //  //set time on ms for overflow, each overflow causes xFunc, void w no parameters, to be called
  MsTimer2::set(1, GPSSIGNAL);
  //enable interrupt
  MsTimer2::start();
  //disable interrupt
  //MsTimer2::stop()

}//end setup

//***************************************************************************************
//// Interrupt is called once a millisecond, does a data read so main loop can parse GPS data
//***************************************************************************************
void GPSSIGNAL()
{
  //cause a GPS data read so that the
  //if (GPS.newNMEAreceived())
  //can do its thing
  GPS.read();
}

void loop() {


/////////////////////////////////////////////////////////////////
// place all loop code that must run above the below entry:
  //leave this code alone!!!!!!!!!!!!!!!!!!!!!
  //query GPS: has a new complete chunk of data been received?
  if (GPS.newNMEAreceived())
  {
    //if received cause parse data
    if (!GPS.parse(GPS.lastNMEA()))
      //else exit routine
      return;
  }

 if (GPS.fix)
  {

//DoTheGPSThings;

// any code after the if (!GPS.parse(GPS.lastNMEA())) may or may not run depending on the statement validation
// note:if (!GPS.parse(GPS.lastNMEA())) if that statement fails there is a return that restarts the loop.
 }
}

The use of <MsTimer2.h> will stop tone and pwm on pin 9 not to work.

I changed the way it operates on a DUE, STM32 and ESP32:

Changed it how?

Why would you use SoftwareSerial on a Mega? Why would you try to use SoftwareSerial on pins that don't, on the Mega, support pin change interrupts? Clearly, that code will NOT work on a Mega.

gfvalvo:
As a (self-proclaimed) noob, it would probably behoove you to stick with a supported and proven hardware / software combination in order to get this working for the first time. You can experiment with changing stuff around after you have a little better idea of what you’re doing.

I would love to do that but this is for the project in Uni and i needed to use an arduino that can send emails from anywhere(doesnt rely on wifi) thats why i choose this arduino board

Deva_Rishi:
This is good advice ! on the other matter referring to the Serial port , if you want to use a hwSerial,
this part of the code should give you some idea of what you should do

// If using hardware serial (e.g. Arduino Mega), comment

// out the above six lines and enable this line instead:
//Adafruit_GPS GPS(&Serial1);


it should then probably be "&Serial" then it know which pins you want to use (if 13 & 14 are you hwSerial pins)

Thanks for the advice i will try it out

PaulS:
Is that a question or a statement?

I do not see the SIGNAL() macro in the SoftwareSerial library.

Thats why i was confused. I dont know why it gives me that error. I did try to use the softwareserial with my board but it is not compatible.

Idahowalker:
I use an Adafruit Ultimate GPS in the following fashion on a Uno and a Mega, I changed the way it operates on a DUE, STM32 and ESP32:

Showing relevant code for GPS.

#include <MsTimer2.h>

#include <Adafruit_GPS.h>

//pin3 to GPS rx - yellow wire
//pin2 to GPS tx - orange wire
SoftwareSerial mySerial(3, 2);
Adafruit_GPS GPS(&mySerial);

void setup() {

GPS.begin(9600);

GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); // has speed n altitude
  // Note you must send both commands below to change both the output rate (how often the position
  // is written to the serial line), and the position fix rate.
  // 1 Hz update rate
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
  GPS.sendCommand(PMTK_API_SET_FIX_CTL_1HZ);
  //turn off antenna data being sent
  GPS.sendCommand("$PGCMD,33,06D/r/n");
  //speed threshold level
  //0/0.2/0.4/0.5/0.8/1.0/1.5/2.0 m/s
  //GPS.sendCommand("$PMTK397,0.2
3F/r/n");

//  //set time on ms for overflow, each overflow causes xFunc, void w no parameters, to be called
  MsTimer2::set(1, GPSSIGNAL);
  //enable interrupt
  MsTimer2::start();
  //disable interrupt
  //MsTimer2::stop()

}//end setup

//***************************************************************************************
//// Interrupt is called once a millisecond, does a data read so main loop can parse GPS data
//***************************************************************************************
void GPSSIGNAL()
{
  //cause a GPS data read so that the
  //if (GPS.newNMEAreceived())
  //can do its thing
  GPS.read();
}

void loop() {

/////////////////////////////////////////////////////////////////
// place all loop code that must run above the below entry:
  //leave this code alone!!!!!!!!!!!!!!!!!!!!!
  //query GPS: has a new complete chunk of data been received?
  if (GPS.newNMEAreceived())
  {
    //if received cause parse data
    if (!GPS.parse(GPS.lastNMEA()))
      //else exit routine
      return;
  }

if (GPS.fix)
  {

//DoTheGPSThings;

// any code after the if (!GPS.parse(GPS.lastNMEA())) may or may not run depending on the statement validation
// note:if (!GPS.parse(GPS.lastNMEA())) if that statement fails there is a return that restarts the loop.
}
}




The use of <MsTimer2.h> will stop tone and pwm on pin 9 not to work.

Thanks i will check it out.

PaulS:
Changed it how?

Why would you use SoftwareSerial on a Mega? Why would you try to use SoftwareSerial on pins that don't, on the Mega, support pin change interrupts? Clearly, that code will NOT work on a Mega.

Oi! That's probably why I moved on to a DUE from a MEGA. Actually, I was not happy with trying to get the MEGA to work with uMT.

The DUE, on the other hand, ran uMT real well and I, on the DUE, switched over to using hardware serial. Still the DUE is to big for a portable device so in came the STM32

When I ported over to STM32, I switched to using freeRTOS but ran into space issues when adding in UTM conversion code. Plus the lat / lon to UTM code is a dog on the STM32 blue pill.

With the ESP32, I am able to get the, brute force, precision of distance traveled, use hardware serial, use freeROTS, do UTM conversions, run the display in a speedy and snappy fashion, and get a portable hand held unit that runs for 9+ hours on batteries.