cancel
Showing results for 
Search instead for 
Did you mean: 

Example for LSM303DLHC Accelerometer

anthony2
Associate II
Posted on November 27, 2013 at 15:26

Hi,

I need to read the accelerometer data from LSM303DLHC. I use the STM32F401 Discovery board and the ''stm32f401_discovery_lsm303dlhc.c'' library.

I read carefully the datasheet, especially the section 7.1 in page 24 with the register setup but I would like to know if someone has any project example that could help me to understand how to use the sensor.

Thank you in advance.

Kind regards,

Antho

6 REPLIES 6
Thiago REIS
Associate II
Posted on November 27, 2013 at 17:01

Hello Antho,

We are currently creating a section of this forum to contain examples of applications using ST's MEMS. I will add one example for you application too.

Once we have the codes, I can also post it here as a reference.

Thank you very much,

Thiago Reis

anthony2
Associate II
Posted on November 28, 2013 at 09:41

Hi Thiago,

Thank you for your time. I think that this new section is a good idea, it might be very helpful for beginners like me.

Antho

olavi
Associate III
Posted on December 16, 2013 at 06:31

Antho,

Just in case that you are still looking some additional information about the LSM303 usage, I would recommend that you look the selftest.c file in the F401 demonstration folder.  There you have the code to read the sensor data (such as LSM303DHLC_CompassReadAcc) using the I2C connection.  Once you have the accelerometer and compass data, you should combine that with the gyro data (from L3GD20).

The accelerometer has a lot of short term noise, but good long term stability.  The gyro has little noise, but it has a bad drift.  You can use a Kalman filter to combine the data streams, simple low pass and high pass filters, or add-hoc methods (such as model based bias adjustment).

sudhi
Associate
Posted on December 20, 2013 at 01:23

Hi Thiago,

Good to know that you are adding a separate section for the applications.

The link

http://www.st.com/web/en/catalog/tools/PF257534#

anthony2
Associate II
Posted on January 08, 2014 at 17:49

Hi,

Thanks for your time Ollie, your reply has been very helpful.

Actually, I am trying to test the accuracy of the Inertial Measurement Unit for a school project. That is why I need to get the output data from both the accelerometer and the gyroscope.

But first, I am trying to exploit the output data to turn on the LED matching with the acceleration direction (as in the demo of the gyroscope). I set the linear acceleration range at 8g in the register but I have not been able to determine which kind of data is returned by the function ''LSM303DLHC_Read(ACC_I2C_ADDRESS,LSM303DLHC_OUT_X_L_A,6,tmpbuffer)''.

In the data sheet, it is mentioned that the 16 bit data output is expressed in 2's complement. this data is then converted into a float. The buffer declaration is : float buffer[6]. However, in the different programs I read, the X and Y values were define by Xval = buffer[0] and Yval = buffer[1] or buffer[2].

But, aren't we supposed to get only the Xval by the function above (parameter : LSM303DLHC_OUT_X_L_A) ? And why is the float value converted in 8 bit for the test (''if((int8_t)Buffer[0] < -2)'') ?

About the data filtering, I will look into the Kalman filter, thank you for the idea.

Kind regards,

Antho
Thiago REIS
Associate II
Posted on January 17, 2014 at 13:33

Hello Sudhi,

Were you able to download the software that you needed?

If not, please send me a message with your contact information and project description at thiago.reis@st.com

Thank you,

Thiago