Skip to content

K-Line

Multi-protocol automotive bus library for ESP32. Optocoupler-isolated hardware interface with SPICE-validated circuit design.

An ESP32-based interface board for talking to BMW’s proprietary body/instrumentation bus (I-Bus and K-Bus) and OBD-II K-line diagnostic ports. Uses PC817 optocouplers for galvanic isolation from the vehicle’s 12V electrical system.

The firmware library — K-Line — handles both protocols through a shared transport layer, with separate protocol handlers for BMW’s multi-master bus and OBD-II’s master/slave diagnostic sessions.

Two Protocols, One Board

BMW I/K-Bus (9600 baud, 8E1, XOR checksum) and OBD-II K-line (10400 baud, 8N1, mod256 checksum) share the same physical layer but have completely different framing and initialization. K-Line handles both.

SPICE Validated

Every circuit path simulated in LTspice before soldering. Three parameter sweeps identified the R2=220 ohm fix for 3.3V ESP32 compatibility. Six netlists document the full operating envelope.

Code Reviewed

Two rounds of code review caught concurrency bugs (64-bit torn reads, TX loopback race), protocol issues (UART pin detach no-op, timeout underflow), and missing safety checks. All fixed.

Three ESP32 Variants

Builds for ESP32 (Xtensa), ESP32-C3 (RISC-V), and ESP32-S3. PlatformIO project with per-board pin overrides.

BMW I/K-Bus: E31 (8 Series), E38 (7 Series), E39 (5 Series), E46 (3 Series), E52 (Z8), E53 (X5), E83 (X3), E85 (Z4), E87 (1 Series)

OBD-II K-line: Any vehicle using ISO 9141-2 or ISO 14230-4 (KWP2000) diagnostic protocols

Hardware circuit is SPICE-validated. Firmware builds clean across all environments. Next steps: breadboard prototype, loopback testing, and vehicle testing.

Circuit design based on muki01/I-K_Bus (MIT license). R2 modification, SPICE validation, ESP32 port, and multi-protocol architecture are original work.