cancel
Showing results for 
Search instead for 
Did you mean: 

LIS2DH12: problem while measuring degree of inclination in 0 - 360 values

danybr
Associate II

Hello there,

I have a device called RuuviTag that includes your LIS2DH12 accelerometer and that can be programmed by means of an IDE called Espruino in JavaScript.

For a project, I am trying to get the tilt angle of the device measured in degrees with a value between 0 and 360. At the moment, however, I'm not succeeding and looking on the internet I found this documentation:

https://www.st.com/content/ccc/resource/technical/document/application_note/d2/d6/22/4f/b9/8f/45/59/DM00119046.pdf/files/DM00119046.pdf/jcr:content/translations/en.DM00119046.pdf

Do you have any code to which I can get information for this problem? I tried to use equation 2 but it doesn't give me back the angle. I also tried equation 6 but it doesn't work. 

The values I can take from the accelerometer are values in mg.

Here is the photo:

0690X000006CH1aQAG.png

Do you know how to help me?

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Miroslav BATEK
ST Employee

These formulas works for range -90° to +90° in all three angles:

0690X000006CH53QAG.png

For Pitch you can use other formula for range -180° to + 180°:

Pitch = arctan2 (Y/Z)

View solution in original post

6 REPLIES 6
Miroslav BATEK
ST Employee

These formulas works for range -90° to +90° in all three angles:

0690X000006CH53QAG.png

For Pitch you can use other formula for range -180° to + 180°:

Pitch = arctan2 (Y/Z)

danybr
Associate II

Hi Miroslav, thank you very much.. It seems to be working properly!

In order to make that I used:

pitch = (((Math.atan2(accelerationY,accelerationZ) * 180) / 3.14 ) + 180 );

By using the AccelerationY and accelerationZ provided by the device, than converted in degree and "+180" offset to get values from 0 to 360.

danybr
Associate II

Hi @Miroslav BATEK​ 

I have a fairly serious problem: I hadn't considered angular acceleration!

In summary: the device that integrates the LIS2DH12 sensor reads the data with a frequency of 100 hz, for each sample from sensor (Ax,Ay,Az) it calculates the pitch and when a revolution (round/lap) is completed (so when the samples pass in sequence between 0-90°, then 90°-180°, then 180°-270° and finally 270°-360°) the counter is increased.

Calculating the pitch with the formula you gave me works, but only for tests made with the device moved by hand.

In fact, the device is now mounted on the crankshaft of a rotating motor and the device has to measure its revolutions. Now, after a certain rotation speed, the device is no longer able to measure these revolutions because (I suppose) it can no longer calculate the pitch correctly.

I absolutely need to find a way to count the number of revolutions made by the engine by means of this device. Do you have any suggestions? I would like to continue on the path of calculating pitch, but if it is not possible I am open to other ways, just include this sensor (I do not have the ability to add additional hardware).

Thank you very much!

Miroslav BATEK
ST Employee

I suppose the accelerometer is saturated by centrifugal force, so the only solution is to place the accelerometer to the center of the shaft. It would be good to see the acceleration data comming from the sensor in real situation. The you can evaluate if there is other option how to calculate the number of revolution.

I think it is not good idea to measure the number of revolution by accelerometer, using optical or magnetic sensor would be much easier.

danybr
Associate II

Hi @Miroslav BATEK​,

I'm trying to get more information about problem that I have, in order to find a solution.

In a static situation, angle of inclination (pitch in this case) is calculated right. Could you explain please the math behind this calculus? Why it works? Specifically, I did not quite understand how the accelerometer values are turned into an angle. I know the interpretation of the atan2 function, but I do not understand how the vectors detected by the sensor are then interpreted in a goniometric circumference and turned into an angle. I can not base myself on what I read in your datasheet:

https://www.st.com/content/ccc/resource/technical/document/application_note/d2/d6/22/4f/b9/8f/45/59/DM00119046.pdf/files/DM00119046.pdf/jcr:content/translations/en.DM00119046.pdf

For example, I get a pitch of 103,94 if I get values y: -0,980 and z: 0,244 with accelerometer with a face towards me, so:

0690X000006CxQQQA0.png

Thanks!

Miroslav BATEK
ST Employee

I'm sorry, but I can't explain here the basic principles.

I recommend you ask some of you colleague with a good physics knowledge.