Help with compiling code

Hi,

I am looking for help with the following code, it is the TX part of software that is used in a weather station that I have built. I am trying to add a rotary encoder to the sketch which uses, GND, 5v, channel A and channel B. I have used a sketch (sketch_may 24a.ino) attached, which was provided by a fellow member of this forum, it compiles
and uploads ok, and it gives the right type output, when viewed on the serial monitor,
The same person the suggested the following might work also :

double getWindVane () {
int n=(windvane.read() &3f)/4;
return pgm_read_word (&vaneDirection[n]);

So this is the mod I am trying to implement into the original software.

I have made a few amendments to the original TX_v1.4_ISTest_boo1.zip which is now TX_v1.4_ISTest_boo1.zip123 when this is compiled I get error message :

ID2_Wind.ino:108:1: error: expected unqualified-id before ‘{’ token

I have incrementally added amendments and compiled after each addition, but I can not get passed this error. so any help will be appreciated,

#ifdef ID2

void send_SensorID2()
#endif
{     
   PacketID = UnitID << 4 | 2;   // Hi nibble UnitID, Lo nibble SensorID
    
  getGust();
  #if WDirSensor_Type < 0 
    WindDir = getWindVane_FO();
  #endif
  #if WDirSensor_Type < 1
    WindDir = getWindVane_RotaryEncoder();
  #endif
  #if WDirSensor_Type < 2 
    WindDir = getWindVane_IS();
  #endif 
  
  #ifdef Local_TestMode
    WindDir_Name    = vaneDirectionsText[(int)(WindDir / 225)]; // --- Convert numeric Wind Direction to Text ------------
  #endif

  sendData(StationID, PacketID, Rolling_WindAvg, WindGust, WindDir, 0);

  #ifdef DebugID2
  printDebugID2();
  #endif
}

void getUnitWind()  // Get Wind Average
{
  unsigned long reading = anem_count;
  unsigned int WindAvg; // within TEST_PAUSE interval

  anem_count = 0;
  double WindAvg_float = (reading * WIND_FACTOR) / TEST_PAUSE;
  WindAvg = (unsigned int)(WindAvg_float * 1000.0);

  raWindAvg.addValue(WindAvg);
  Rolling_WindAvg = raWindAvg.getAverage();
}

void getGust()  // Get Wind Gust
{
  unsigned long reading = anem_min;
  anem_min = 0xffffffff;
  double WindGust_float = (1/(reading/1000000.0)) * WIND_FACTOR;
  WindGust = (unsigned int)(WindGust_float * 1000.0);
  
  // --- Spike Removal -------
  if (WindGust >= 65000 || WindGust < 0) WindGust = last_WindGust;
  last_WindGust = WindGust;
}

void anemometerClick()
{
  long thisTime = micros() - anem_last;
  anem_last = micros();
  if(thisTime > 500)  // Debouncing hardware time ms
  {
    anem_count++;
    if(thisTime < anem_min) anem_min = thisTime;
  }
 }
 
// -------- Wind Directions Functions ---------------

#if WDirSensor_Type == 0
//  Fine Offset Wind Direction Sensor
/*
To save battery power, the wind vane is powered by the digital pin VANE_PWR right before
it is used.  a 100ms delay is inserted after the power pin is driven high just to left
things settle down.  The rest of the function compares the ADC value to the ideal values
in vaneValues, and returns the corresponding wind direction.
*/

double getWindVane_FO()
{
  digitalWrite(VANE_PWR, HIGH);
  delay(100);
  for(int n=0;n<10;n++) {          // Do 10 readings to stabilize ADC
    analogRead(VANE_PIN);
    delay(1);
    }
  unsigned int vane_reading = analogRead(VANE_PIN);

  digitalWrite(VANE_PWR, LOW);
  unsigned int lastDiff=2048;

 for (int n=0; n < 16; n++)
 {
   int diff =vane_reading - pgm_read_word(&vaneValues[n]);
   diff =abs(diff);
   if(diff == 0) return pgm_read_word(&vaneDirections[n]);
   if(diff > lastDiff) return pgm_read_word(&vaneDirections[n-1]);
   lastDiff = diff;  
  }
    return pgm_read_word(&vaneDirections[15]); 
} 
#endif

// ----------------------------------------------------------------------

#if WDirSensor_Type == 1
//RotaryEncoderDirection Sensor -----------------------------------------

double getWindVane();
{
int n=(windvane.read()&3e2)/4;
return pgm_read_word(&vaneDirections[n]);
}
// ----------------------------------------------------------------------
//  Inspeed Wind Direction Sensor ---------------------------------------
#if WDirSensor_Type == 2
double getWindVane_IS()
{
  int WDir_min = 63;
  int WDir_max = 602;
  int WDir_offs = 0;

  //digitalWrite(VANE_PWR, HIGH);
  delay(50);
  for(int n=0;n<10;n++) {          // Do 10 readings to stabilize ADC
    analogRead(VANE_PIN);
    delay(1);
    }
  unsigned int vane_reading = analogRead(VANE_PIN);
  //digitalWrite(VANE_PWR, LOW);

  // calc and store the current wind dir
  long wind_dir;    // needs to be long for overflow protection in math
  wind_dir = ((vane_reading - WDir_min) *  360L) / (WDir_max - WDir_min);
  wind_dir += WDir_offs;

  // Precaution in case the calib values are wrong or slightly off
  if (wind_dir > 360)
    wind_dir = 360;
  else if (wind_dir < 0)
    wind_dir = 0;


  return wind_dir * 10;
}
#endif

#endif






/*
The datasheet shows that the rain gauge and the anemometer are magnetic reed switches;
every 0.011″ of rain causes a momentary contact and a 2.4km/h wind will cause a momentary
contact every second for the anemometer.  These inputs will be connected to Arduino interrupts.
The wind vane uses an array of resistors which can be read through the ADC of the Arduino,
but the datasheet is wrong for the wind vane.  At 315°, the datasheet states that the voltage
should be 4.78V, but in actuality, with a 10K resistor in series with a 64.9K resistor,
the voltage drop across the vane will be 4.33V.

Note that setting a pin to INPUT and then writing a HIGH value to it turns on the internal 20K
pull up resistor in the Arduino, which prevents the need for external pull up resistors on
the interrupt driven devices.  The wind vane requires a 10K resistor in series with the vane’s
resistors, and to save power, this resistor and the vane are powered from a digital output,
which is driven HIGH only when the reading is to be taken.
*/

Regards

tyntop

WeatherDuino_TX_v1.4_ISTest_b001.zip (11.9 KB)

sketch_may24a.ino (455 Bytes)

WeatherDuino_TX_v1.4_ISTest_b001.zip (11.8 KB)

#ifdef ID2

void send_SensorID2()
#endif
{

If ID2 isn't defined, then the first line of the function definition won't be there and it looks like a rogue { and block of code outside of any function. I'm not sure what you intend for this to accomplish, but it is almost definitely wrong.

Hi thanks for reply

The weather station I have built, which is working fine, uses a anemometer and wind direction vane which uses reed switches, the person who has developed this particular station has recently added mods to support, hall effect sensors (anemometer) and some other commercially available hardware. I personally just wanted to try using a rotary encoder (windvane) which I had available.

The weather station I have built is the Weatherduino-Pro2 system which uses a nano as the processor

http://www.meteocercal.info/forum/Forum-WeatherDuino-Pro2

//#ifdef ID2

void send_SensorID2()
//#endif

{