Skip to main content
Visitor II
March 20, 2018
Solved

LSM303AGR: Magnetometer Interpreting values

  • March 20, 2018
  • 1 reply
  • 1609 views
Posted on March 20, 2018 at 18:33

Hi!

Fairly new to programming and embedded software in general but I'm having a problem with interpreting the values I am receiving from the magnetometer registers.

I'm able to get a value between 0 and 255 for each register (both high and low for X,Y and Z). I can't seem to workout what to do with these values; any help would/point in the right direction would be greatly appreciated!

Thanks,

Fraser

EDIT:

For anyone searching this in look for help, I have a github on this project: 

https://github.com/FrazLaw/RoboPot

 . 

The code isn't perfect but it may help someone else, like myself, looking for some assistance as it can be a fairly difficult task if you've never done something like this before.

Fraser

#e-compasses #e-compass #lsm303agr
    This topic has been closed for replies.
    Best answer by
    Posted on March 21, 2018 at 08:23

    Hello,

    There are lots of similar questions here, have a look at this one, for example:

    https://community.st.com/0D50X00009XkXHfSAN

    (search for a keyword 'interpretation', by the way the interpretation principle is the same for accelerometer and gyroscope)

    You are saying you can read a value of 0..255, but that is wrong. The registers are two, High and Low, see datasheet page 66 and 67:

    http://www.st.com/content/ccc/resource/technical/document/datasheet/74/c4/19/54/62/c5/46/13/DM001776pdf/files/DM001776pdf/jcr:content/translations/en.DM001776pdf

    The value is stored as a signed 16 bit value (2nd complement format).

    Just a quick reminder of the usual process:

    1) select a range (according to the datasheet) - this will give you the sensitivity

    2) select an output data rate (how often you want the sensor to measure the data)

    3) start measuring (there are modes for separate or combined accelerometer and gyroscope operation)

    4) wait for the data to be ready, read it and interpret it

    David

    1 reply

    Answer
    March 21, 2018
    Posted on March 21, 2018 at 08:23

    Hello,

    There are lots of similar questions here, have a look at this one, for example:

    https://community.st.com/0D50X00009XkXHfSAN

    (search for a keyword 'interpretation', by the way the interpretation principle is the same for accelerometer and gyroscope)

    You are saying you can read a value of 0..255, but that is wrong. The registers are two, High and Low, see datasheet page 66 and 67:

    http://www.st.com/content/ccc/resource/technical/document/datasheet/74/c4/19/54/62/c5/46/13/DM001776pdf/files/DM001776pdf/jcr:content/translations/en.DM001776pdf

    The value is stored as a signed 16 bit value (2nd complement format).

    Just a quick reminder of the usual process:

    1) select a range (according to the datasheet) - this will give you the sensitivity

    2) select an output data rate (how often you want the sensor to measure the data)

    3) start measuring (there are modes for separate or combined accelerometer and gyroscope operation)

    4) wait for the data to be ready, read it and interpret it

    David

    Visitor II
    March 21, 2018
    Posted on March 21, 2018 at 11:50

    Thank you! That's cleared it up a bit.

    Fraser