Skip to content

fix issue 103: use correct constant for gravity calculation#104

Open
amsjntz wants to merge 1 commit into
ElectronicCats:masterfrom
amsjntz:fix/issue-103
Open

fix issue 103: use correct constant for gravity calculation#104
amsjntz wants to merge 1 commit into
ElectronicCats:masterfrom
amsjntz:fix/issue-103

Conversation

@amsjntz

@amsjntz amsjntz commented Dec 3, 2025

Copy link
Copy Markdown

Implementing a fix for the gravity constant in the acceleration calibration process that caused the resulting z-axis offset to be incorrect. The gravity of 1G was being calculated like this: gravity = 32768 >> getFullScaleAccelRange();. getFullScaleAccelRange() returns 0 when the range of -2G to +2G is set, while the raw sensor readings go from -32768 to +32767. By that logic, 1G would equal about 16384.

Fixes #103

@Elizabeth-0

Copy link
Copy Markdown

I replicated the issue reported, and after running CalibrateAccel() with the current code, the Z-axis shows approximately 16364 instead of the expected value of ~8192 for the ±4G range.
This fix was previously mentioned in PR #94.

@xpeqex
xpeqex requested a review from sabas1080 December 8, 2025 19:31
@xpeqex
xpeqex requested a review from Elizabeth-0 December 9, 2025 16:51
@amsjntz

amsjntz commented Jun 16, 2026

Copy link
Copy Markdown
Author

Hi, does the issue require further investigation, for example to check if other constants are off as well? The bug still exist in the currently available version of the library in the Arduino repository, which probably led to lots of headaches for many people trying to get their MPU6050 to work, so I imagine fixing it could be very beneficial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Acceleration z-axis offset is incorrect after using CalibrateAccel function

3 participants