SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By s_frit
#131466
Hi, I just got my new SEN-10736 Razor IMU (http://www.sparkfun.com/products/10736) connected and I don't see any output from one of the magnetometer axis. It's the HMC5883L. Note that this is not the same problem that IL Denizen recently reported in another thread.

Using the SF9DOF_AHRS sample code (from here http://www.sparkfun.com/products/10736) with the PRINT_ANALOGS switch enabled I get output like this:

!ANG:-13.44,30.44,46.57,AN:-801,286,-37,-142,-20,232,4096,235,589
!ANG:-12.08,29.32,46.55,AN:770,-168,-2,-185,2,359,4096,249,601
!ANG:-11.03,25.98,46.51,AN:2113,-146,-302,-146,-72,338,4096,248,581
!ANG:-11.05,24.20,46.08,AN:1039,-218,216,-137,-58,188,4096,245,565

The last 3 columns should be the magnetometer. The 3rd from last column is always 4096. It never changes.


Using the FreeIMU FreeIMU_raw code (from here http://www.varesano.net/projects/hardware/FreeIMU) I get a similar problem:

-142,-2,252,-659,-2400,-308,-202,-280,0,
-142,-2,252,-707,-2486,-243,-202,-280,0,
-142,-2,252,-668,-2413,-201,-176,-291,0,
-131,-3,307,-514,-2185,-196,-176,-291,0,
-131,-3,307,-286,-2026,-171,-150,-300,0,

Last 3 columns are the magnetometer. The last column is always 0.

All the rest of the sensor axis seem to work fine.

Does that mean my sensor has a dead axis? or is it possible to reset it/recalibrate it somehow?

Is there some other trusted test code I could try?

Or should I just request a replacement?

Thanks.
#131500
Sorry to reply to my own post, but the new members moderation policy gave me some time to research this further. I've resolved the issue. Posting here in case it helps someone else in the future:

The HMC5883L magnetometer was returning -4096 in the z axis. This is documented in the datasheet as the "internal overflow" value.

In my case, reducing the gain (to GN=4) resolved the issue. I have attached an Arduino sketch file that dumps the magnetometer register values and sets the gain (and reset the other configuration registers if you uncomment the right lines). You can use this to debug similar issues. Thanks to Wayne Truchsess and Fabio Varesano, it's based on their code I found on the net.

There were a few things that were confusing me:

- A number of example codes out there don't fully reset the magnetometer on startup. They assume it's in the default state after a cold boot. But if you've got the power/programming cable connected the magnetometer remembers its configuration (eg Gain) when you switch sketches. So, make sure you reset the magnetometer to a known state before reading it.

- FreeIMU code currently hard-codes the gain to 1 (the power-on default). There is a comment in FreeIMU.cpp suggesting you can change it in the call to magn.calibrate(). I changed it to 4 and it works for me.

Ok, hope that helps someone. Sorry for the noise.
You do not have the required permissions to view the files attached to this post.