Error Reading Class on Library - PLEASE HELP

i want to try calibrate my sensor compass but the code has an error
this is the error message: 'class HMC5883L' has no member named 'begin'. then i try to command the syntax, but there still has an error for other class.

anybody know? please help me.. Thank You

this is the code

  HMC5883L Triple Axis Digital Compass. Compass Example.
  Read more:
  (c) 2014 by Korneliusz Jarzebski

#include <Wire.h>
#include <HMC5883L.h>

HMC5883L compass;

void setup()

  // Initialize Initialize HMC5883L
  Serial.println("Initialize HMC5883L");
  while (!compass.begin())
    Serial.println("Could not find a valid HMC5883L sensor, check wiring!");

  // Set measurement range

  // Set measurement mode

  // Set data rate

  // Set number of samples averaged

  // Set calibration offset. See HMC5883L_calibration.ino
  compass.setOffset(0, 0);

void loop()
  Vector norm = compass.readNormalize();

  // Calculate heading
  float heading = atan2(norm.YAxis, norm.XAxis);

  // Set declination angle on your location and fix heading
  // You can find your declination on:
  // (+) Positive or (-) for negative
  // For Bytom / Poland declination angle is 4'26E (positive)
  // Formula: (deg + (min / 60.0)) / (180 / M_PI);
  float declinationAngle = (4.0 + (26.0 / 60.0)) / (180 / M_PI);
  heading += declinationAngle;

  // Correct for heading < 0deg and heading > 360deg
  if (heading < 0)
    heading += 2 * PI;

  if (heading > 2 * PI)
    heading -= 2 * PI;

  // Convert to degrees
  float headingDegrees = heading * 180/M_PI; 

  // Output
  Serial.print(" Heading = ");
  Serial.print(" Degress = ");


and this is the library code

HMC5883L.h - Header file for the HMC5883L Triple Axis Digital Compass Arduino Library.
Version: 1.1.0
(c) 2014 Korneliusz Jarzebski
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
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 <>.

#ifndef HMC5883L_h
#define HMC5883L_h

#if ARDUINO >= 100
#include "Arduino.h"
#include "WProgram.h"

#define HMC5883L_ADDRESS              (0x1E)
#define HMC5883L_REG_CONFIG_A         (0x00)
#define HMC5883L_REG_CONFIG_B         (0x01)
#define HMC5883L_REG_MODE             (0x02)
#define HMC5883L_REG_OUT_X_M          (0x03)
#define HMC5883L_REG_OUT_X_L          (0x04)
#define HMC5883L_REG_OUT_Z_M          (0x05)
#define HMC5883L_REG_OUT_Z_L          (0x06)
#define HMC5883L_REG_OUT_Y_M          (0x07)
#define HMC5883L_REG_OUT_Y_L          (0x08)
#define HMC5883L_REG_STATUS           (0x09)
#define HMC5883L_REG_IDENT_A          (0x0A)
#define HMC5883L_REG_IDENT_B          (0x0B)
#define HMC5883L_REG_IDENT_C          (0x0C)

typedef enum
    HMC5883L_SAMPLES_8     = 0b11,
    HMC5883L_SAMPLES_4     = 0b10,
    HMC5883L_SAMPLES_2     = 0b01,
    HMC5883L_SAMPLES_1     = 0b00
} hmc5883l_samples_t;

typedef enum
    HMC5883L_DATARATE_75HZ       = 0b110,
    HMC5883L_DATARATE_30HZ       = 0b101,
    HMC5883L_DATARATE_15HZ       = 0b100,
    HMC5883L_DATARATE_7_5HZ      = 0b011,
    HMC5883L_DATARATE_3HZ        = 0b010,
    HMC5883L_DATARATE_1_5HZ      = 0b001,
    HMC5883L_DATARATE_0_75_HZ    = 0b000
} hmc5883l_dataRate_t;

typedef enum
    HMC5883L_RANGE_8_1GA     = 0b111,
    HMC5883L_RANGE_5_6GA     = 0b110,
    HMC5883L_RANGE_4_7GA     = 0b101,
    HMC5883L_RANGE_4GA       = 0b100,
    HMC5883L_RANGE_2_5GA     = 0b011,
    HMC5883L_RANGE_1_9GA     = 0b010,
    HMC5883L_RANGE_1_3GA     = 0b001,
    HMC5883L_RANGE_0_88GA    = 0b000
} hmc5883l_range_t;

typedef enum
    HMC5883L_IDLE          = 0b10,
    HMC5883L_SINGLE        = 0b01,
    HMC5883L_CONTINOUS     = 0b00
} hmc5883l_mode_t;

struct Vector
    float XAxis;
    float YAxis;
    float ZAxis;

class HMC5883L

 bool begin(void);

 Vector readRaw(void);
 Vector readNormalize(void);

 void  setOffset(int xo, int yo);

 void  setRange(hmc5883l_range_t range);
 hmc5883l_range_t getRange(void);

 void  setMeasurementMode(hmc5883l_mode_t mode);
 hmc5883l_mode_t getMeasurementMode(void);

 void  setDataRate(hmc5883l_dataRate_t dataRate);
 hmc5883l_dataRate_t getDataRate(void);

 void  setSamples(hmc5883l_samples_t samples);
 hmc5883l_samples_t getSamples(void);


 float mgPerDigit;
 Vector v;
 int xOffset, yOffset;

 void writeRegister8(uint8_t reg, uint8_t value);
 uint8_t readRegister8(uint8_t reg);
 uint8_t fastRegister8(uint8_t reg);
 int16_t readRegister16(uint8_t reg);


library source : GitHub - jarzebski/Arduino-HMC5883L: HMC5883L Triple Axis Digital Compass Arduino Library

Compass_Calibrate.ino (2.04 KB)

HMC5883L.h (3.21 KB)

When you encounter an error you'll see a button on the right side of the orange bar in the Arduino IDE "Copy error messages" (or the icon that looks like two pieces of paper in the Arduino Web Editor). Click that button. Paste the error in a reply here using code tags.

If the text exceeds the forum's 9000 character limit, save it to a .txt file and post it as an attachment. If you click the "Reply" button here, you will see an "Attachments and other settings" link.

I suspect the IDE is finding the wrong library for the sketch.

Your sketch appears to be "File -> Examples -> HMC58831L -> HMC58831L_compass" from GitHub - jarzebski/Arduino-HMC5883L: HMC5883L Triple Axis Digital Compass Arduino Library. That example compiles without error for me. There are three places in HMC58831L.cpp where someone wrote "#endif;" instead of "#endif" but those are just warnings.

When you installed the library did you rename the library directory from "Arduino-HMC58831L-master" to "HMC58831L"? Perhaps that helps.

Did you move the various example directories into a directory called "examples"? The IDE likes things that way.

class HMC5883L definitely has a member named 'begin':

class HMC5883L

bool begin(void);

So, considering johnwasser's answer, the problem must come from the way you installed the library. Can you show the hierarchy of you arduino folder, from 'arduino' to 'Arduino-HMC5883L'?