Pages: [1]   Go Down
Author Topic: [HMC5883L Magnetometer] - Wrong Scaled values  (Read 1732 times)
0 Members and 1 Guest are viewing this topic.
Italy
Offline Offline
Newbie
*
Karma: 0
Posts: 8
http://www.zooh.it
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I tried to use the library on http://bildr.org/2012/02/hmc5883l_arduino/ for HMC5883L magnetometer and it works fine. I only have a bit question concerning scaled values: If I set the scale range to +/- 0.88 Gauss and I put my cellphone on the sensor, the maximum value for scaled values aren't -800 (mGauss) but something near -3000 (mGauss). It's seems that, despite I set the Scale Range to +/- 0.88 Gauss, it uses another scale range.
Do you have some suggestions?

Regards,

Alessandro

Here is the output:
Code:
Starting the I2C interface.
Constructing new HMC5883L
Setting scale to +/- 0.88 Ga
Setting measurement mode to continous.
Raw: -4096   -1795   -4096   Scaled: -2990.08   -1310.35   -2990.08   Heading: 3.60 Radians   206.28 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Raw: -4096   -4096   -4096   Scaled: -2990.08   -2990.08   -2990.08   Heading: 3.97 Radians   227.62 Degrees  
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13707
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Do you have some suggestions?
Post your code how you use the library, it sounds like some overflow / int rounding error  (or a bad connector)

do the sample sketches of the lib work?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3018
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are getting raw values of 4096 all the time,  it looks suspiciously like you have a 12 bit A/D converter there which is stuck on limit.  Or maybe 13 bits.   Stuck on limit, anyway.

This could mean that the device is not working properly.   It could also mean that your I2C communication isn't actually working  but the microcontroller end of the I2C doesn't realise it is doing nothing and actually thinks it is reading something.

I recently got several of these devices and had quite a bit of bother getting them to work,  although they all eventually did.

I downloaded several bits of library code to read the device,  some of them had problems,  eventually I wrote a new one which works for me on all of my devices.


Logged

Italy
Offline Offline
Newbie
*
Karma: 0
Posts: 8
http://www.zooh.it
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I've only tried to run the example (just changed the default scale):

Code:
  Serial.println("Setting scale to +/- 0.88 Ga");
  error = compass.SetScale(0.88); // Set the scale of the compass.
  if(error != 0) // If there is an error, print it out.
    Serial.println(compass.GetErrorText(error));

@michinyon:
I don't get 4096 all the time but only when I put the cellphone on the magnetometer (and this is right)
The problem is the scaled values: If I set the scale to 0.88, when I put the cellphone on the mag, should the scaled values be comprised between -800 and 800 or not?

Thanks

Alessandro



Code:
Starting the I2C interface.
Constructing new HMC5883L
Setting scale to +/- 0.88 Ga
Setting measurement mode to continous.
Raw: -458   -393   -31    Scaled: -334.34   -286.89   -22.63    Heading: 3.90 Radians    223.25 Degrees   
Raw: -457   -390   -28    Scaled: -333.61   -284.70   -20.44    Heading: 3.89 Radians    223.10 Degrees   
Raw: -455   -398   -27    Scaled: -332.15   -290.54   -19.71    Heading: 3.91 Radians    223.80 Degrees   
Raw: -457   -396   -28    Scaled: -333.61   -289.08   -20.44    Heading: 3.90 Radians    223.53 Degrees   
Raw: -456   -393   -29    Scaled: -332.88   -286.89   -21.17    Heading: 3.90 Radians    223.37 Degrees   
Raw: -455   -390   -31    Scaled: -332.15   -284.70   -22.63    Heading: 3.90 Radians    223.22 Degrees   
Raw: -461   -396   -31    Scaled: -336.53   -289.08   -22.63    Heading: 3.90 Radians    223.28 Degrees   
Raw: -455   -395   -28    Scaled: -332.15   -286.16   -21.17    Heading: 3.90 Radians    223.36 Degrees   
Raw: -459   -391   -30    Scaled: -335.07   -285.43   -21.90    Heading: 3.89 Radians    223.04 Degrees   
Raw: -458   -393   -31    Scaled: -334.34   -286.89   -22.63    Heading: 3.90 Radians    223.25 Degrees   
Raw: -454   -393   -28    Scaled: -331.42   -286.89   -20.44    Heading: 3.90 Radians    223.50 Degrees   
Raw: -456   -391   -28    Scaled: -332.88   -285.43   -20.44    Heading: 3.90 Radians    223.23 Degrees   
Raw: -459   -392   -31    Scaled: -335.07   -286.16   -22.63    Heading: 3.89 Radians    223.12 Degrees   
Raw: -458   -393   -32    Scaled: -334.34   -286.89   -23.36    Heading: 3.90 Radians    223.25 Degrees   
Raw: -459   -395   -29    Scaled: -335.07   -288.35   -21.17    Heading: 3.90 Radians    223.33 Degrees   
Raw: -452   -393   -29    Scaled: -329.96   -286.89   -21.17    Heading: 3.90 Radians    223.62 Degrees   
Raw: -461   -393   -26    Scaled: -336.53   -286.89   -18.98    Heading: 3.89 Radians    223.07 Degrees   
Raw: -457   -393   -31    Scaled: -333.61   -286.89   -22.63    Heading: 3.90 Radians    223.31 Degrees   
Raw: -457   -392   -31    Scaled: -333.61   -286.16   -22.63    Heading: 3.90 Radians    223.24 Degrees   
Raw: -458   -392   -29    Scaled: -334.34   -286.16   -21.17    Heading: 3.90 Radians    223.18 Degrees   
Raw: -456   -396   -29    Scaled: -332.88   -289.08   -21.17    Heading: 3.90 Radians    223.59 Degrees   
Raw: -457   -396   -31    Scaled: -333.61   -289.08   -22.63    Heading: 3.90 Radians    223.53 Degrees   
Raw: -459   -397   -30    Scaled: -335.07   -289.81   -21.90    Heading: 3.90 Radians    223.48 Degrees   
Raw: -458   -394   -29    Scaled: -334.34   -287.62   -21.17    Heading: 3.90 Radians    223.32 Degrees   
Raw: -458   -396   -31    Scaled: -334.34   -289.08   -22.63    Heading: 3.90 Radians    223.47 Degrees   
Raw: -452   -394   -30    Scaled: -329.96   -287.62   -21.90    Heading: 3.90 Radians    223.70 Degrees   
Raw: -450   -392   -32    Scaled: -328.50   -286.16   -23.36    Heading: 3.90 Radians    223.68 Degrees   
Raw: -441   -389   -33    Scaled: -321.93   -283.97   -24.09    Heading: 3.91 Radians    224.03 Degrees   
Raw: -419   -369   -17    Scaled: -305.87   -269.37   -12.41    Heading: 3.91 Radians    223.99 Degrees   
Raw: -367   -269   107    Scaled: -267.91   -196.37   78.11    Heading: 3.82 Radians    218.86 Degrees   
Raw: -360   -180   248    Scaled: -262.80   -131.40   181.04    Heading: 3.65 Radians    209.18 Degrees   
Raw: -166   193   667    Scaled: -121.18   140.89   486.91    Heading: 2.33 Radians    133.32 Degrees   
Raw: 220   1429   -4096    Scaled: 160.60   1043.17   -2990.08    Heading: 1.46 Radians    83.87 Degrees   
Raw: -332   1127   -4096    Scaled: -242.36   822.71   -2990.08    Heading: 1.90 Radians    109.03 Degrees   
Raw: -1860   85   -4096    Scaled: -1357.80   62.05   -2990.08    Heading: 3.14 Radians    180.00 Degrees


putting the cellphone on the mag:


Code:
 
Raw: -4096   -236   -4096    Scaled: -2990.08   -172.28   -2990.08    Heading: 3.24 Radians    185.92 Degrees
Raw: -4096   -957   -4096    Scaled: -2990.08   -698.61   -2990.08    Heading: 3.42 Radians    195.77 Degrees   
Raw: -4096   -628   -4096    Scaled: -2990.08   -458.44   -2990.08    Heading: 3.34 Radians    191.34 Degrees   
Raw: -4096   -610   -4096    Scaled: -2990.08   -445.30   -2990.08    Heading: 3.34 Radians    191.09 Degrees   
Raw: -4096   -584   -4096    Scaled: -2990.08   -426.32   -2990.08    Heading: 3.33 Radians    190.73 Degrees   
Raw: -4096   -528   -4096    Scaled: -2990.08   -385.44   -2990.08    Heading: 3.32 Radians    189.96 Degrees   
Raw: -4096   -509   -4096    Scaled: -2990.08   -371.57   -2990.08    Heading: 3.31 Radians    189.70 Degrees   
Raw: -4096   -480   -4096    Scaled: -2990.08   -350.40   -2990.08    Heading: 3.30 Radians    189.30 Degrees   
Raw: -4096   -467   -4096    Scaled: -2990.08   -340.91   -2990.08    Heading: 3.30 Radians    189.12 Degrees   
Raw: -4096   -445   -4096    Scaled: -2990.08   -324.85   -2990.08    Heading: 3.30 Radians    188.82 Degrees   
Raw: -4096   -430   -4096    Scaled: -2990.08   -313.90   -2990.08    Heading: 3.29 Radians    188.61 Degrees   
Raw: -4096   -405   -4096    Scaled: -2990.08   -295.65   -2990.08    Heading: 3.29 Radians    188.27 Degrees   
Raw: -4096   -402   -4096    Scaled: -2990.08   -293.46   -2990.08    Heading: 3.29 Radians    188.22 Degrees   
Raw: -4096   -402   -4096    Scaled: -2990.08   -293.46   -2990.08    Heading: 3.29 Radians    188.22 Degrees   
Raw: -4096   -400   -4096    Scaled: -2990.08   -292.00   -2990.08    Heading: 3.28 Radians    188.20 Degrees   
Raw: -4096   -401   -4096    Scaled: -2990.08   -292.73   -2990.08    Heading: 3.28 Radians    188.21 Degrees   
Raw: -4096   -388   -4096    Scaled: -2990.08   -283.24   -2990.08    Heading: 3.28 Radians    188.03 Degrees   
Raw: -4096   -390   -4096    Scaled: -2990.08   -284.70   -2990.08    Heading: 3.28 Radians    188.06 Degrees   
Raw: -4096   -395   -4096    Scaled: -2990.08   -288.35   -2990.08    Heading: 3.28 Radians    188.13 Degrees   
Raw: -4096   -387   -4096    Scaled: -2990.08   -282.51   -2990.08    Heading: 3.28 Radians    188.02 Degrees   
Raw: -4096   -389   -4096    Scaled: -2990.08   -283.97   -2990.08    Heading: 3.28 Radians    188.04 Degrees   
Raw: -4096   -389   -4096    Scaled: -2990.08   -283.97   -2990.08    Heading: 3.28 Radians    188.04 Degrees   
Raw: -4096   -379   -4096    Scaled: -2990.08   -276.67   -2990.08    Heading: 3.28 Radians    187.90 Degrees   
Raw: -4096   -366   -4096    Scaled: -2990.08   -267.18   -2990.08    Heading: 3.28 Radians    187.72 Degrees   
Logged

Pages: [1]   Go Up
Jump to: