user78111: I recently got an MPU6050 and I noticed the accelerometer data was a bit off, especially on the Z axis.
I'm running it on a Teensy 4.0 with Adafruit's MPU6050 library and basic example code: https://github.com/adafruit/Adafruit_MPU6050/blob/master/examples/basic_readings/basic_readings.ino
While stable on a flat surface (+Z up), it's reading ~8.5 m/s^2 and when flipped over (-Z up), ~11.6 m/s^2:
+Z:
Acceleration X: -0.06, Y: 0.00, Z: 8.44 m/s^2
-Z:
Acceleration X: -0.01, Y: -0.07, Z: -11.57 m/s^2

Aligning the other axes vertically gives me:
+X:
Acceleration X: 10.16, Y: -0.16, Z: -0.03 m/s^2
-X:
Acceleration X: -9.27, Y: -0.10, Z: -0.18 m/s^2
+Y:
Acceleration X: 0.07, Y: 9.55, Z: -0.10 m/s^2
-Y:
Acceleration X: 0.04, Y: -9.93, Z: -0.05 m/s^2

The X and Y readings could be adjusted fairly close to 9.81 m/s^2 with just an offset, but it seems like the Z axis would also require some scaling.
My question, is there a standard method of calibrating it in code?

user20245: Yes an accelerometer can be calibrated.  An offset for each of the 3 accelerometers can be found such that the absolute value of the maximum and minimum values of any given accelerometer axis are equal.  The maximum and minimum values can be found by rotating the accelerometer such that each axes is pointed directly toward and directly away from the earth.  Once each axes is normalized each axes needs a magnitude adjustment value such that the maximum value of all axes equal one another.  It may be convenient the product of the maximum of any given axes and that axes' magnitude adjustment value is 9.8 (meters per second * second).

78111: <p>I recently got an MPU6050 and I noticed the accelerometer data was a bit off, especially on the Z axis.</p>
<p>I'm running it on a Teensy 4.0 with Adafruit's MPU6050 library and basic example code: <a href="https://github.com/adafruit/Adafruit_MPU6050/blob/master/examples/basic_readings/basic_readings.ino" rel="nofollow noreferrer">https://github.com/adafruit/Adafruit_MPU6050/blob/master/examples/basic_readings/basic_readings.ino</a></p>
<p>While stable on a flat surface (+Z up), it's reading ~8.5 m/s^2 and when flipped over (-Z up), ~11.6 m/s^2:</p>
<pre><code>+Z:
Acceleration X: -0.06, Y: 0.00, Z: 8.44 m/s^2
-Z:
Acceleration X: -0.01, Y: -0.07, Z: -11.57 m/s^2
</code></pre>
<p>Aligning the other axes vertically gives me:</p>
<pre><code>+X:
Acceleration X: 10.16, Y: -0.16, Z: -0.03 m/s^2
-X:
Acceleration X: -9.27, Y: -0.10, Z: -0.18 m/s^2
+Y:
Acceleration X: 0.07, Y: 9.55, Z: -0.10 m/s^2
-Y:
Acceleration X: 0.04, Y: -9.93, Z: -0.05 m/s^2
</code></pre>
<p>The X and Y readings could be adjusted fairly close to 9.81 m/s^2 with just an offset, but it seems like the Z axis would also require some scaling.</p>
<p>My question, is there a standard method of calibrating it in code?</p>
 20245: <p>Yes an accelerometer can be calibrated.  An offset for each of the 3 accelerometers can be found such that the absolute value of the maximum and minimum values of any given accelerometer axis are equal.  The maximum and minimum values can be found by rotating the accelerometer such that each axes is pointed directly toward and directly away from the earth.  Once each axes is normalized each axes needs a magnitude adjustment value such that the maximum value of all axes equal one another.  It may be convenient the product of the maximum of any given axes and that axes' magnitude adjustment value is 9.8 (meters per second * second).</p>
