Home › Forums › Forums › Technical Support for BerryIMU › [Perhaps] Better Example Code
- This topic has 8 replies, 4 voices, and was last updated 2 years ago by Tannz0rz.
- AuthorPosts
- May 17, 2021 at 2:40 am #16718Tannz0rzParticipant
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):
May 17, 2021 at 4:24 am #16719Tannz0rzParticipantUsing 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.
May 17, 2021 at 7:16 am #16720djmaxwellParticipantA 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.
May 17, 2021 at 8:19 am #16723Tannz0rzParticipantI 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.
May 18, 2021 at 12:55 am #16725djmaxwellParticipantI have a v3 and the demo I linked above works fine for me. I believe I’ve changed the range with success as well.
May 18, 2021 at 2:32 pm #16730Mark WilliamsKeymasterremove 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 --
May 18, 2021 at 8:35 pm #16731Tannz0rzParticipantKeen eye Mr. Williams! That did the trick; now the readings scale according to their respective sensitivities. Thank you kindly for the help.
May 18, 2021 at 9:54 pm #16732pkstrskParticipantRemoving 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
May 19, 2021 at 7:35 am #16735Tannz0rzParticipantFantastic sleuthing pkstrsk, this truly fixed the issue.
- AuthorPosts
- You must be logged in to reply to this topic.