← Projects
electronics intermediate 1 days ago ◑ 6 views ◯ 6 min read

Build an ESP32 OBD-II CAN Bus Reader and Data Logger

Build time: 4-6 hours
Tools needed: Soldering iron, wire strippers, small Phillips screwdriver, multimeter, computer with Arduino IDE or PlatformIO installed
esp32can busobd2data loggerelectronicsmcp2515
Parts List

Every car built since 2008 (and most built since the mid-1990s) exposes a CAN bus through its OBD-II port, carrying far more data than the generic "check engine" codes a cheap Bluetooth scanner reads. Engine RPM, coolant temperature, throttle position, fuel trim, wheel speed, and dozens of other parameters are broadcast on that bus continuously, whether or not anything is listening. This project builds a standalone ESP32-based reader that taps into that stream, decodes the parameters you care about, logs them to a microSD card for later analysis, and shows live values on a small OLED screen — no phone, no subscription app, no cloud account. It's the same basic approach used by data-logging boxes sold for track days and tuning work, built from parts that together cost a fraction of a commercial unit.

Why an MCP2515 Instead of the ESP32's Built-In CAN Controller

Several ESP32 variants (including the plain ESP32 and the ESP32-S3) have a built-in TWAI (Two-Wire Automotive Interface) peripheral, which is Espressif's name for a CAN controller. In principle you could skip the MCP2515 module and wire a standalone CAN transceiver directly to the ESP32's TWAI pins. In practice, the MCP2515 module route is more forgiving for a first build: it's a complete, pre-wired board with its own crystal, its own transceiver, and a stable SPI interface that isolates CAN bus electrical noise from the ESP32's other peripherals. If you already have a TWAI-capable ESP32 and want to skip a part, the wiring and software differ enough that it's worth treating as a separate project rather than a drop-in substitution.

Understanding What You're Actually Listening To

OBD-II defines a standardized set of Parameter IDs (PIDs) for emissions-related data — Mode 01 PIDs like 0x0C (engine RPM) and 0x05 (coolant temperature) are standardized across nearly every manufacturer. Beyond those, each manufacturer broadcasts huge amounts of proprietary data on the same bus for their own body control, transmission, and infotainment modules, using PIDs and scaling factors that are never officially published. This project focuses on the standardized Mode 01 PIDs, which work identically across makes and models, rather than reverse-engineering manufacturer-specific traffic (a worthwhile follow-up project, but a much deeper rabbit hole).

PID (hex)ParameterFormulaUnits
0x0CEngine RPM((A*256)+B)/4RPM
0x0DVehicle speedAkm/h
0x05Coolant temperatureA-40°C
0x11Throttle positionA*100/255%
0x0FIntake air temperatureA-40°C
0x06Short term fuel trim(A-128)*100/128%
0x2FFuel tank levelA*100/255%

Step 1: Wire the MCP2515 Module to the ESP32

The MCP2515 communicates over SPI. Wire it as follows, using the ESP32 DevKitC's default VSPI pins:

Most MCP2515 breakout modules already include the 120 ohm termination resistor across CAN-H/CAN-L. If yours doesn't, add one — OBD-II buses are already terminated at both ends inside the vehicle, so an unterminated tap generally still works, but a mismatched impedance on a long lead can cause intermittent read errors.

Step 2: Wire the OBD-II Connector

On the standard 16-pin OBD-II connector, the pins you need are:

Never feed the OBD port's 12V rail directly into the ESP32's 5V pin. Use a proper buck converter or a cheap USB car charger module gutted for its regulator board — automotive 12V rails see significant voltage spikes during cranking and alternator load dumps that a dedicated automotive-rated regulator is designed to survive.

Step 3: Flash the Firmware

Using the Arduino IDE with the autowp-mcp2515 and Adafruit SSD1306 libraries installed, the core loop does three things every cycle: requests a PID over CAN, waits for the response frame, and decodes it using the formulas above. A minimal request frame for engine RPM looks like this:

// Standard OBD-II request, ID 0x7DF, Mode 01, PID 0x0C (RPM)
struct can_frame request;
request.can_id  = 0x7DF;
request.can_dlc = 8;
request.data[0] = 0x02;  // 2 additional data bytes follow
request.data[1] = 0x01;  // Mode 01 (show current data)
request.data[2] = 0x0C;  // PID: engine RPM
request.data[3] = 0x00;
request.data[4] = 0x00;
request.data[5] = 0x00;
request.data[6] = 0x00;
request.data[7] = 0x00;
mcp2515.sendMessage(&request);

The ECU responds on ID 0x7E8 with the requested value in bytes A and B of the payload. Poll each PID on a rotation (RPM and speed at higher priority/frequency, coolant temp and fuel trim less often) rather than requesting everything every loop iteration — flooding the bus with requests can cause some ECUs to throttle or ignore additional queries.

Step 4: Log to microSD and Display Live Values

Write each decoded sample to a CSV file on the SD card with a timestamp, using the ESP32's internal millis() counter since you won't have reliable wall-clock time without adding a GPS or NTP source. A typical log line looks like 12453,2341,62,89,14.2 (ms since boot, RPM, speed, coolant temp, throttle %). Buffer writes in RAM and flush every second or two rather than opening and closing the file every loop iteration; SD card writes are slow relative to CAN polling and will create gaps in your data if done naively on every sample. The OLED display can cycle through 3-4 values per screen, refreshing every 250-500ms, which is fast enough to be useful without visibly lagging.

Safety Notes

Tapping a live vehicle CAN bus is generally safe for passive listening and standard OBD-II PID requests — this is exactly what every commercial OBD scanner does. That said, keep a few things in mind:

Once the logger is running reliably, the next step is usually pulling the CSV off the SD card after a drive and graphing it in a spreadsheet or a tool like Python/pandas — RPM versus throttle position over a drive cycle makes shift points and part-throttle behavior obvious in a way that watching a live gauge never does.