Production-ready firmware for an OBD-II diagnostic dongle based on ESP32, enabling CAN bus communication with vehicles and supporting USB, WiFi, and Bluetooth connectivity.
- CAN Bus Communication: Full CAN 2.0A/2.0B support with configurable bit rates (125K, 250K, 500K, 1M bps)
- Multi-Transport Support:
- USB Serial (921600 baud)
- WiFi AP/Station mode
- Bluetooth Classic (SPP)
- High Performance: Handles 10,000+ CAN frames/second
- Reliable Operation: Watchdog protection, automatic recovery, overflow detection
- Persistent Configuration: NVS storage for settings
- OTA Updates: Over-the-air firmware updates via WiFi
- LED Indicators: Visual feedback for power, CAN activity, and connection status
- Microcontroller: ESP32 or ESP32-S3
- CAN Transceiver: MCP2562, TJA1050 (5V) or TCAN332 (3.3V)
- Power: 12V from OBD-II → Buck converter → 5V → 3.3V LDO
- Connectivity: USB Type-C, WiFi 802.11n, Bluetooth Classic/BLE
CAN Interface:
- TX: GPIO 4
- RX: GPIO 5
Status LEDs (optional):
- Power: GPIO 2
- CAN RX: GPIO 15
- CAN TX: GPIO 16
- Status: GPIO 17
OBD-II Connections:
- Pin 6: CAN-H
- Pin 14: CAN-L
- Pin 16: +12V
- Pin 4/5: Ground
-
ESP-IDF (v5.0 or later)
git clone --recursive https://github.com/espressif/esp-idf.git cd esp-idf ./install.sh esp32,esp32s3 source export.sh
-
PlatformIO (optional but recommended)
pip install platformio pio platform install espressif32
# Build for ESP32
pio run -e esp32
# Build for ESP32-S3
pio run -e esp32s3
# Build and upload
pio run -e esp32 -t upload
# Monitor serial output
pio device monitor# Configure
idf.py set-target esp32
# Build
idf.py build
# Flash
idf.py flash
# Monitor
idf.py monitor- Connect the ESP32 via USB
- Put into download mode (if needed - hold BOOT button while pressing RESET)
- Flash the firmware:
or
pio run -e esp32 -t upload
idf.py flash
On first boot, the dongle will:
- Initialize with default settings (500 kbps CAN, WiFi AP mode)
- Create WiFi Access Point:
OBD-Dongle-XXXX(password:12345678) - Start USB serial on UART0 at 921600 baud
- Enable Bluetooth with name
OBD-Dongle
- Connect to the serial port at 921600 baud, 8N1
- Use any serial terminal (PuTTY, screen, minicom)
- Connect to WiFi AP
OBD-Dongle-XXXX - Connect to IP
192.168.4.1:8080via TCP - Multiple clients supported (up to 4)
- Pair with
OBD-Dongle - Connect to SPP serial profile
- Send/receive data like serial
The dongle uses a binary protocol for frame exchange:
Standard Frame (11-bit ID):
[0xAA][ID_H][ID_L][DLC][FLAGS][DATA0-7][CHECKSUM]
Total: 15 bytes
Extended Frame (29-bit ID):
[0xAA][ID_3][ID_2][ID_1][ID_0][DLC][FLAGS][DATA0-7][CHECKSUM]
Total: 17 bytes
[0x55][CMD][LENGTH][PAYLOAD...]
| Command | Code | Description |
|---|---|---|
| Set CAN Bitrate | 0x01 | Change CAN bus speed |
| Get Status | 0x02 | Retrieve statistics |
| Reset Buffers | 0x03 | Clear RX/TX buffers |
| Set WiFi | 0x04 | Configure WiFi credentials |
| Factory Reset | 0x05 | Restore defaults |
| CAN Frame | 0x10 | Send CAN frame |
| Ping | 0xFE | Connection test |
| Pong | 0xFF | Ping response |
Send: [0x55][0x01][0x04][0x00][0x07][0xA1][0x20]
(start)(cmd)(len)(---500000 in Hz---)
Receive: [0x55][0x01][0x01][0x00]
(start)(cmd)(len)(success)
Runtime configuration via commands. Configuration is automatically saved to NVS and persists across reboots.
┌─────────────────────────────────────────┐
│ ESP32 Firmware │
├─────────────────────────────────────────┤
│ CAN Driver ◄──► Frame Buffer │
│ │ │ │
│ └──────┬───────┘ │
│ │ │
│ Transport Manager │
│ ├─────┼─────┐ │
│ │ │ │ │
│ USB WiFi Bluetooth │
│ │
│ Config · Logging · Watchdog · LEDs │
└─────────────────────────────────────────┘
Priority 10: CAN_RX_Task (Core 0)
Priority 8: CAN_TX_Task (Core 0)
Priority 5: Transport_TX (Core 1)
Priority 5: Transport_RX (Core 1)
Priority 3: Watchdog (Any core)
Priority 2: Diagnostics (Any core)
Priority 2: LEDs (Any core)
firmware/
├── platformio.ini # Build configuration
├── partitions.csv # Flash partitions (OTA support)
├── README.md # This file
├── include/
│ ├── pins.h # GPIO definitions
│ └── version.h # Firmware version
├── src/
│ ├── main.cpp # Application entry point
│ ├── config.h # Configuration interface
│ ├── can/
│ │ ├── can_driver.* # CAN peripheral driver
│ │ └── can_buffer.* # Frame buffering
│ ├── protocol/
│ │ ├── frame_handler.* # Protocol serialization
│ │ └── command_handler.* # Command processing
│ ├── transport/
│ │ ├── transport_manager.* # Transport coordination
│ │ ├── usb_transport.* # USB serial
│ │ ├── wifi_transport.* # WiFi TCP/UDP
│ │ └── bluetooth_transport.* # BT SPP
│ └── utils/
│ ├── config.* # NVS storage
│ ├── logging.* # Log configuration
│ ├── watchdog.* # Watchdog timer
│ └── leds.* # LED indicators
└── test/
├── test_main.cpp # Test runner
├── test_frame_handler.cpp
├── test_can_buffer.cpp
└── test_config.cpp
# Build tests
pio run -e esp32 -t buildfs
# Upload and run tests
pio test -e esp32
# Monitor test output
pio device monitor- CAN Frame Rate: 10,000+ frames/second
- Latency: <5ms from CAN RX to transport TX
- CPU Utilization: <50% under normal load
- Memory: <60% RAM utilization
- Power: <150mA @ 5V (active mode)
- Check power LED (GPIO 2 should be on)
- Verify OBD-II connection (pins 4,5,6,14,16)
- Check serial output for errors
- Try factory reset
- Verify CAN bitrate matches vehicle (usually 500 kbps)
- Check CAN-H and CAN-L connections
- Ensure vehicle is powered on
- Check for bus-off errors in status command
- Verify SSID and password
- Check WiFi mode (AP vs STA)
- Ensure not too far from dongle (AP mode)
- Check firewall settings (STA mode)
- Check CAN bus termination (120Ω)
- Verify transceiver power supply (5V or 3.3V)
- Check for loose connections
- Monitor overflow statistics
- Always disconnect from OBD-II when vehicle is off
- Do not operate while driving
- Ensure proper CAN bus termination
- Use only in authorized diagnostic scenarios
- Complies with ISO 11898-1:2015 (CAN 2.0)
- Complete CAN 2.0A/2.0B implementation
- USB, WiFi, and Bluetooth transports
- Binary protocol with checksum
- NVS configuration storage
- Watchdog protection
- LED status indicators
- OTA update support
- Comprehensive unit tests
Built with ESP-IDF framework by Espressif Systems.