Ield 'Output' declared void

Hi,
whats wrong with this?
Thanks
Adam

/* https://www.youtube.com/watch?v=lV0qmeOapvg
    https://www.electroniclinic.com/hmc5883l-arduinoarduino-compassmagnetometer-arduino-compass-navigation/


*/

/*
  HMC5883L_Example.pde - Example sketch for integration with an HMC5883L triple axis magnetomerwe.

  This program is free software: you can redistribute it and/or modify
  it under the terms of the version 3 GNU General Public License as
  published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

// Reference the I2C Library
#include <Wire.h>
// Reference the HMC5883L Compass Library
#include <HMC5883L.h>

// Store our compass as a variable.
HMC5883L compass;
// Record any errors that may occur in the compass.
int error = 0;
int ledpin = 13;
// Out setup routine, here we will configure the microcontroller and compass.
void setup()
{
  // Initialize the serial port.
  Serial.begin(9600);
  pinMode(ledpin, OUTPUT);
  Serial.println("Starting the I2C interface.");
  Wire.begin(); // Start the I2C interface.

  Serial.println("Constructing new HMC5883L");
  compass = HMC5883L(); // Construct a new HMC5883 compass.

  Serial.println("Setting scale to +/- 1.3 Ga");
  error = compass.SetScale(1.3); // Set the scale of the compass.
  if (error != 0) // If there is an error, print it out.
    Serial.println(compass.GetErrorText(error));

  Serial.println("Setting measurement mode to continous.");
  error = compass.SetMeasurementMode(Measurement_Continuous); // Set the measurement mode to Continuous
  if (error != 0) // If there is an error, print it out.
    Serial.println(compass.GetErrorText(error));
}

// Our main program loop.
void loop()
{
  // Retrive the raw values from the compass (not scaled).
  MagnetometerRaw raw = compass.ReadRawAxis();
  // Retrived the scaled values from the compass (scaled to the configured scale).
  MagnetometerScaled scaled = compass.ReadScaledAxis();

  // Values are accessed like so:
  int MilliGauss_OnThe_XAxis = scaled.XAxis;// (or YAxis, or ZAxis)

  // Calculate heading when the magnetometer is level, then correct for signs of axis.
  float heading = atan2(scaled.YAxis, scaled.XAxis);

  // Once you have your heading, you must then add your 'Declination Angle', which is the 'Error' of the magnetic field in your location.
  // Find yours here: http://www.magnetic-declination.com/
  // Mine is: 2� 37' W, which is 2.617 Degrees, or (which we need) 0.0456752665 radians, I will use 0.0457
  // If you cannot find your Declination, comment out these two lines, your compass will be slightly off.
  float declinationAngle = 0.0457;
  heading += declinationAngle;

  // Correct for when signs are reversed.
  if (heading < 0)
    heading += 2 * PI;

  // Check for wrap due to addition of declination.
  if (heading > 2 * PI)
    heading -= 2 * PI;

  // Convert radians to degrees for readability.
  float headingDegrees = heading * 180 / M_PI;

  // Output the data via the serial port.
  Output(raw, scaled, heading, headingDegrees);

  // Normally we would delay the application by 66ms to allow the loop
  // to run at 15Hz (default bandwidth for the HMC5883L).
  // However since we have a long serial out (104ms at 9600) we will let
  // it run at its natural speed.
  // delay(66);
}

// Output the data down the serial port.
void Output(MagnetometerRaw raw, MagnetometerScaled scaled, float heading, float headingDegrees)
{
  Serial.print("Raw:\t");
  Serial.print(raw.XAxis);
  Serial.print("   ");
  Serial.print(raw.YAxis);
  Serial.print("   ");
  Serial.print(raw.ZAxis);
  Serial.print("   \tScaled:\t");

  Serial.print(scaled.XAxis);
  Serial.print("   ");
  Serial.print(scaled.YAxis);
  Serial.print("   ");
  Serial.print(scaled.ZAxis);

  Serial.print("   \tHeading:\t");
  Serial.print(heading);
  Serial.print(" Radians   \t");
  Serial.print(headingDegrees);
  Serial.println(" Degrees   \t");
  //delay(1000);
  if ((headingDegrees >= 1) & (headingDegrees <= 45)  )
    digitalWrite(ledpin, HIGH);
  else
    digitalWrite(ledpin, LOW);
}

ERROR:

Arduino: 1.8.3 (Windows 7), Board: "Arduino/Genuino Uno"

HMC5883L_compass_n:100: error: variable or field 'Output' declared void

 void Output(MagnetometerRaw raw, MagnetometerScaled scaled, float heading, float headingDegrees)

             ^

HMC5883L_compass_n:100: error: 'MagnetometerRaw' was not declared in this scope

HMC5883L_compass_n:100: error: 'MagnetometerScaled' was not declared in this scope

 void Output(MagnetometerRaw raw, MagnetometerScaled scaled, float heading, float headingDegrees)

                                  ^

HMC5883L_compass_n:100: error: expected primary-expression before 'float'

 void Output(MagnetometerRaw raw, MagnetometerScaled scaled, float heading, float headingDegrees)

                                                             ^

HMC5883L_compass_n:100: error: expected primary-expression before 'float'

 void Output(MagnetometerRaw raw, MagnetometerScaled scaled, float heading, float headingDegrees)

                                                                            ^

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

HMC5883L_compass_n:47: error: 'class HMC5883L' has no member named 'SetScale'

   error = compass.SetScale(1.3); // Set the scale of the compass.

                   ^

HMC5883L_compass_n:49: error: 'class HMC5883L' has no member named 'GetErrorText'

     Serial.println(compass.GetErrorText(error));

                            ^

HMC5883L_compass_n:52: error: 'class HMC5883L' has no member named 'SetMeasurementMode'

   error = compass.SetMeasurementMode(Measurement_Continuous); // Set the measurement mode to Continuous

                   ^

HMC5883L_compass_n:52: error: 'Measurement_Continuous' was not declared in this scope

   error = compass.SetMeasurementMode(Measurement_Continuous); // Set the measurement mode to Continuous

                                      ^

HMC5883L_compass_n:54: error: 'class HMC5883L' has no member named 'GetErrorText'

     Serial.println(compass.GetErrorText(error));

                            ^

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

HMC5883L_compass_n:61: error: 'MagnetometerRaw' was not declared in this scope

   MagnetometerRaw raw = compass.ReadRawAxis();

   ^

HMC5883L_compass_n:63: error: 'MagnetometerScaled' was not declared in this scope

   MagnetometerScaled scaled = compass.ReadScaledAxis();

   ^

HMC5883L_compass_n:66: error: 'scaled' was not declared in this scope

   int MilliGauss_OnThe_XAxis = scaled.XAxis;// (or YAxis, or ZAxis)

                                ^

HMC5883L_compass_n:90: error: 'raw' was not declared in this scope

   Output(raw, scaled, heading, headingDegrees);

          ^

HMC5883L_compass_n:90: error: 'Output' was not declared in this scope

   Output(raw, scaled, heading, headingDegrees);

                                              ^

C:\Users\HUA.DELLV-PC\Documents\Arduino\HMC5883L_compass_n\HMC5883L_compass_n.ino: At global scope:

HMC5883L_compass_n:100: error: variable or field 'Output' declared void

 void Output(MagnetometerRaw raw, MagnetometerScaled scaled, float heading, float headingDegrees)

             ^

HMC5883L_compass_n:100: error: 'MagnetometerRaw' was not declared in this scope

HMC5883L_compass_n:100: error: 'MagnetometerScaled' was not declared in this scope

 void Output(MagnetometerRaw raw, MagnetometerScaled scaled, float heading, float headingDegrees)

                                  ^

HMC5883L_compass_n:100: error: expected primary-expression before 'float'

 void Output(MagnetometerRaw raw, MagnetometerScaled scaled, float heading, float headingDegrees)

                                                             ^

HMC5883L_compass_n:100: error: expected primary-expression before 'float'

 void Output(MagnetometerRaw raw, MagnetometerScaled scaled, float heading, float headingDegrees)

                                                                            ^

exit status 1
variable or field 'Output' declared void

Sketch uses 6598 bytes (20%) of program storage space. Maximum is 32256 bytes.
Global variables use 528 bytes (25%) of dynamic memory, leaving 1520 bytes for local variables. Maximum is 2048 bytes.
E:\ENGINEERING\DIY\Electronic\ARDUINO\arduino-1.8.3-windows\arduino-1.8.3\hardware\tools\avr/bin/avrdude -CE:\ENGINEERING\DIY\Electronic\ARDUINO\arduino-1.8.3-windows\arduino-1.8.3\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM6 -b115200 -D -Uflash:w:C:\Users\HUA~1.DEL\AppData\Local\Temp\arduino_build_131096/HMC5883L_compass.ino.hex:i 

avrdude: Version 6.3, compiled on Jan 17 2017 at 12:00:53
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "E:\ENGINEERING\DIY\Electronic\ARDUINO\arduino-1.8.3-windows\arduino-1.8.3\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM6
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 3
         Firmware Version: 4.4

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x46

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x69

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x6c
         Vtarget         : 0.3 V
         Varef           : 0.3 V
         Oscillator      : 1.373 Hz
         SCK period      : 7006779.6 us


avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x65

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x20
avrdude: stk500_initialize(): (a) protocol error, expect=0x14, resp=0x20
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x3a

avrdude done.  Thank you.

the selected serial port 
 does not exist or your board is not connected

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

A number of things.

Where is MagnetometerRaw declared and what is the data type?

1 Like

raw is declared as type MagnetometerRaw, and it doesn't work.

Not sure which library you are using, but if you use the Library Manager in the IDE, this example need to change (all functions start will a lowercase name) [This is the Grove 3-axis library]

/* https://www.youtube.com/watch?v=lV0qmeOapvg
    https://www.electroniclinic.com/hmc5883l-arduinoarduino-compassmagnetometer-arduino-compass-navigation/


*/

/*
  HMC5883L_Example.pde - Example sketch for integration with an HMC5883L triple axis magnetomerwe.

  This program is free software: you can redistribute it and/or modify
  it under the terms of the version 3 GNU General Public License as
  published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

// Reference the I2C Library
#include <Wire.h>
// Reference the HMC5883L Compass Library
#include <HMC5883L.h>

// Store our compass as a variable.
HMC5883L compass;
// Record any errors that may occur in the compass.
int error = 0;
int ledpin = 13;
// Out setup routine, here we will configure the microcontroller and compass.
void setup()
{
  // Initialize the serial port.
  Serial.begin(9600);
  pinMode(ledpin, OUTPUT);
  Serial.println("Starting the I2C interface.");
  Wire.begin(); // Start the I2C interface.

  Serial.println("Constructing new HMC5883L");
  compass = HMC5883L(); // Construct a new HMC5883 compass.

  Serial.println("Setting scale to +/- 1.3 Ga");
  error = compass.setScale(1.3); // Set the scale of the compass.
  if (error != 0) // If there is an error, print it out.
    Serial.println(compass.getErrorText(error));

  Serial.println("Setting measurement mode to continous.");
  error = compass.setMeasurementMode(MEASUREMENT_CONTINUOUS); // Set the measurement mode to Continuous
  if (error != 0) // If there is an error, print it out.
    Serial.println(compass.getErrorText(error));
}

// Our main program loop.
void loop()
{
  // Retrive the raw values from the compass (not scaled).
  MagnetometerRaw raw = compass.readRawAxis();
  // Retrived the scaled values from the compass (scaled to the configured scale).
  MagnetometerScaled scaled = compass.readScaledAxis();

  // Values are accessed like so:
  int MilliGauss_OnThe_XAxis = scaled.XAxis;// (or YAxis, or ZAxis)

  // Calculate heading when the magnetometer is level, then correct for signs of axis.
  float heading = atan2(scaled.YAxis, scaled.XAxis);

  // Once you have your heading, you must then add your 'Declination Angle', which is the 'Error' of the magnetic field in your location.
  // Find yours here: http://www.magnetic-declination.com/
  // Mine is: 2� 37' W, which is 2.617 Degrees, or (which we need) 0.0456752665 radians, I will use 0.0457
  // If you cannot find your Declination, comment out these two lines, your compass will be slightly off.
  float declinationAngle = 0.0457;
  heading += declinationAngle;

  // Correct for when signs are reversed.
  if (heading < 0)
    heading += 2 * PI;

  // Check for wrap due to addition of declination.
  if (heading > 2 * PI)
    heading -= 2 * PI;

  // Convert radians to degrees for readability.
  float headingDegrees = heading * 180 / M_PI;

  // Output the data via the serial port.
  Output(raw, scaled, heading, headingDegrees);

  // Normally we would delay the application by 66ms to allow the loop
  // to run at 15Hz (default bandwidth for the HMC5883L).
  // However since we have a long serial out (104ms at 9600) we will let
  // it run at its natural speed.
  // delay(66);
}

// Output the data down the serial port.
void Output(MagnetometerRaw raw, MagnetometerScaled scaled, float heading, float headingDegrees)
{
  Serial.print("Raw:\t");
  Serial.print(raw.XAxis);
  Serial.print("   ");
  Serial.print(raw.YAxis);
  Serial.print("   ");
  Serial.print(raw.ZAxis);
  Serial.print("   \tScaled:\t");

  Serial.print(scaled.XAxis);
  Serial.print("   ");
  Serial.print(scaled.YAxis);
  Serial.print("   ");
  Serial.print(scaled.ZAxis);

  Serial.print("   \tHeading:\t");
  Serial.print(heading);
  Serial.print(" Radians   \t");
  Serial.print(headingDegrees);
  Serial.println(" Degrees   \t");
  //delay(1000);
  if ((headingDegrees >= 1) & (headingDegrees <= 45)  )
    digitalWrite(ledpin, HIGH);
  else
    digitalWrite(ledpin, LOW);
}

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