[Nexus 5X Q&A, Help & Troubleshooting] Fif_:
Great to be able to help.

I found it easy to calibrate the accelerometer: just raise the middle and bottom section of the phone over a book. The camera parts can be dangling. :)

I have since made more discoveries and was able to calibrate the device correctly and have the calibration persist on reboot.

My sensors problems are now gone!

Instructions follow below.

Just reboot. These changes are in memory only.

If you actually want to undo the policy changes without rebooting, run as root:

supolicy --live 'deny sensortool devpts chr_file { read write getattr }' 'deny sensortool persist_sensortool_file file { write }'

---------- Post added at 04:30 PM ---------- Previous post was at 03:47 PM ----------

After struggling with this for a while, here's the latest update about what I found.

Contrarily about what I wrote earlier on, the Nexus 5X does read the calibration data in /persist/sensorcal.json at boot.

What happens is the calibration procedure (as initiated by /vendor/bin/sensortool.bullhead -c <sensor>) correctly calibrates the sensor, updates the sensor with the new calibration data, then writes the calibration file /persist/sensorcal.json wrong.

That's why running /vendor/bin/sensortool.bullhead -c <sensor> fixes the problem until the next reboot.

So the fix is to edit by hand the /persist/sensorcal.json file, trying to tweak the calibration values, reboot, check the sensor and do that a few times until you have no sensor bias.

Well, you can do it this way (rebooting between every change to /persist/sensorcal.json), or you can look at the next post for an alternate method that does not involve rebooting twenty times.

WARNING: If you make a typo editing /persist/sensorcal.json, like adding a comma where it's not needed or removing one where it's needed, your device will not boot. You will have to get into recovery and fix the file there. What's even worse, a factory reset will not fix a busted /persist/sensorcal.json as /persist is not wiped during factory reset.

DO THIS AT YOUR OWN RISK

Before you make any change to /persist/sensorcal.json:

Make a backup of the file

Make sure you know how to restore that backup from recovery, without Android booting.

Again: a mess up will softbrick your phone.

My particular case:

My gyrometer readings were off. When the device was still, a simple app to report the gyro reading was returning a non-zero value. The device was thinking it was rotating around only one axis.

Needless to say all apps that used the gyro (eg. driving games) were not happy about this.

My original /persist/sensorcal.json file looked like this:

{
"accel": [
22,
-2,
-8
],
"gyro": [
22,
-9,
-9
],
"proximity": 1
}
}

I started changing the numbers in the gyro section. After changing the "22" to "100" and rebooting, I saw that my original faulty axis was still wrong, but also another axis was now busted.

So I reverted that change, moved on the next number.

Finally I found that the third figure was the one that was corresponding to my busted axis.

I managed to tweak that number until my gyro was reporting no motion at rest.

And now my Nexus 5X's sensors are just fine, and I can play driving games :)

My final /persist/sensorcal.json looks like this:

{
"accel": [
22,
-2,
-8
],
"gyro": [
22,
-9,
-73
],
"proximity": 1
}
}

Since the problem is likely to be memory corruption in /vendor/bin/sensortool.bullhead, on your device, a different calibration value may be affected.

If you want to "factory recalibrate the device" (and re-break your sensors), just follow the instructions in post #5.