Skip to content

K-Line

ESP32 interface for automotive K-line buses. Read diagnostics, control modules, and talk to ECUs across hundreds of vehicles — with optocoupler isolation and SPICE-validated circuit design.

K-Line is an ESP32 library and hardware interface for the single-wire buses found in cars from the mid-90s through late 2000s. It handles two distinct protocols that share the same physical layer:

  • BMW I/K-Bus — the body control network on E31 through E87 chassis. Lights, locks, windows, climate, steering wheel controls, instrument cluster. Multi-master, 9600 baud.
  • OBD-II K-line — the ISO 9141 / ISO 14230 diagnostic protocol used by Ford, Honda, Toyota, VW, Chrysler, and dozens more. Read PIDs, clear DTCs, talk to ECUs. Master/slave, 10400 baud.

The hardware uses PC817 optocouplers for galvanic isolation between the ESP32 and the vehicle’s 12V electrical system. The circuit is SPICE-validated — every signal path simulated in LTspice before soldering.

400+ Vehicles

BMW, Ford, Honda, Toyota, VW, Audi, Mercedes, Volvo, Subaru, Mazda, Hyundai, Kia, Chrysler, and more. Any car with ISO 9141 or KWP2000 diagnostics.

SPICE Validated

Eight netlists cover both signal paths, three parameter sweeps, and two bus impedance scenarios. The R2=220 ohm fix for 3.3V ESP32 was found through simulation, not guesswork.

Reviewed and Hardened

Two code review rounds caught ISR race conditions, protocol framing bugs, and timeout underflows. Defensive design throughout — checksums validated, echo verified, sessions kept alive.

Three ESP32 Variants

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

Hardware circuit is SPICE-validated. Firmware builds clean across all three ESP32 environments. Next: breadboard prototype, loopback testing, and vehicle testing on BMW E46 K-Bus and Ford Fiesta K-line.

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