Hello everyone, I am a total beginner when it comes to electronics and arduino but I do not lack the will and enthusiasm to learn something;)
I have an LSM303D module, I used the arduino library which you recommend.
I calibrated the sensor first according to your requirements.
I set the compass more or less to the north, fired up the serial monitor and I have these results. All right.
359.80
0.05
0.14
359.80
0.57
0.61
0.61
0.14
0.03
359.97
359.94
359.73
359.85
359.67
0.15
0.11
0.25
0.32
0.53
0.56
359.90
359.63
0.32
359.92
359.45
0.37
0.14
359.98
0.64
0.50
0.27
359.57
359.84
359.73
0.00
0.10
0.46
0.14
0.01
0.46
0.41
360.00
0.24
0.27
359.86
0.31
0.49
0.02
0.22
0.16
0.09
0.03
0.01
I turn the power off and on, I do not move the compass, I start the series and monitor and I have the following results:
92.65
92.65
93.15
93.15
92.72
92.84
92.84
92.87
92.86
92.86
92.99
93.12
93.12
92.68
92.68
92.64
93.03
93.03
93.18
93.25
93.25
I will turn on / off the power several times. Some time they are correct again and indicate north and ~ 0 degrees well. Do you know what could be wrong or what I’m doing wrong?
Here is my code
#include <Wire.h>
#include <LSM303.h>
LSM303 compass;
void setup() {
Serial.begin(9600);
Wire.begin();
compass.init();
compass.enableDefault();
/*
Calibration values; the default values of +/-32767 for each axis
lead to an assumed magnetometer bias of 0. Use the Calibrate example
program to determine appropriate values for your particular unit.
*/
compass.m_min = (LSM303::vector<int16_t>){-2813, -2107, -2738};
compass.m_max = (LSM303::vector<int16_t>){+2724, +2998, +3155};
}
void loop() {
compass.read();
float heading = compass.heading((LSM303::vector<int>){0, -1, 0});
Serial.println(heading);
delay(100);
}
Thank you in advance for your help