Hey everyone I have some questions first does anyone know why my total magnetic field changes? In my city is 0.47 gauss , but it keeps changing doesn't stay constant, any idea why this happens?
Second I wanna measure field changes that are caused from electric wires, but sensor doesn't detect those changes even though I'm measuring at 2G,does anyone know why is that?
For calibration I used Mag Master , but I tried using magneto v1.2 too but same results, I couldn't get constant output and can't detect EMF!
I'm using chinese version of hmc5883l (qmc5883l) and this is my code :
#include <QMC5883LCompass.h>
QMC5883LCompass compass;
int x, y, z;
float calibrated_values[3];
float M;
void transformation(float uncalibrated_values[3])
{
double calibration_matrix[3][3] =
{
{1.207, 0.017, 0.081},
{-0.025, 1.195, -0.101},
{-0.053, 0.109, 1.223}
};
double bias[3] =
{
17.838,
879.807,
-600.048
};
for (int i=0; i<3; ++i) uncalibrated_values[i] = uncalibrated_values[i] - bias[i];
float result[3] = {0, 0, 0};
for (int i=0; i<3; ++i)
for (int j=0; j<3; ++j)
result[i] += calibration_matrix[i][j] * uncalibrated_values[j];
for (int i=0; i<3; ++i) calibrated_values[i] = result[i];
}
void setup() {
Serial.begin(9600);
Wire.begin();
setQMCup();
}
void loop() {
float values_from_magnetometer[3];
// Read compass values
getdata();
values_from_magnetometer[0] = x;
values_from_magnetometer[1] = y;
values_from_magnetometer[2] = z;
transformation(values_from_magnetometer);
calibrated_values[0]/=12000;
calibrated_values[1]/=12000;
calibrated_values[2]/=12000;
M=sqrt(calibrated_values[0]*calibrated_values[0]+calibrated_values[1]*calibrated_values[1]+calibrated_values[2]*calibrated_values[2]);
Serial.flush();
Serial.print(calibrated_values[0]);
Serial.print(",");
Serial.print(calibrated_values[1]);
Serial.print(",");
Serial.print(calibrated_values[2]);
Serial.print(",");
Serial.print(M);
Serial.println();
delay(250);
}
void setQMCup()
{
compass.setADDR(0x0D);
compass.init();
compass.setMode(0x01,0x04,0x00,0xC0); // (Mode_continues,50ODR,2G,64OSR)
}
void getdata(){
compass.read();
// Return XYZ readings
x = compass.getX();
y = compass.getY();
z = compass.getZ();
}
The output I get :
-0.54,0.16,-0.19,0.60
-0.55,0.16,-0.19,0.60
-0.54,0.18,-0.18,0.60
-0.55,0.17,-0.18,0.61
-0.53,0.18,-0.18,0.59
-0.54,0.18,-0.18,0.60
-0.54,0.17,-0.18,0.59
-0.55,0.17,-0.19,0.61
-0.54,0.18,-0.20,0.60
-0.53,0.15,-0.21,0.59
-0.56,0.17,-0.20,0.62
-0.53,0.16,-0.20,0.59
-0.56,0.15,-0.20,0.61
-0.55,0.17,-0.20,0.60
-0.55,0.18,-0.20,0.62
-0.54,0.17,-0.19,0.60
-0.55,0.16,-0.21,0.61
-0.56,0.16,-0.19,0.61
-0.55,0.17,-0.19,0.60
-0.55,0.17,-0.19,0.61
-0.54,0.17,-0.20,0.60
-0.56,0.17,-0.21,0.63
-0.56,0.16,-0.20,0.61
-0.39,0.50,-0.23,0.68
-0.38,0.50,-0.23,0.67
-0.38,0.50,-0.25,0.68
-0.39,0.51,-0.23,0.68
-0.39,0.48,-0.24,0.66
-0.39,0.50,-0.24,0.68
-0.38,0.51,-0.24,0.68
-0.39,0.51,-0.24,0.69
-0.38,0.49,-0.24,0.67
-0.38,0.49,-0.23,0.66
-0.39,0.50,-0.23,0.68
-0.39,0.50,-0.24,0.68
-0.38,0.51,-0.22,0.67
-0.39,0.50,-0.23,0.68
-0.40,0.49,-0.23,0.67
-0.40,0.50,-0.24,0.68
-0.39,0.49,-0.24,0.67
-0.39,0.50,-0.24,0.68
-0.39,0.51,-0.24,0.68