Skip to content

QaximGhumman/OBD-Python

Repository files navigation

🚗 OBD-Python — Fetch Car Real-Time Data Through OBD-II

A Python-based tool that connects to a vehicle's OBD-II port and fetches real-time diagnostic data — such as speed, RPM, engine temperature, fuel level, and more — directly from the car's ECU.

Python OBD-II License


📌 Features

  • 🔌 Connects to any car via a Bluetooth / USB OBD-II adapter (ELM327)
  • 📊 Reads live data: speed, RPM, coolant temperature, fuel level, throttle position, and more
  • 🧠 Decodes raw OBD-II PIDs into human-readable values
  • 💾 Logs data to CSV for later analysis
  • 🧪 Includes a mock mode (OBD-mock.py) for testing without a car or adapter
  • ⚡ Lightweight — works on a laptop or Raspberry Pi in the car

🛠️ Tech Stack

  • Python 3
  • python-OBD — library for OBD-II communication
  • PySerial — handles the serial/Bluetooth connection to the adapter

🏗️ Architecture

graph LR
    A[Car ECU] -->|OBD-II Port| B[ELM327 Adapter]
    B -->|Bluetooth / USB / Serial| C[Python Script]
    C --> D[python-OBD Decoder]
    D --> E[Live Terminal Display]
    D --> F[(CSV Log File)]
Loading

Flow: The car's ECU exposes live sensor data through the OBD-II port → an ELM327 adapter translates this into a serial/Bluetooth signal → the Python script connects to that adapter, sends PID requests, decodes the responses, and displays or logs the results.


📂 Project Structure

OBD-Python/
├── OBD-v6.py                        # Latest/main version — run this one
├── OBD-v5.py                        # Earlier iteration
├── OBD-v4.py                        # Earlier iteration
├── OBD-v3.py                        # Earlier iteration
├── OBD-v2.py                        # Earlier iteration
├── OBD-v1.py                        # First working version
├── OBD-mock.py                      # Simulated OBD data — no adapter/car needed
├── veh_config.json                  # Per-vehicle configuration
├── obd_dataset.csv                  # Sample dataset
├── obd_log_20250705_155130.csv      # Example logged session
└── README.md

🚧 Note: This repo currently has several versioned files (OBD-v1.pyOBD-v6.py) from active development. OBD-v6.py is the most current — the older versions are kept for reference but will likely be moved into an /archive folder in a future cleanup. If you're just trying the project, start with OBD-v6.py.


⚙️ Installation

# Clone the repository
git clone https://github.com/QaximGhumman/OBD-Python.git
cd OBD-Python

# Create a virtual environment (optional but recommended)
python -m venv venv
source venv/bin/activate   # On Windows: venv\Scripts\activate

# Install dependencies
pip install obd pyserial

▶️ Usage

Option 1 — Test without hardware (recommended first step)

python OBD-mock.py

This simulates OBD-II responses so you can see how the tool works before connecting real hardware.

Option 2 — Connect to a real vehicle

  1. Plug an ELM327 OBD-II adapter (Bluetooth or USB) into your car's OBD-II port (usually under the dashboard)
  2. Pair/connect the adapter to your laptop or Raspberry Pi
  3. Update veh_config.json with your adapter's connection details if needed
  4. Run:
python OBD-v6.py
  1. You'll see live data streaming in the terminal:
Speed: 42 km/h
RPM: 2100
Coolant Temp: 89°C
Fuel Level: 63%

📊 Sample Code Snippet

import obd

connection = obd.OBD()  # auto-connects to USB or RF port

cmd = obd.commands.SPEED
response = connection.query(cmd)

print(f"Speed: {response.value}")

🚧 Roadmap / Ideas

  • Add a live graph (speed/RPM over time) using Matplotlib
  • Build a simple GUI dashboard
  • Support exporting to a database (SQLite)
  • Add DTC (trouble code) reading & clearing
  • Consolidate OBD-v1.pyOBD-v6.py into a single, documented entry point

Want to help with any of these? Check out CONTRIBUTING.md — there are good-first-issue ideas ready to go.


🤝 Contributing

Contributions are welcome! See CONTRIBUTING.md for setup instructions, how to test without a car using OBD-mock.py, and a list of good first issues.


📄 License

This project is licensed under the MIT License.


🌐 Author

Qasim Ali Ghumman Portfolio · LinkedIn · contactqaxim@gmail.com

About

Python tool that connects to a car's OBD-II port via an ELM327 adapter to read real-time diagnostics — speed, RPM, coolant temp, fuel level, and more.

Topics

Resources

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages