HMC5883 Magnetometer - confusion with axis orientation

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all, I'm confused with the axis drawn in the board ( GY-273 )  and the relation with the output data for each one, for example, I thought that the axis drawn were vectors, so the output data for the axis that would point the north is at his maximum positive value, and if that axis points oposite to north would be at his maximum negative value, and the transition between the positive and negative would be from its maximum positive to cero to maximum negative ( e.g. +270 -> 100 -> 0 -> -100 -> -270), all transition between signs has to cross cero, but the behavior that I'm seeing is:

- If I point the X axis to the north I get the maximum positive value, If I rotate the sensor a little counterclockwise the output decreases as expected, but If I rotate the sensor clockwise the output jumps instantly from the maximun positive value to the maximum negative value, like pointing it oposite to north, but I'm just rotating it like 2 degrees counter wise from its maximum positive value, so that is not like a vector behavior, what i think is that the sign describes something related to a positive or negative declination that are related to the north, but I don't really know what the sign tells me or what the output is, I discarded that behavior due to something related with the place where I'm testing it, if that would be the cause, any compass would not work (the compass from my phone works well) so I don't think that is related with something like the room where I am , I'm not using any library.

Any ideas what the data describes?

Thank you in advance for your help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Guillenvar

 

Try first to read the datasheet: https://cdn-shop.adafruit.com/datasheets/HMC5883L_3-Axis_Digital_Compass_IC.pdf

 

Also, i think you may find existing libraries for the device.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi!, thank you for your response, I have read the datasheet before, just says that the arrow will indicate a positive value in the direction of the magnetic field, no more detail :(, and dont get me wrong but I am not fan of using libraries, people today are so used to use that, and their proyects turn into black bloxes, only depending on the platform where the library exists, instead I prefer to understand what I'm using and how to improve its performance...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When I first started programming AVR's I read a lot of other peoples projects,  libraries (code) to understand how to do things. 

Much faster then trying to do it from scratch on my own.  Now I have a whole directory full of these code (libraries) to choose from and

copy / paste from as needed, makes code generation easy and saves time once I know something works.

 

Jim

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I recently tried a HMC5883L compass with the Adafruit sensor library.  

 

The IC has three MEMS (microelectronic mechanical systems, I guess) elements.  Each of these is a small tube of conductive material with a voltage sensor on each end.  When the element is in parallel to the Earth's magnetic flux line, the magnetic force generates a voltage between the two sensors.  This is a tiny voltage in microvolts.  It is linear to the degree that the element is positioned in the magnetic flux line direction.  The microvoltage is amplified and converted by an internal ADC to a number.  This number is multiplied by the values in the configuration and calibration registers.  The result is placed into the I2C registers for download by the AVR.   The Adafruit library converts the I2C data into Micro Teslas (uT) for each of the three elements (X,Y,Z).   When the element is oriented in the direction of the flux line, the absolute value of the I2C reading is at its highest.  When the element is positioned to be 90 degrees perpendicular to the magnetic flux line, the reading is 0 uT.  This is because there is an equal distance between the North magnetic Pole and each of the voltage sensors on the ends of the element. No voltage is generated between the sensors by the magnetic energy.

 

The Adafruit library also gives the compass heading, giving 0.0 degrees if the board is held so that the IC front face (the side with the writing) is pointed UP, and the X arrow is pointed due north.   The INO file has an entry for the declination angle.  This is the difference in degrees between the true North Pole and the Magnetic North Pole.  This will change depending where you are geographically on Earth, and on a yearly basis because the Magnetic North Pole is constantly drifting in position.  Google for sites that allow you to enter your home's latitude and longitude and get the current declination.  You then need to convert the angle to radians.  (57.3 degrees per radian) .   Note that the heading value will be affected by the tilt of the HMC5883L.  It will allow be affected by metal objects near the 5883L module.

 

I'm not sure what I would be able to use a tilt-sensor for.  The compass is must faster taking headings.  I've mounted the little PCB on the end of a ruler and then just point it at a distant tree or building to get a quick heading from my viewpoint.  Then I use a (paper) protractor and topographic maps in TIF or PDF format to learn where that landmark is located and where I am in relation to it.