2023-06-17 01:58 PM
Hi, I created a SensorTile.box project in STM32CubeIDE in which I am receiving the acceleration data from the LSM6DSOX accelerometer. I would like to convert the data I receive from the sensor into the [mg] unit in the same way it is converted in the Data recorder app which you can download on to the SensorTile.box when using the ST BLE Sensor app. Thats why I am wondering if there is any Project code for the Data recorder app, where I could see how the calculation is performed. (I require the same kind of data because I have taught a machine learning model on data received from using the Data recorder app)
I have set the accelerometer to work at 104 Hz and 4g. My current calculation of accelerometer data is based off of the code I found in the SensorTileBox-BLESensors project from the FP-SNS-STBOX1 function pack. Here is the code (for the X axis, Y and Z are also calculated like X) I am using to get the acceleration data and convert it to the [mg] unit:
For instance the data I received from the app while the SensorTile.box was stationary, was around 993 mg on the Z axis. When I used my own project and the SensorTile.box was in the same position, the data was around 960 mg on the Z axis. That is why I am assuming that I am not converting the data correctly.
Thank you in advance.
Solved! Go to Solution.
2023-06-19 06:23 AM
Hi @Bxy ,
Lookig at your code, you write:
the correct form should be:
int16_t AccelX;
int32_t AccelX_mg:
AccelX= ((int16)AccelX1 <<8 ) | AccelX2);
AccelX_mg= (int32_t)((float)AccelX * LSM6DSOX_ACC_SENSITIVITY_FS_4G);
If this solves your problem, please mark my answer as "Accept as Solution" by clicking on the "Select as Best" button, this can be helpful for Community users to find this solution faster :)
2023-06-17 09:03 PM
Interesting, I didn't know about this IC, maybe I can compare it with the MPU-6050, which is used a lot by the Arduino community, it has a lot of libraries too.
I also found these videos, if you haven't seen them, they usually help, the ST channel on YouTube has many videos about the products:
[LSM6DSOX Step-By-Step Tutorial, Part 1 of 5: Introduction]:
2023-06-18 02:18 PM
Thank you, but I require the calculation that is used in the Data recorder app to get the data in [mg] units and probably also the settings at which the accelerometer inside LSM6DSOX is running at. I am using the machine learning model through X-CUBE-AI, so the tutorial videos arent exactly helpful for that, nor are the others that I found that do use X-CUBE-AI.
2023-06-19 06:23 AM
Hi @Bxy ,
Lookig at your code, you write:
the correct form should be:
int16_t AccelX;
int32_t AccelX_mg:
AccelX= ((int16)AccelX1 <<8 ) | AccelX2);
AccelX_mg= (int32_t)((float)AccelX * LSM6DSOX_ACC_SENSITIVITY_FS_4G);
If this solves your problem, please mark my answer as "Accept as Solution" by clicking on the "Select as Best" button, this can be helpful for Community users to find this solution faster :)
2023-06-19 12:57 PM
Thank you, I seem to be getting just about the same values now.
Before I accept the solution I would like to also ask if you know what settings are being used on the LSM6DSOX (which values are being sent to which registers to set up the accelerometer), when I choose to use the Data recorder app from the ST BLE Sensor app. The settings in the Data recorder app for the IMU Accelerometer sensor are: 0 minutes Acquisition Time, Low power Power mode, 104 Hz ODR and 4 g FS.
Because currently, I am just setting the accelerometer to 104 Hz ODR and 4 g FS as such ( in the CTRL1_XL register):
I would also guess that Low power Power mode means disabling high-performance operating mode in the CTRL6_C register like this:
So I would appreciate it a lot if you could tell me how the LSM6DSOX is being set up when using the app. Again thank you very much for your help.
2023-06-21 05:22 AM
Ciao @Bxy ,
The settings you use are the same of the app, because the fw performs the same operations.
The only difference could be in the ODR: the setting for the sensor is the same (write 0x48 in register 0x10) but for some ODRs the timer at which the data is read/written is slightly different (for example it could be 100 instead of 104)
If this difference is important to you I can check with the dedicated team and let you know.
If this helps you, please mark my answer as "Best Answer" by clicking on the "Accept as Solution" button, this can be helpful for Community users to find this solution faster.
2023-06-21 10:36 AM
No thank you. If those are the same settings used in the LSM6DSOX registers, I doubt I would be receiving any different acceleration values compared to the app.
Thank you for your help.