Skip to content

OBD-II CAN Bus library for ESP32 using the built-in TWAI controller (Arduino IDE compatible).

License

Notifications You must be signed in to change notification settings

muki01/OBD2_CAN_Bus_Library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OBD2 CanBus Library

GitHub forks GitHub Repo stars GitHub Issues or Pull Requests GitHub License GitHub last commit

OBD2_CanBus is a lightweight yet powerful ESP32 compatible library that enables direct communication with vehicles using the Can Bus.

This library is designed for microcontrollers such as ESP32, and similar platforms. It allows your device to communicate directly with a vehicle that uses the Can Bus.
If you're curious about which types of data are supported, you can find a full list of features below.

You can also see my other car projects:

  1. Тhis project is for BMW with I/K bus system.
  2. Тhis project is for Cars with CAN Bus.
  3. Тhis project is for Cars with ISO9141 and ISO14230 protocols.
  4. Тhis is my OBD2 CAN Bus Communication Library for Arduino IDE.
  5. Тhis is my OBD2 K-Line Communication Library for Arduino IDE.

❓ Does Your Vehicle Support Can Bus?

Before using this library, it's important to confirm whether your vehicle supports the Can Bus protocol.

Can Bus vehicles typically have Pin 6 and Pin 14 on the OBD-II connector connected. If your vehicle’s OBD-II connector has Pins 7 connected, it uses the K-Line protocol instead of Can Bus.

Pin 6 and 14 (CAN bus): Your vehicle uses CAN — this library will work.
Pin 7 (K-Line): Your vehicle likely supports ISO 9141 or ISO 14230 (KWP2000) — consider a different library.

Example photos of OBD2 Connector

In the first image, the OBD2 socket includes pin 7, which indicates it operates using the K-Line protocol. In the second image, pins 6 and 14 are present, meaning it uses the CAN Bus protocol.


✨ Features

  • Supports 11BIT and 29BIT, 250KBPS and 500KBPS
  • Automatic protocol detection
  • Read real-time sensor values
  • Read and clear stored and pending DTCs
  • Retrieve vehicle info (VIN, calibration IDs, etc.)
  • Mode 06 support (on-board test results)
  • Debug output for easier development
  • Customizable delays and request intervals
  • Works with ESP32 and similar platforms

📡 Supported OBD-II Modes

Mode Description
01 Read current live data (sensor values)
02 Read freeze frame data
03 Read stored Diagnostic Trouble Codes (DTCs)
04 Clear DTCs and MIL reset
05 Oxygen sensor test results
06 On-board monitoring test results
07 Read pending Diagnostic Trouble Codes
09 Retrieve vehicle information (VIN, calibration)

📊 Typical Data Rates

Each protocol has its own timing characteristics, which affect how many responses you can expect per second when reading data from the ECU. The values below reflect actual performance measurements based on this library’s real-world testing.

Protocol Average Responses per Second
250KBPS Not Tested
500KBPS ~100 responses/sec

🔎 Note: Tese values represent average conditions based on real-world testing. The actual throughput can vary depending on the ECU’s internal processing time, the specific data being requested (e.g. PID type), and system latency.


🛠️ Schematics for Communication


☕ Support My Work

If you enjoy my projects and want to support me, you can do so through the links below:

Buy Me A Coffee PayPal GitHub Sponsors

📧 Contact: muksin.muksin04@gmail.com