"not declared in this scope" FRUSTRATING!!!

I find this to be a most illusive error! It often goes away when I have corrected the other errors.

I am trying to convert my serial telemetry software to UDP. Most of the software is a direct copy from a tested and working version but a function call (subroutine) is now causing an error that it didn’t cause before and I’ll be damned if I can find the error!

This is the code:

/*
 * Convert to UDP Ethernet 06/02/2017
  Telemetry Transmit with 10DOF Sensors
 */


#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_BMP085_U.h>
#include <Adafruit_L3GD20_U.h>
#include <Adafruit_10DOF.h>
#include <UIPEthernet.h>

EthernetUDP udp;

// Assign a unique ID to the sensors
Adafruit_10DOF                dof   = Adafruit_10DOF();
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
Adafruit_LSM303_Mag_Unified   mag   = Adafruit_LSM303_Mag_Unified(30302);
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

//Define soft variables

int compass = 0 ; // Compass in degrees, default 0 degrees
int pressure = 600 ; // Pressure in Pascals,
int pitch = 0 ; // pitch in degrees
int checksum = 0 ;
int len ;
int numBytes ;
// Timing

int tick = 0 ; // 1 Second clock
unsigned long currentT = 0 ;
unsigned long lastT = 0 ;


struct DOFDATA
{
  uint16_t compass;
  uint16_t pressure;
  uint16_t pitch;
  uint16_t checksum ;
};

float heading ;

//************** SETUP ***********************

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  uint8_t mac[6] = {0x11,0x22,0x33,0x04,0x05,0x06};
  Ethernet.begin(mac,IPAddress(10,0,199,5));
  Serial.begin(9600);
  
 /* 
  // Initialise the sensors
    Serial.println("initialize sensors"); 

  if(!accel.begin())
  {
    // There was a problem detecting the LSM303 ... check your connections
    Serial.println(F("Ooops, no LSM303 detected ... Check your wiring!"));
    while(1);
  }

  if(!mag.begin())
  {
    // There was a problem detecting the LSM303 ... check your connections 
    Serial.println("Ooops, no LSM303 detected ... Check your wiring!");
    while(1);
  }
    Serial.println("initialized mag");
  
  if(!bmp.begin())
  {
    // There was a problem detecting the BMP180 ... check your connections
    Serial.println("Ooops, no BMP180 detected ... Check your wiring!");
    while(1);
  }
      Serial.println("initialize bmp");

  Serial.println("Tx Started here");
*/



}

//************** LOOP ***********************

void loop() {

// 1 Second timer loop
  (currentT = (millis()/1000)) ;
  if (currentT > lastT) {
    
    (lastT = currentT ) ;
    tick++  ;  
  }
    
  if (tick >= 6) {
   (tick = 0) ;
  }

  switch(tick){

  case 3: {
    upData () ; // update data
//    sensorRead() ; // read sensors
    tick++ ;
    break ;
  }

  case 5: {
    sendData () ; //transmit data
    tick++ ;
    break ;
  }
  }  
} 
  
// *********************** Sensor Reads *****************  
void sensorRead(){
  sensors_event_t accel_event;
  sensors_event_t mag_event;
  sensors_event_t bmp_event;
  sensors_vec_t   orientation;

  // Calculate pitch and roll from the raw accelerometer data
  accel.getEvent(&accel_event);
  if (dof.accelGetOrientation(&accel_event, &orientation))
  {
    // 'orientation' should have valid .roll and .pitch fields

    (pitch =(orientation.pitch));
 
    
  // Get a new sensor event
  sensors_event_t event;
  bmp.getEvent(&event);
 
  // Display the results (barometric pressure is measure in hPa)
  if (event.pressure)
  {
    // Display atmospheric pressure in hPa
    (pressure = (event.pressure));
  }
  else
  {
    Serial.println("Sensor error");
  }
  }
  
  // Calculate the heading using the magnetometer
  mag.getEvent(&mag_event);
  if (dof.magGetOrientation(SENSOR_AXIS_Z, &mag_event, &orientation))
  {
    // 'orientation' should have valid .heading data now

    (compass = (orientation.heading));

  } 

  return ;

}

// ******************* DATA SEND ****************

void sendData (){

  // data to send
  
  DOFDATA dd;
  dd.compass = compass ; // 0 to 359 degrees, 0 to 168$
  dd.pressure = pressure ; //  to 1200 "H2O, 0 to 4B0$
  dd.pitch = pitch ; // -20 to +20 Degrees, ffec to 14$
  dd.checksum = checksum ;

  udp.beginPacket(IPAddress(10,0,199,6),5000);
  
  int numBytes = udp.write((byte*)&dd, sizeof(dd));


  Serial.print ("Heading ") ;
  Serial.println (compass) ;
  
  Serial.print ("Pressure ") ; 
  Serial.println (pressure) ;

  Serial.print ("Pitch ") ; 
  Serial.println (pitch) ; 


  Serial.print ("Checksum ") ;
  Serial.println (checksum) ;
  Serial.println (" ") ;

 }  
  return ;
}

************************************************

  // Create fake data
  
void upData () { // inc. fudged data values


  compass=(compass+10) ;  // inc. compass 0 to 359 degrees, 0 to 168$
  if (compass>360) {
    compass=0 ;
  }

  pressure  = (pressure +10) ; // inc pressure // 0 to 1200 "H2O, 0 to 4B0$
  if (pressure>1200) {
    pressure = 0 ;
      }

  pitch++ ; // inc pitch // -20 to +20 Degrees, ffec to 14$
  if (pitch>20) {
    pitch= (-20) ;
  }
  return ;
}

And these are the error messages:

Arduino: 1.6.13 (Windows 7), Board: "Arduino Nano, ATmega328"

WARNING: Category '' in library UIPEthernet is not valid. Setting to 'Uncategorized'
C:\Users\Dianne\Documents\Arduino\Transmit_3_0\Transmit_3_0.ino: In function 'void loop()':

Transmit_3_0:113: error: 'upData' was not declared in this scope

     upData () ; // update data

             ^

C:\Users\Dianne\Documents\Arduino\Transmit_3_0\Transmit_3_0.ino: At global scope:

Transmit_3_0:205: error: expected unqualified-id before 'return'

   return ;

   ^

Transmit_3_0:206: error: expected declaration before '}' token

 }

 ^

exit status 1
'upData' was not declared in this scope

If anyone can see the error that I am blind to, I am deeply in your debt!

It looks to me like the function sendData needs a little more attention.

I find this to be a most illusive error!

No, it's perfectly real.

AWOL:
It looks to me like the function sendData needs a little more attention.

Quite likely! I was just starting to work on that but can't compile because of the errors shown above and can't figure what is wrong with the upData routine that WAS working fine and was a direct copy.

can’t figure what is wrong with the upData routine that WAS working fine and was a direct copy.

If you properly indented your code, you’d KNOW what the problem is.

Put EVERY { on a line BY ITSELF.
Put EVERY } on a line BY ITSELF.

Properly indent the code between each { and it’s matching }. When you find a } without a matching {, you’ll see the same problem that AWOL did.

I must be dense as a stone today because I STILL can't find a miss-matched pair of { and } !!!

PaulS:
If you properly indented your code, you’d KNOW what the problem is.

Put EVERY { on a line BY ITSELF.
Put EVERY } on a line BY ITSELF.

Properly indent the code between each { and it’s matching }. When you find a } without a matching {, you’ll see the same problem that AWOL did.

Although I agree every {} should be on its own line. ‘Proper’ is a matter of opinion. Even the IDE does it the same way as the source from DianneB.

void sendData (){

  // data to send
 
  DOFDATA dd;
  dd.compass = compass ; // 0 to 359 degrees, 0 to 168$
  dd.pressure = pressure ; //  to 1200 "H2O, 0 to 4B0$
  dd.pitch = pitch ; // -20 to +20 Degrees, ffec to 14$
  dd.checksum = checksum ;

  udp.beginPacket(IPAddress(10,0,199,6),5000);
 
  int numBytes = udp.write((byte*)&dd, sizeof(dd));


  Serial.print ("Heading ") ;
  Serial.println (compass) ;
 
  Serial.print ("Pressure ") ;
  Serial.println (pressure) ;

  Serial.print ("Pitch ") ;
  Serial.println (pitch) ;


  Serial.print ("Checksum ") ;
  Serial.println (checksum) ;
  Serial.println (" ") ;

 } 
  return ;
}

Look at the last three lines. Which } closes the function? What is the other code doing?

True - found that, revised code

void sendData (){

  // data to send
  
  DOFDATA dd;
  dd.compass = compass ; // 0 to 359 degrees, 0 to 168$
  dd.pressure = pressure ; //  to 1200 "H2O, 0 to 4B0$
  dd.pitch = pitch ; // -20 to +20 Degrees, ffec to 14$
  dd.checksum = checksum ;

  udp.beginPacket(IPAddress(10,0,199,6),5000);
  
  int numBytes = udp.write((byte*)&dd, sizeof(dd));

  Serial.print ("Heading ") ;
  Serial.println (compass) ;
  
  Serial.print ("Pressure ") ; 
  Serial.println (pressure) ;

  Serial.print ("Pitch ") ; 
  Serial.println (pitch) ; 


  Serial.print ("Checksum ") ;
  Serial.println (checksum) ;
  Serial.println (" ") ;

  return ;
}

STILL getting errors about upData

Arduino: 1.6.13 (Windows 7), Board: "Arduino Nano, ATmega328"

WARNING: Category '' in library UIPEthernet is not valid. Setting to 'Uncategorized'
C:\Users\Dianne\Documents\Arduino\Transmit_3_0\Transmit_3_0.ino: In function 'void loop()':

Transmit_3_0:113: error: 'upData' was not declared in this scope

     upData () ; // update data

             ^

C:\Users\Dianne\Documents\Arduino\Transmit_3_0\Transmit_3_0.ino: At global scope:

Transmit_3_0:209: error: expected unqualified-id before 'void'

 void upData ()

 ^

Transmit_3_0:209: error: expected constructor, destructor, or type conversion before 'void'

exit status 1
'upData' was not declared in this scope

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

Code as it stands now:

/*
 * Convert to UDP Ethernet 06/02/2017
  Telemetry Transmit with 10DOF Sensors
 */


#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_BMP085_U.h>
#include <Adafruit_L3GD20_U.h>
#include <Adafruit_10DOF.h>
#include <UIPEthernet.h>

EthernetUDP udp;

// Assign a unique ID to the sensors
Adafruit_10DOF                dof   = Adafruit_10DOF();
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
Adafruit_LSM303_Mag_Unified   mag   = Adafruit_LSM303_Mag_Unified(30302);
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

//Define soft variables

int compass = 0 ; // Compass in degrees, default 0 degrees
int pressure = 600 ; // Pressure in Pascals,
int pitch = 0 ; // pitch in degrees
int checksum = 0 ;
int len ;
int numBytes ;
// Timing

int tick = 0 ; // 1 Second clock
unsigned long currentT = 0 ;
unsigned long lastT = 0 ;


struct DOFDATA
{
  uint16_t compass;
  uint16_t pressure;
  uint16_t pitch;
  uint16_t checksum ;
};

float heading ;

//************** SETUP ***********************

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  uint8_t mac[6] = {0x11,0x22,0x33,0x04,0x05,0x06};
  Ethernet.begin(mac,IPAddress(10,0,199,5));
  Serial.begin(9600);
  
 /* 
  // Initialise the sensors
    Serial.println("initialize sensors"); 

  if(!accel.begin())
  {
    // There was a problem detecting the LSM303 ... check your connections
    Serial.println(F("Ooops, no LSM303 detected ... Check your wiring!"));
    while(1);
  }

  if(!mag.begin())
  {
    // There was a problem detecting the LSM303 ... check your connections 
    Serial.println("Ooops, no LSM303 detected ... Check your wiring!");
    while(1);
  }
    Serial.println("initialized mag");
  
  if(!bmp.begin())
  {
    // There was a problem detecting the BMP180 ... check your connections
    Serial.println("Ooops, no BMP180 detected ... Check your wiring!");
    while(1);
  }
      Serial.println("initialize bmp");

  Serial.println("Tx Started here");
*/



}

//************** LOOP ***********************

void loop() {

// 1 Second timer loop
  (currentT = (millis()/1000)) ;
  if (currentT > lastT) {
    
    (lastT = currentT ) ;
    tick++  ;  
  }
    
  if (tick >= 6) {
   (tick = 0) ;
  }

  switch(tick){

  case 3: {
    upData () ; // update data
//    sensorRead() ; // read sensors
    tick++ ;
    break ;
  }

  case 5: {
    sendData () ; //transmit data
    tick++ ;
    break ;
  }
  }  
} 
  
// *********************** Sensor Reads *****************  
void sensorRead()
{
  sensors_event_t accel_event;
  sensors_event_t mag_event;
  sensors_event_t bmp_event;
  sensors_vec_t   orientation;

  // Calculate pitch and roll from the raw accelerometer data
  accel.getEvent(&accel_event);
  if (dof.accelGetOrientation(&accel_event, &orientation))
    {
      // 'orientation' should have valid .roll and .pitch fields

      (pitch =(orientation.pitch));
 
    
   // Get a new sensor event
    sensors_event_t event;
    bmp.getEvent(&event);
 
  // Display the results (barometric pressure is measure in hPa)
    if (event.pressure)
      {
    // Display atmospheric pressure in hPa
    (pressure = (event.pressure));
       }
  else
    {
    Serial.println("Sensor error");
    }
  }
  
  // Calculate the heading using the magnetometer
  mag.getEvent(&mag_event);
  if (dof.magGetOrientation(SENSOR_AXIS_Z, &mag_event, &orientation))
    {
    // 'orientation' should have valid .heading data now

    (compass = (orientation.heading));

    } 

  return ;

}

// ******************* DATA SEND ****************

void sendData (){

  // data to send
  
  DOFDATA dd;
  dd.compass = compass ; // 0 to 359 degrees, 0 to 168$
  dd.pressure = pressure ; //  to 1200 "H2O, 0 to 4B0$
  dd.pitch = pitch ; // -20 to +20 Degrees, ffec to 14$
  dd.checksum = checksum ;

  udp.beginPacket(IPAddress(10,0,199,6),5000);
  
  int numBytes = udp.write((byte*)&dd, sizeof(dd));

  Serial.print ("Heading ") ;
  Serial.println (compass) ;
  
  Serial.print ("Pressure ") ; 
  Serial.println (pressure) ;

  Serial.print ("Pitch ") ; 
  Serial.println (pitch) ; 


  Serial.print ("Checksum ") ;
  Serial.println (checksum) ;
  Serial.println (" ") ;

  return ;
}

************************************************

void upData (){
  // inc. fudged data values

  compass=(compass+10) ;  // inc. compass 0 to 359 degrees, 0 to 168$
  if (compass>360)  {
    compass=0 ;
      }

  pressure  = (pressure +10) ; // inc pressure // 0 to 1200 "H2O, 0 to 4B0$
  if (pressure>1200) {
    pressure = 0 ;
      }

  pitch++ ; // inc pitch // -20 to +20 Degrees, ffec to 14$
  if (pitch>20) {
    pitch= (-20) ;
   }
  return ;
}

Errors:

Arduino: 1.6.13 (Windows 7), Board: "Arduino Nano, ATmega328"

WARNING: Category '' in library UIPEthernet is not valid. Setting to 'Uncategorized'
C:\Users\Dianne\Documents\Arduino\Transmit_3_0\Transmit_3_0.ino: In function 'void loop()':

Transmit_3_0:113: error: 'upData' was not declared in this scope

     upData () ; // update data

             ^

C:\Users\Dianne\Documents\Arduino\Transmit_3_0\Transmit_3_0.ino: At global scope:

Transmit_3_0:209: error: expected unqualified-id before 'void'

 void upData (){

 ^

Transmit_3_0:209: error: expected constructor, destructor, or type conversion before 'void'

exit status 1
'upData' was not declared in this scope

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

OH CRAP!!!

Found the problem:

The visual divider before the upData routine

"************************************************"

SHOULD have started with "//" but they got lost in the Copy/Paste

Added the proper comment symbol (//) and all errors gone.

Thanks for you help guys!!!!!!