hey, I had purchased a Gy-271 HMC5883_L magnetometer sensor for my project
I downloaded the library and extracted it to libraries folder inside my Arduino folder
downloaded from here:https://github.com/jarzebski/Arduino-HMC5883L
But whenever I run the code, I get tons of errors saying like
“‘class HMC5883L’ has no member named ‘begin’”
“‘class HMC5883L’ has no member named ‘setRange’”
Arduino: 1.8.4 (Windows 8.1), Board: “Arduino/Genuino Uno”
C:\Program Files (x86)\Arduino\libraries\Arduino-HMC5883L-master\HMC5883L_simple\HMC5883L_simple.ino: In function ‘void setup()’:
HMC5883L_simple:20: error: ‘class HMC5883L’ has no member named ‘begin’
while (!compass.begin())
^
HMC5883L_simple:35: error: ‘class HMC5883L’ has no member named ‘setRange’
compass.setRange(HMC5883L_RANGE_1_3GA);
^
HMC5883L_simple:35: error: ‘HMC5883L_RANGE_1_3GA’ was not declared in this scope
compass.setRange(HMC5883L_RANGE_1_3GA);
^
HMC5883L_simple:41: error: ‘class HMC5883L’ has no member named ‘setMeasurementMode’
compass.setMeasurementMode(HMC5883L_CONTINOUS);
^
HMC5883L_simple:41: error: ‘HMC5883L_CONTINOUS’ was not declared in this scope
compass.setMeasurementMode(HMC5883L_CONTINOUS);
^
HMC5883L_simple:51: error: ‘HMC5883L_DATARATE_15HZ’ was not declared in this scope
compass.setDataRate(HMC5883L_DATARATE_15HZ);
^
HMC5883L_simple:58: error: ‘class HMC5883L’ has no member named ‘setSamples’
compass.setSamples(HMC5883L_SAMPLES_1);
^
HMC5883L_simple:58: error: ‘HMC5883L_SAMPLES_1’ was not declared in this scope
compass.setSamples(HMC5883L_SAMPLES_1);
^
C:\Program Files (x86)\Arduino\libraries\Arduino-HMC5883L-master\HMC5883L_simple\HMC5883L_simple.ino: In function ‘void checkSettings()’:
HMC5883L_simple:68: error: ‘class HMC5883L’ has no member named ‘getRange’
switch (compass.getRange())
^
^
HMC5883L_simple:106: error: ‘HMC5883L_SAMPLES_1’ was not declared in this scope
case HMC5883L_SAMPLES_1: Serial.println(“1”); break;
^
HMC5883L_simple:107: error: ‘HMC5883L_SAMPLES_2’ was not declared in this scope
case HMC5883L_SAMPLES_2: Serial.println(“2”); break;
^
HMC5883L_simple:108: error: ‘HMC5883L_SAMPLES_4’ was not declared in this scope
case HMC5883L_SAMPLES_4: Serial.println(“4”); break;
^
HMC5883L_simple:109: error: ‘HMC5883L_SAMPLES_8’ was not declared in this scope
case HMC5883L_SAMPLES_8: Serial.println(“8”); break;
^
C:\Program Files (x86)\Arduino\libraries\Arduino-HMC5883L-master\HMC5883L_simple\HMC5883L_simple.ino: In function ‘void loop()’:
HMC5883L_simple:117: error: ‘Vector’ was not declared in this scope
Multiple libraries were found for “HMC5883L.h”
Vector raw = compass.readRaw();
Used: C:\Program Files (x86)\Arduino\libraries\HMC5883L
^
Not used: C:\Program Files (x86)\Arduino\libraries\Arduino-HMC5883L-master
HMC5883L_simple:118: error: expected ‘;’ before ‘norm’
Vector norm = compass.readNormalize();
^
HMC5883L_simple:121: error: ‘raw’ was not declared in this scope
Serial.print(raw.XAxis);
^
HMC5883L_simple:127: error: ‘norm’ was not declared in this scope
Serial.print(norm.XAxis);
^
exit status 1
‘class HMC5883L’ has no member named ‘begin’
etc etc
This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.
Here is the code
#include <Wire.h>
#include <HMC5883L.h>
HMC5883L compass;
void setup()
{
Serial.begin(9600);
// Initialize HMC5883L
Serial.println("Initialize HMC5883L");
while (!compass.begin())
{
Serial.println("Could not find a valid HMC5883L sensor, check wiring!");
delay(500);
}
// Set measurement range
// +/- 0.88 Ga: HMC5883L_RANGE_0_88GA
// +/- 1.30 Ga: HMC5883L_RANGE_1_3GA (default)
// +/- 1.90 Ga: HMC5883L_RANGE_1_9GA
// +/- 2.50 Ga: HMC5883L_RANGE_2_5GA
// +/- 4.00 Ga: HMC5883L_RANGE_4GA
// +/- 4.70 Ga: HMC5883L_RANGE_4_7GA
// +/- 5.60 Ga: HMC5883L_RANGE_5_6GA
// +/- 8.10 Ga: HMC5883L_RANGE_8_1GA
compass.setRange(HMC5883L_RANGE_1_3GA);
// Set measurement mode
// Idle mode: HMC5883L_IDLE
// Single-Measurement: HMC5883L_SINGLE
// Continuous-Measurement: HMC5883L_CONTINOUS (default)
compass.setMeasurementMode(HMC5883L_CONTINOUS);
// Set data rate
// 0.75Hz: HMC5883L_DATARATE_0_75HZ
// 1.50Hz: HMC5883L_DATARATE_1_5HZ
// 3.00Hz: HMC5883L_DATARATE_3HZ
// 7.50Hz: HMC5883L_DATARATE_7_50HZ
// 15.00Hz: HMC5883L_DATARATE_15HZ (default)
// 30.00Hz: HMC5883L_DATARATE_30HZ
// 75.00Hz: HMC5883L_DATARATE_75HZ
compass.setDataRate(HMC5883L_DATARATE_15HZ);
// Set number of samples averaged
// 1 sample: HMC5883L_SAMPLES_1 (default)
// 2 samples: HMC5883L_SAMPLES_2
// 4 samples: HMC5883L_SAMPLES_4
// 8 samples: HMC5883L_SAMPLES_8
compass.setSamples(HMC5883L_SAMPLES_1);
// Check settings
checkSettings();
}
void checkSettings()
{
Serial.print("Selected range: ");
switch (compass.getRange())
{
case HMC5883L_RANGE_0_88GA: Serial.println("0.88 Ga"); break;
case HMC5883L_RANGE_1_3GA: Serial.println("1.3 Ga"); break;
case HMC5883L_RANGE_1_9GA: Serial.println("1.9 Ga"); break;
case HMC5883L_RANGE_2_5GA: Serial.println("2.5 Ga"); break;
case HMC5883L_RANGE_4GA: Serial.println("4 Ga"); break;
case HMC5883L_RANGE_4_7GA: Serial.println("4.7 Ga"); break;
case HMC5883L_RANGE_5_6GA: Serial.println("5.6 Ga"); break;
case HMC5883L_RANGE_8_1GA: Serial.println("8.1 Ga"); break;
default: Serial.println("Bad range!");
}
Serial.print("Selected Measurement Mode: ");
switch (compass.getMeasurementMode())
{
case HMC5883L_IDLE: Serial.println("Idle mode"); break;
case HMC5883L_SINGLE: Serial.println("Single-Measurement"); break;
case HMC5883L_CONTINOUS: Serial.println("Continuous-Measurement"); break;
default: Serial.println("Bad mode!");
}
Serial.print("Selected Data Rate: ");
switch (compass.getDataRate())
{
case HMC5883L_DATARATE_0_75_HZ: Serial.println("0.75 Hz"); break;
case HMC5883L_DATARATE_1_5HZ: Serial.println("1.5 Hz"); break;
case HMC5883L_DATARATE_3HZ: Serial.println("3 Hz"); break;
case HMC5883L_DATARATE_7_5HZ: Serial.println("7.5 Hz"); break;
case HMC5883L_DATARATE_15HZ: Serial.println("15 Hz"); break;
case HMC5883L_DATARATE_30HZ: Serial.println("30 Hz"); break;
case HMC5883L_DATARATE_75HZ: Serial.println("75 Hz"); break;
default: Serial.println("Bad data rate!");
}
Serial.print("Selected number of samples: ");
switch (compass.getSamples())
{
case HMC5883L_SAMPLES_1: Serial.println("1"); break;
case HMC5883L_SAMPLES_2: Serial.println("2"); break;
case HMC5883L_SAMPLES_4: Serial.println("4"); break;
case HMC5883L_SAMPLES_8: Serial.println("8"); break;
default: Serial.println("Bad number of samples!");
}
}
void loop()
{
Vector raw = compass.readRaw();
Vector norm = compass.readNormalize();
Serial.print(" Xraw = ");
Serial.print(raw.XAxis);
Serial.print(" Yraw = ");
Serial.print(raw.YAxis);
Serial.print(" Zraw = ");
Serial.print(raw.ZAxis);
Serial.print(" Xnorm = ");
Serial.print(norm.XAxis);
Serial.print(" Ynorm = ");
Serial.print(norm.YAxis);
Serial.print(" ZNorm = ");
Serial.print(norm.ZAxis);
Serial.println();
delay(100);