Sending 01 0C to a car and getting engine speed back is the easy part. The OBD-II request example covers that. The next questions are harder: which of the standard PIDs does this car actually answer, what do the bytes mean, where are the trouble codes, and how do you get a VIN that does not fit in one CAN frame?

This guide answers those with real frame layouts and a Python scanner you can run on a SocketCAN interface.

The request and response in one table

Everything below uses 11-bit CAN IDs from ISO 15765-4:

ItemValue
Functional request (every OBD ECU listens)0x7DF
Physical request to one ECU0x7E0–0x7E7
Responses0x7E8–0x7EF, the ECU's request ID + 8
Byte 0 of a single frameNumber of bytes that follow
Positive responseService + 0x40, so 01 → 41, 03 → 43, 09 → 49
Negative response7F, the service, then a reason code

The services you will use most:

ServicePurpose
01Current data
02Freeze frame data
03Stored trouble codes
04Clear trouble codes and stored values
07Pending trouble codes
09Vehicle information, such as the VIN
0APermanent trouble codes

Ask which PIDs the car supports

Do not guess PIDs. Send PID 0x00:

Example
7DF  [8]  02 01 00 00 00 00 00 00     request: 2 bytes, service 01, PID 00
7E8  [8]  06 41 00 BE 3F A8 13 00     answer from the engine ECU

The four bytes after 41 00 are a bitmap. Each bit, from the most significant bit of the first byte to the least significant bit of the last, says whether one of the next 32 PIDs is supported.

ByteHexBinaryPIDs
ABE1011 111001–08: 01, 03, 04, 05, 06, 07
B3F0011 111109–10: 0B, 0C, 0D, 0E, 0F, 10
CA81010 100011–18: 11, 13, 15
D130001 001119–20: 1C, 1F, 20

The last bit is PID 0x20. It does not carry data; it says the ECU also answers PID 0x20, which is the bitmap for PIDs 21–40. Keep asking 0x20, 0x40, 0x60 and so on until that last bit is 0.

More than one ECU can answer a functional request. An engine ECU replies from 0x7E8, a transmission ECU often from 0x7E9, and each sends its own bitmap. To talk to one of them only, send to its physical ID: 0x7E0 for the ECU that answers from 0x7E8.

Decode the common PIDs

A is the first data byte after the PID and B the second. These formulas are the SAE J1979 definitions as listed in the OBD-II PIDs reference:

PIDNameFormulaUnit
04Calculated engine loadA × 100 / 255%
05Engine coolant temperatureA − 40°C
0BIntake manifold absolute pressureAkPa
0CEngine speed(256 × A + B) / 4rpm
0DVehicle speedAkm/h
0FIntake air temperatureA − 40°C
10Mass air flow(256 × A + B) / 100g/s
11Throttle positionA × 100 / 255%
1FRun time since engine start256 × A + Bs
21Distance travelled with MIL on256 × A + Bkm
2FFuel tank levelA × 100 / 255%
31Distance since codes cleared256 × A + Bkm
42Control module voltage(256 × A + B) / 1000V
46Ambient air temperatureA − 40°C
5CEngine oil temperatureA − 40°C
5EEngine fuel rate(256 × A + B) / 20L/h

For example, 41 0C 1A F8 is (256 × 26 + 248) / 4 = 1726 rpm.

A Python scanner

These functions decode bitmaps, values and trouble codes. They need no CAN hardware:

Python
SERVICE_01 = {
    0x04: ("Calculated engine load", "%", lambda a, b: a * 100 / 255),
    0x05: ("Engine coolant temperature", "°C", lambda a, b: a - 40),
    0x0B: ("Intake manifold pressure", "kPa", lambda a, b: a),
    0x0C: ("Engine speed", "rpm", lambda a, b: (256 * a + b) / 4),
    0x0D: ("Vehicle speed", "km/h", lambda a, b: a),
    0x0F: ("Intake air temperature", "°C", lambda a, b: a - 40),
    0x10: ("Mass air flow", "g/s", lambda a, b: (256 * a + b) / 100),
    0x11: ("Throttle position", "%", lambda a, b: a * 100 / 255),
    0x1F: ("Run time since engine start", "s", lambda a, b: 256 * a + b),
    0x21: ("Distance with MIL on", "km", lambda a, b: 256 * a + b),
    0x2F: ("Fuel tank level", "%", lambda a, b: a * 100 / 255),
    0x31: ("Distance since codes cleared", "km", lambda a, b: 256 * a + b),
    0x42: ("Control module voltage", "V", lambda a, b: (256 * a + b) / 1000),
    0x46: ("Ambient air temperature", "°C", lambda a, b: a - 40),
    0x5C: ("Engine oil temperature", "°C", lambda a, b: a - 40),
    0x5E: ("Engine fuel rate", "L/h", lambda a, b: (256 * a + b) / 20),
}


def supported_pids(base, data):
    """PIDs marked in a 4-byte bitmap from PID 0x00, 0x20, 0x40 ... Bit A7 is base + 1."""
    bits = int.from_bytes(data[:4], "big")
    return [base + i for i in range(1, 33) if bits & (1 << (32 - i))]


def decode_pid(pid, data):
    name, unit, formula = SERVICE_01[pid]
    a, b = data[0], data[1] if len(data) > 1 else 0
    return name, unit, round(formula(a, b), 2)


def decode_dtc(high, low):
    """Two DTC bytes to text: 0x01 0x33 -> P0133."""
    return f"{'PCBU'[high >> 6]}{(high >> 4) & 0x3}{high & 0xF:X}{low:02X}"


def parse_service_03(payload):
    """CAN response to service 03: 43, number of DTCs, then two bytes per DTC."""
    count = payload[1]
    return [decode_dtc(payload[i], payload[i + 1]) for i in range(2, 2 + 2 * count, 2)]


print(" ".join(f"{pid:02X}" for pid in supported_pids(0x00, bytes.fromhex("BE3FA813"))))
print(decode_pid(0x0C, bytes.fromhex("1AF8")))
print(parse_service_03(bytes.fromhex("43020133C158")))

Output:

Example
01 03 04 05 06 07 0B 0C 0D 0E 0F 10 11 13 15 1C 1F 20
('Engine speed', 'rpm', 1726.0)
['P0133', 'U0158']

Then add the bus side with python-can. obd_request sends one functional request and collects the single-frame answers from every ECU. scan_supported walks the bitmaps, and read_live_data decodes every supported PID it has a formula for:

Python
import time

import can


def obd_request(bus, service, pid=None, timeout=0.2):
    """Send a functional request to 0x7DF; return {response ID: payload} for single-frame answers."""
    request = [service] if pid is None else [service, pid]
    padding = [0x00] * (7 - len(request))
    bus.send(can.Message(arbitration_id=0x7DF, is_extended_id=False, data=[len(request), *request, *padding]))
    answers = {}
    deadline = time.monotonic() + timeout
    while (remaining := deadline - time.monotonic()) > 0:
        msg = bus.recv(remaining)
        if msg is None or not 0x7E8 <= msg.arbitration_id <= 0x7EF:
            continue
        length = msg.data[0]
        if length <= 7 and msg.data[1] == service + 0x40:  # single frame, positive response
            answers[msg.arbitration_id] = bytes(msg.data[1:1 + length])
    return answers


def scan_supported(bus):
    """Ask PID 0x00, 0x20, 0x40 ... until no ECU says the next range exists."""
    supported = {}
    base = 0x00
    while base <= 0xE0:
        for ecu, payload in obd_request(bus, 0x01, base).items():
            supported.setdefault(ecu, []).extend(supported_pids(base, payload[2:6]))
        if not any(base + 0x20 in pids for pids in supported.values()):
            break
        base += 0x20
    return supported


def read_live_data(bus):
    for ecu, pids in scan_supported(bus).items():
        print(f"ECU 0x{ecu:X} supports: " + " ".join(f"{pid:02X}" for pid in pids))
        for pid in pids:
            if pid not in SERVICE_01:
                continue
            payload = obd_request(bus, 0x01, pid).get(ecu)
            if payload:
                name, unit, value = decode_pid(pid, payload[2:])
                print(f"  {pid:02X} {name}: {value:g} {unit}")

Run it on a SocketCAN interface, with the car's ignition on:

Python
with can.Bus(interface="socketcan", channel="can0", bitrate=500000) as bus:
read_live_data(bus)

Output from a test run against a simulated engine ECU:

Example
ECU 0x7E8 supports: 01 03 04 05 06 07 0B 0C 0D 0E 0F 10 11 13 15 1C 1F 20 21 2E 2F 31 33 3C 40 41 42 46 49 4A 4C 51 5C 5E
04 Calculated engine load: 35.29 %
05 Engine coolant temperature: 50 °C
0B Intake manifold pressure: 33 kPa
0C Engine speed: 1726 rpm
0D Vehicle speed: 50 km/h
0F Intake air temperature: 20 °C
10 Mass air flow: 4 g/s
11 Throttle position: 18.04 %
1F Run time since engine start: 600 s
21 Distance with MIL on: 0 km
2F Fuel tank level: 60 %
31 Distance since codes cleared: 3434 km
42 Control module voltage: 14.4 V
46 Ambient air temperature: 15 °C
5C Engine oil temperature: 55 °C
5E Engine fuel rate: 5 L/h

20 and 40 appear in the supported list because they are the bitmap PIDs for the next ranges. PIDs without a formula in the table, such as 01 and 03, are listed but not decoded.

Is the check engine light on?

PID 01 answers that. Its first data byte does two jobs: bit 7 is the malfunction indicator lamp (MIL), and bits 0–6 are the number of stored emission-related trouble codes.

Example
7E8  [8]  06 41 01 81 07 65 00 00

81 is binary 1000 0001: the MIL is on and one code is stored. The remaining bytes describe which on-board tests the ECU supports and has completed.

Read trouble codes with service 03

Service 03 has no PID. The request is 01 03:

Example
7DF  [8]  01 03 00 00 00 00 00 00
7E8  [8]  06 43 02 01 33 C1 58 00

On CAN, the byte after 43 is the number of codes that follow, here 2. Older, non-CAN OBD protocols do not have this byte, so a decoder written for them misreads CAN answers unless it skips it. Each code is then two bytes:

Bits of the first byteMeaning
7–6Letter: 00 P (powertrain), 01 C (chassis), 10 B (body), 11 U (network)
5–4First digit, 0–3
3–0Second digit
Second byteLast two digits

So 01 33 is P0133 and C1 58 is U0158. Two codes fit in one CAN frame. Three or more come as a multi-frame ISO-TP message, which obd_request above skips; read them through an ISO-TP socket as in the VIN example below.

Service 07 returns pending codes and 0A permanent codes in the same format.

Be careful with service 04. It clears the stored codes, the freeze frame data and the test results the ECU has collected, and turns off the MIL. Permanent codes stay. The ELM327 datasheet notes that a car may run poorly for a short time afterwards while it recalibrates. Do not send it while exploring.

Read the VIN with service 09

The VIN request is 09 02. The answer is 20 bytes, 49 02 01 and then 17 ASCII characters, so it does not fit in one frame:

Example
7DF  [8]  02 09 02 00 00 00 00 00     request
7E8  [8]  10 14 49 02 01 57 56 57     first frame: 0x14 = 20 bytes in total
7E0  [8]  30 00 00 00 00 00 00 00     flow control from the tester: send the rest
7E8  [8]  21 5A 5A 5A 31 4A 5A 58     consecutive frame 1
7E8  [8]  22 57 30 30 30 30 30 31     consecutive frame 2

Join the data: 49 02 marks the reply, 01 is the number of data items (one VIN), and the last 17 bytes spell WVWZZZ1JZXW000001. The flow control frame goes to the ECU's physical ID, 0x7E0 for an answer from 0x7E8. Without it, the ECU stops after the first frame.

On Linux, the kernel's ISO-TP sockets handle the flow control and joining for you. Load the module with sudo modprobe can-isotp and use Python's standard library:

Python
import socket


def read_vin(interface="can0", request_id=0x7E0, response_id=0x7E8):
    """Read the VIN (service 09, PID 02) through a Linux ISO-TP socket."""
    with socket.socket(socket.AF_CAN, socket.SOCK_DGRAM, socket.CAN_ISOTP) as sock:
        sock.bind((interface, response_id, request_id))  # (interface, rx_addr, tx_addr)
        sock.settimeout(1.0)
        sock.send(bytes([0x09, 0x02]))
        reply = sock.recv(4095)
    if reply[:2] != b"\x49\x02":
        raise ValueError(f"unexpected reply: {reply.hex(' ')}")
    return reply[3:].strip(b"\x00").decode("ascii")  # skip 49 02 and the item count


print(read_vin())

If an ECU ignores the request, it may expect every frame padded to 8 bytes. The Linux ISO-TP socket pads frames when you set its CAN_ISOTP_TX_PADDING option.

When the answer is missing

What you seeLikely reason
No frames at allWrong bitrate (ISO 15765-4 allows 500 or 250 kbit/s), ignition off, or wrong pins
No answer to one PIDThat ECU does not support the PID. Check its bitmap first
7F 01 ..Negative response. The ECU received the request and rejected it; the last byte is the reason code
Only the first frame of a long answerFlow control was not sent, or sent to the wrong ID
The value you want is not in any bitmapIt is not emissions data. Manufacturer data is read with UDS instead; see finding OEM data with UDS DID scanning

Frequently asked questions

How do I know which OBD-II PIDs my car supports?

Send service 01 PID 00. The 4-byte answer is a bitmap of PIDs 01 to 20. If the last bit is set, ask PID 20 for the next 32, and continue with 40, 60 and so on until the last bit is 0.

Why do two ECUs answer the same OBD-II request?

The request to 0x7DF is functional, so every OBD-capable ECU answers. The engine ECU usually replies from 0x7E8 and the transmission from 0x7E9. Use the physical ID, 0x7E0 or 0x7E1, to address one of them.

How do I convert DTC bytes to a P-code?

The top two bits of the first byte give the letter (P, C, B or U), the next two bits the first digit, and the remaining 12 bits the last three digits in hex. 01 33 becomes P0133.

Why is my OBD-II VIN request only returning one frame?

The VIN is 20 bytes, so it is sent as an ISO-TP first frame followed by consecutive frames. Your tool must answer the first frame with a flow control frame to the ECU's physical ID, or the ECU stops sending.

References