[Perhaps] Better Example Code

Home Forums Forums Technical Support for BerryIMU [Perhaps] Better Example Code

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
  • #16718

    Hello OzzMaker team. I would like to preface my post with a bit of brutal honesty: the provided examples are not particularly great nor helpful.

    I am trying to mend this (for the BerryIMU V3) by creating a class that provides some customizable options. To do this I’ve had to delve into the datasheets of both the LSM6DSL and LIS3MDL. Additionally, my code intends to provide the user with SI units for acceleration, angular velocity, and magnetic flux density, instead of the non-SI units provided.

    The example, however, yields results for acceleration (in an idle, non-moving state) as such:

    -1.0, -0.8, 20.0

    Which is concerning, as I would expect a Z value of around -9.8.

    Could one of your team members perhaps have a look at my code and give it a test? I would greatly appreciate any and all assistance. I really do not understand why I am getting these unusual values, and I would love to make this available for other BerryIMU users.

    The project is here below (requires no dependencies):



    Using the FS_XL = ±8 option, the sensitivity is stated as 0.244. To convert from mG to m/s^2, the calculation ought to be as simple as the following:

    acceleration * 0.244 * 9.8 / 1000.0

    Bear in mind this worked perfectly fine with my BerryIMU V2 using the LSM9DS1, albeit with a different sensitivity value. But now it does not work at all.


    A couple of things I noticed:

    1. you shouldn’t be multiplying by 9.8 in you acceleration calculation. It should be acc * sensitivity / 1000.0

    2. Your acceleration range setting appears to not match what you are using for your sensitivity. Your resting acceleration is half of 9.8.


    Their example here is pretty good.

    Converting values from an Accelerometer to G



    I appreciate the reply djmaxwell, however I am trying to convert from mG to m/s^2, not G, so the factor of 9.8 is necessary in this case. I need to integrate these values for transform approximation purposes.

    I have come to notice one thing: regardless of whether FS_XL is 2, 4, 8, or 16, the same sensitivity factor of 0.122 yields the proper value. Can anyone confirm this for me? I reiterate I am using the BerryIMU V3.


    I have a v3 and the demo I linked above works fine for me. I believe I’ve changed the range with success as well.

    Mark Williams

    remove the low pass filter from your code and see if this fixes it
    writeByte(LSM6DSL_ADDRESS, LSM6DSL_CTRL8_XL, 0b11001000); // Low pass filter enabled, BW9, composite filter

    Mark --OzzMaker.com --


    Keen eye Mr. Williams! That did the trick; now the readings scale according to their respective sensitivities. Thank you kindly for the help.


    Removing the low pass filter helps for a simple reason, look at your LSM6DSL.h file at line 7. The address is identical to line 6. According to the datasheet, CTRL1_XL really is at HEX 0x10, however the CTRL8_XL register is at address 0x17. Fix that in your .h file and you can keep using the low pass filter too. https://github.com/ozzmaker/BerryIMU/issues/23


    Fantastic sleuthing pkstrsk, this truly fixed the issue.

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.

Blip, blop, bloop…