Help figuring whats wrong

i have got this code for a GY-87 and it seems that ut is not working i can not find out what the error messages mean please help. I have attached the ino file to this thread.

here are the errors i get.

gy_87__code:15: error: variable or field ‘Output’ declared void
gy_87__code:15: error: ‘MagnetometerRaw’ was not declared in this scope
gy_87__code:15: error: ‘MagnetometerScaled’ was not declared in this scope
gy_87__code:15: error: expected primary-expression before ‘float’
gy_87__code:15: error: expected primary-expression before ‘float’
gy_87__code:11: error: ‘hmc5883l’ does not name a type
gy_87__code.ino: In function ‘void setup()’:
gy_87__code:22: error: ‘compass’ was not declared in this scope
gy_87__code:22: error: ‘hmc5883l’ was not declared in this scope
gy_87__code:26: error: ‘Measurement_Continuous’ was not declared in this scope
gy_87__code:28: error: ‘bmp085_init’ was not declared in this scope
gy_87__code.ino: In function ‘void doPresAndTemp()’:
gy_87__code:38: error: ‘bmp085Temp’ was not declared in this scope
gy_87__code:39: error: ‘bmp085Pressure’ was not declared in this scope
gy_87__code:42: error: ‘bmp085PascalToMeter’ was not declared in this scope
gy_87__code.ino: In function ‘void doCompass()’:
gy_87__code:110: error: ‘MagnetometerRaw’ was not declared in this scope
gy_87__code:110: error: expected ;' before 'raw' gy_87__code:112: error: 'MagnetometerScaled' was not declared in this scope gy_87__code:112: error: expected ;’ before ‘scaled’
gy_87__code:115: error: ‘scaled’ was not declared in this scope
gy_87__code:139: error: ‘raw’ was not declared in this scope
gy_87__code:139: error: ‘Output’ was not declared in this scope
gy_87__code.ino: At global scope:
gy_87__code:149: error: variable or field ‘Output’ declared void
gy_87__code:149: error: ‘MagnetometerRaw’ was not declared in this scope
gy_87__code:149: error: ‘MagnetometerScaled’ was not declared in this scope
gy_87__code:149: error: expected primary-expression before ‘float’
gy_87__code:149: error: expected primary-expression before ‘float’


gy_87__code.ino (4.57 KB)

The compiler is missing many things. One of the include files for a library (probably hmc5883l.h) seems to have problems.
You have installed 3 libraries (MPU-6050, HMC5883L and BMP085/BMP180). How did you install those libraries and which libraries are they ?
I think you have picked randomly libraries and non-matching include files from the internet. I even doubt if the attached sketch is the sketch that causes those error messages.


thanks for the quick reply and the library are installed just like other library’s which means they do work with the code that they come with it is just when i use this code it means not to work because of those errors.

You have to tell me for every library, which libraries they are (links to them please) and how you have installed them. Did you write that sketch yourself or did you find it somewhere ?

Here’s the code, to save everyone the hassle of downloading it.

#include <Wire.h>
#include <MPU6050.h>
#include <hmc5883l.h>
#include <bmp085.h>

// afdjust to the pressure of today at sealevel for correct altitude
#define PRES_0M 101325.0

MPU6050 mpu;
Vector rawAccel, normAccel, rawGyro, normGyro;
hmc5883l compass;

int error;

void setup() {
  // put your setup code here, to run once:
  // 2000 degrees pr second max and +/- 16 g max
  mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_16G);
  mpu.setI2CBypassEnabled(true); // set bypass mode
  // now we can reach 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.
  error = compass.SetMeasurementMode(Measurement_Continuous); // Set the measurement mode to Continuous



void doPresAndTemp()
  float temp, atm, alt;
  long pres;
  //  bmp085_init();
  temp = bmp085Temp();
  pres = bmp085Pressure();

  atm = pres / PRES_0M; // "standard atmosphere"
  alt = bmp085PascalToMeter(pres, PRES_0M);
  Serial.print("Pres and Temp ");
  Serial.print(" C ");

  Serial.print(" Pa ");

  Serial.print(" (rel atm) ");

  Serial.println( " m ");


void doAcceleration()
  rawAccel = mpu.readRawAccel();
  normAccel = mpu.readNormalizeAccel();
  Serial.print("Acc  ");
  Serial.print(" Xraw = ");
  Serial.print(" Yraw = ");
  Serial.print(" Zraw = ");

  Serial.print(" Xnorm = ");
  Serial.print(" Ynorm = ");
  Serial.print(" Znorm = ");

void doGyro()
  rawGyro = mpu.readRawGyro();
  normGyro = mpu.readNormalizeGyro();
  Serial.print("Gyro ");
  Serial.print(" Xraw = ");
  Serial.print(" Yraw = ");
  Serial.print(" Zraw = ");

  Serial.print(" Xnorm = ");
  Serial.print(" Ynorm = ");
  Serial.print(" Znorm = ");


void doCompass()
  // 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:
  // 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("Cmps  #include <bmp085.h>Raw:\t");
  Serial.print("   ");
  Serial.print("   ");
  Serial.print("   \tScaled:\t");

  Serial.print("   ");
  Serial.print("   ");

  Serial.print("   \tHeading:\t");
  Serial.print(" Radians   \t");
  Serial.println(" Degrees   \t");

void loop() {
  // put your main code here, to run repeatedly:

i got the code and the library's from here

How did you install them ?

like normal by putting them in the sketchbook folder on my laptop

I am willing to install those libraries and do the same thing that you do, but I don't want to guess. We are getting closer to the problem, because how you have added the libraries files is why the compiler is missing things.

Did you put them in the sketchbook folder in your own project folder ("gy_87__code") or in the "libraries" folder ? In sub-folders ?

i put them in the "libraries" folder

In sub folders ?
I think I have enough information, and I can guess the rest. You should have written what you did, but I will do that for you.

The MPU6050 does not have a zip file :frowning:

In the “libraries” folder in the sketch folder, I created a folder “MPU6050” and copied MPU6050.h and MPU6050.cpp into it from here :

I downloaded into the “libraries” folder from here :

I downloaded and into the libraries folder from here :

Then I unpacked those three zip files in their own folder and I removed the three zip files.

I selected an Arduino Uno and compiled your sketch:

Sketch uses 13,850 bytes (42%) of program storage space. Maximum is 32,256 bytes.
Global variables use 832 bytes (40%) of dynamic memory, leaving 1,216 bytes for local variables. Maximum is 2,048 bytes.

It compiled without problem.

Thanks dude ill try that just going to reinstall the liburys like you did and the is the second to last zip file.

saved me a lot of bother

You have to tell what you mean. I'm not a magician. I think you mean the here :
The zip files in the subfolders are other zip files. Perhaps the code in the sub-folders is newer, I did not compare them.

got it all working now haha finally i get going with the project thnaks for the help if i need more help ill put it on this thread.