Sensor wired to a Mega2560. Compiles with no errors. All I see is two numbers that do not change even when i move the compass.
I am just looking to see some raw (un- calibrated) readings, just to get a feel for the sensor and its quirks.
I took the example code and just extracted what i wanted to see (even if not perfect).
Any help is much appreciated!
// Reference the I2C Library
#include <Wire.h>
// Reference the HMC5883L Compass Library
#include <HMC5883L.h>
//#include "Streaming.h"
// Store our compass as a variable.
HMC5883L compass;
// Record any errors that may occur in the compass.
int error = 0;
MagnetometerRaw raw;
// Out setup routine, here we will configure the microcontroller and compass.
void setup()
{
compass.initCompass() ;
compass.getCompass();
// Initialize the serial port.
Serial.begin(115200);
delay(2000);
Serial.println("Starting the I2C interface.");
Wire.begin(); // Start the I2C interface.
Serial.println("Constructing new HMC5883L");
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));
}
}
//************************************************** L O O P **********************************************************
// Our main program loop.
void loop()
{
// Retrive the raw values from the compass (not scaled).
MagnetometerRaw raw = compass.readRawAxis();
Serial.print(raw.YAxis);
Serial.print( F( " " ) ) ;
Serial.println(raw.YAxis);
delay(100) ;
}