Raspberry Pi practice problem · I²C, SPI, UART & 1-Wire
Calibrate the gyro
HardBudget $9Python · gpiozero
A real gyroscope never reads exactly zero when still: each unit has a small zero offset of a few °/s. Calibrate it by averaging while the board is still, then subtract.
Build: an MPU-6050 on I²C (3V3, AD0 to GND → 0x68).
Program:
- Wake it (write 0 to 0x6B).
- During the first second, while the board is still, average at least 50 readings of the Z gyro: signed 16-bit big-endian at 0x47–0x48, 131 counts per °/s at the default range.
- Then every 0.25 s print the calibrated yaw rate, rounded to whole °/s:
Yaw: 30 deg/s
The test keeps the board still until 3 s, turns it at 30 °/s from 3 s, and at −15 °/s from 6 s.