MPU-6050 Attitude Monitor
Bare-metal Artificial Horizon on STM32L031K6
- Role
- Embedded firmware engineer
- Year
- 2026
- Status
- Prototype
- Stack
- C · STM32L031K6 · I2C · Bare-metal · SSD1306 · MPU-6050 · Keil µVision
- MCU
- STM32L031K6 · Cortex-M0+
- Buses
- 2 × I²C
- Framebuffer
- 1 KB
- Frame rate
- ≈5–7 fps
Overview
Bare-metal STM32L031K6 firmware that renders an MPU-6050 accelerometer/gyro on a 128×64 SSD1306 OLED as an aircraft-style artificial horizon. No HAL, no CubeMX: direct register access, two independent I²C buses (hardware and bit-banged), and a boot diagnostic ladder that pinpoints wiring faults instead of just reporting "not found".
What I built
- Direct register access throughout: no HAL, no CubeMX
- Two independent I²C buses: hardware I²C1 for the OLED, bit-banged for the sensor
- Boot diagnostic ladder: OLED self-test, DC pin test, bus scans, then init or a failure screen that says why
- Bus-scan result feeds the driver, so the sensor is used at whichever address answers
- Roll and pitch derived from gravity via atan2, drift-free; yaw left out rather than shown drifting
- Artificial horizon, roll scale and acceleration gauge rendered into a 1 KB framebuffer
- WHO_AM_I not whitelisted: GY-521 clone dies (0x70–0x98) accepted; only a NACK means absent
- DC pin test proves wire and module power with no I²C traffic, using the internal pull-down against the breakout pull-ups
Key decisions
- MCU
- STM32L031K6 · Cortex-M0+
- Buses
- 2 × I²C
- Framebuffer
- 1 KB
- Frame rate
- ≈5–7 fps
Stack
C · STM32L031K6 · I2C · Bare-metal · SSD1306 · MPU-6050 · Keil µVision
Outcome
≈5–7 fps artificial horizon from a 1 KB framebuffer on a Cortex-M0+. Prototype · 2026.
Next case — 07 / 10
OV5640 Camera CaptureAll work