OBD-II Diagnostics
Interface
OBD-II (On-Board Diagnostics) is a standardized port for vehicle diagnostics. It provides direct access to the CAN bus and standard diagnostic services.
OBD-II Modes
text
# Standard OBD-II service modes (PIDs):
Mode 01: Current powertrain data
Mode 02: Freeze frame data
Mode 03: Emission diagnostic codes
Mode 04: Clear diagnostic codes
Mode 05: Oxygen sensor monitoring
Mode 06: On-board monitoring test results
Mode 07: Pending diagnostic codes
Mode 08: Control on-board systems
Mode 09: Vehicle information (VIN, calibration)
Mode 0A: Permanent diagnostic codes
# Example: Request RPM (Mode 01, PID 0C)
# Send: 7DF#02010C0000000000
# Response: 7E8#04410C0FA00000OBD-II Tools
python
# Python OBD library
pip install obd
import obd
connection = obd.OBD() # Auto-connects
# Query standard PIDs
rpm = connection.query(obd.commands.RPM)
speed = connection.query(obd.commands.SPEED)
print(f"RPM: {rpm.value}, Speed: {speed.value}")
# Get VIN
vin = connection.query(obd.commands.VIN)
# Read DTCs (Diagnostic Trouble Codes)
dtcs = connection.query(obd.commands.GET_DTC)
# ELM327-based tools
# Send raw AT commands
ATZ # Reset
ATSP0 # Auto protocol
0100 # Supported PIDs 01-20
0902 # Request VINUDS
Many vehicles support UDS (Unified Diagnostic Services - ISO 14229) which provides
extended diagnostic capabilities including ECU flashing.