Odd problem with GY-271

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 see, from the description it seemed more like an "out of the box" type of thing.

Thank you for the advice, now I will know where to look!

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... :frowning:

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.

I will try this out... If I understand you correctly, I should pass the magnet near the module and check the readings?

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.

I have finally found out the procedure even I could follow:

My results are not ideal (the opposite headings are off about 7 deg), but at least it makes sense. I will see how it will work in my rover...

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.

That is very kind of you! I am sending you a PM with the data.

I attach the raw data results...

calibration.txt (574 KB)

Thanks for posting the data. Could you repost with at most 300 distinct, well distributed (in angular coordinates) data points?

I am traveling and can't deal with this until Monday, 5/23.

Hello Jabber,
Can you send the code because I'm having the same problem and the answers don't change?
Can you help me? please.

Hi,

The GY-271 work with the HMC5883 chip.

I did work with the 1746-ADA Triple-axis Magnetometer and after many hours I finally fix it.

Can you show the program you work with? Maybe I can help...

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.

Arduino.zip (35.5 KB)

Hi,

If you are using something like this:

void Mag_Sensor()
{sensors_event_t event; 
  mag.getEvent(&event);
  x=event.magnetic.x;
  y=event.magnetic.y;
  z=event.magnetic.z;

     
   //float heading = atan2(y, x);

etc.
etc

then I think you have to include a correction factor for the y or x value.

For my sensor I have to use the following equation:

float heading = atan2(y+10, x);.

Hello every body,

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

I try many libraries but it does not work.

I wonder if you forgot to calibrate the compass.