I have just bought the 3D magnetometer. It seems to operate, it communicates correctly etc. However, I have already used three different libraries to use it as a compass and all fail. Basically, the heading does not move through the whole range when the sensor is used. For example, 350 is given for a heading both when the sensor is facing a particular spot and also after it has been rotated by 180 degrees.
I keep the sensor flat and far from any possible interference.
Am I doing something wrong or is the sensor faulty in some way?
Magnetometers must be individually calibrated, generally every time their immediate environment changes much.
Basically you need to calculate a scale and offset for each axis. The best and most complicate procedure is this one, but there are several other, simpler approaches. Google "magnetometer calibration" for more info.
I have run the procedure with Magneto 1.2 and checking the result with the library available here, but still the result I get are nonsensical. I am losing hope I will figure it out...
GY-271 has a HMC5883 module. So, for the readings you can refer this HMC5883 Arduino code. Use a magnet and measure the values for magnetic fields in the x, y, z axis.Just check if this solves your issue.
Yes, place the magnet above the sensor at a very small distance and move it with respect to three axis, parallel or inclined to the axis and then check the readings in the respective ones accordingly.
Also you can do vice versa i.e. placing and moving the sensor above the magnet.
My results are not ideal (the opposite headings are off about 7 deg)
If you follow the instructions in step 1 of this link, and post a set of data points (a few hundred X,Y,Z magnetometer readings) in as many orientations as possible, I'll help you calibrate the compass properly.
Hi duino_nano,
I used HMC5883L Compass Library,
The problem is not to change the results when I move the GY-271.
And also used several other codes but in vain.
I hope to help me.
I haves the same problem with GY-271.
I try many libraries but it does not work.
So my conclusion is to avoid to buy such component
I will try another compass become I want to made a numeric compass fort ULM
Soon