Are you a car enthusiast or a DIY mechanic looking to delve into the diagnostics of your vehicle using Linux? Connecting an OBD2 Bluetooth adapter to a Linux-based laptop is a powerful and cost-effective way to access real-time data from your car’s computer. This guide will walk you through the process of setting up a Linux Obd2 Bluetooth connection, enabling you to monitor performance, diagnose issues, and gain a deeper understanding of your vehicle’s inner workings.
Originally, I set out to investigate why my car felt a bit sluggish. My goal was to establish communication between an OBD2 Bluetooth adapter and my Acer Aspire One laptop running CentOS 6.3. The ultimate aim was to visualize vehicle data in graphs, similar to this:
Let’s break down the setup process step-by-step, starting from your car and moving towards your Linux system.
1. Identifying the OBD2 Port in Your Car
Nearly all modern vehicles are equipped with an OBD2 (On-Board Diagnostics II) port. This standardized port allows access to your car’s diagnostic system. The appearance and location of this port can vary slightly depending on your car’s make and model.
On my 2004 Opel/Vauxhall Astra 1.6, the OBD2 port looks like this:
To locate the OBD2 port in your car, consult your vehicle’s service manual. Alternatively, a quick online search for “[your car make and model] OBD2 port location” should provide the answer. In my Astra, the port was hidden behind a small panel beneath the handbrake, which I gently pried open using a flat-head screwdriver.
2. Choosing the Right OBD2 Bluetooth Adapter
The market offers a plethora of OBD2 Bluetooth adapters. If you intend to use iOS-based apps with your adapter, you should consider a Wifi OBD2 adapter instead, as iOS devices generally have limited Bluetooth OBD2 support.
After reading numerous reviews and considering compatibility with Linux, I opted for the “Supper Mini Bluetooth Car Code Reader / ELM327 Power 2”, available on platforms like Amazon.
This compact adapter features a Bluetooth symbol after “POWER2” indicating its Bluetooth capability. When connected to the OBD2 port, it looks like this, with a constant red LED illuminated:
Important Note: I experienced a dead car battery after leaving the adapter plugged in for a few days without using the car. While I cannot definitively confirm the adapter as the cause, it’s prudent to unplug the adapter when the car is not in use to prevent potential battery drain.
3. Enabling Bluetooth on Your Linux Laptop
My Acer Aspire One, a basic laptop model, lacked built-in Bluetooth. Therefore, I needed to add Bluetooth functionality using a USB adapter. I chose the Belkin mini Bluetooth adapter, readily available online.
While the product page may primarily mention Windows compatibility, this adapter works seamlessly with Linux. If you opt for a different or newer adapter, it’s crucial to verify Linux compatibility, often found in user reviews or product descriptions.
After plugging in the adapter, the lsusb
command should recognize it. The output will be similar to: Bus 002 Device 009: ID 050d:016a Belkin Components Bluetooth Mini Dongle
(device numbers may vary).
For Bluetooth management software on Linux, I found Blueman to be the most reliable. Install it using your distribution’s package manager. For Debian/Ubuntu-based systems, use sudo apt-get install blueman
. For Red Hat/CentOS based systems like mine, use yum install blueman
as root.
While Gnome Bluetooth is another option, I encountered issues with it and recommend removing it if you experience conflicts with Blueman. You can remove Gnome Bluetooth using rpm -e gnome-bluetooth gnome-bluetooth-libs --nodeps
on RPM-based systems.
Once Blueman is installed, a Bluetooth icon will appear in your system panel. You can confirm you’re using Blueman by checking the “About” section in the Bluetooth icon’s context menu.
4. Pairing Your Linux Laptop with the OBD2 Bluetooth Adapter
With the Bluetooth adapter installed and Blueman running, you’re ready to pair with your OBD2 adapter.
-
Prepare your car: Turn your car’s ignition to the “II” position (or the position that powers the car’s electronics without starting the engine). This activates the OBD2 port.
-
Initiate pairing: On your Linux laptop, right-click the Blueman Bluetooth icon in the system panel and select “Setup new device…”. Click “Forward”.
-
Device discovery: Blueman will scan for nearby Bluetooth devices. The “OBDII” device should appear in the list. Select it and click “Forward”.
-
Passkey entry: Choose “Use Custom Passkey” and enter “1234” as the passkey. This is a common passkey for OBD2 adapters, but yours might be different – check your adapter’s documentation if pairing fails.
-
Service selection: Select “Serial Port” as the service for the connection.
-
Confirmation: Upon successful pairing, you should see a confirmation message indicating the connection is established.
5. Software Setup for Reading OBD2 Data on Linux
With the Bluetooth connection established, you need software to interpret the OBD2 data stream. I used ScanTool, a program available for download from the ScanTool.net downloads page. Obtain the scantool_net121src.zip
source archive.
While ScanTool worked for me, there might be more advanced or user-friendly OBD2 software options available now. FreeDiag is another open-source project worth exploring.
To set up ScanTool:
-
Create directory and extract source:
mkdir scantool mv scantool_net121src.zip scantool cd scantool unzip scantool_net121src.zip
(If
unzip
is not installed, install it using your package manager, e.g.,yum install unzip
orapt-get install unzip
). -
Modify Makefile: The
Makefile
requires adjustments for Linux compatibility:- Replace
AL_LIBS = -lalleg
withAL_LIBS =
allegro-config –libs`in two locations. (You might need to install Allegro library and development files:
yum install allegro allegro-develor
apt-get install liballegro4-dev`). - Add
DEFINES += -DTERMIOS
beforeifdef MINGDIR
(around line 17). - Change
LIBS = -ldzcom $(AL_LIBS)
toLIBS = $(AL_LIBS)
(line 29). - Change
BIN = ScanTool.exe
toBIN = ScanTool
(line 43).
You can download a pre-modified Makefile.
- Replace
-
Enable serial communication logging: In
globals.h
, uncomment line 9://#define LOG_COMMS // Uncomment this line to enable serial comm logging
. -
Apply timestamp and logging bug fixes: I’ve made minor updates to
main.c
for timestamp logging and bug fixes. Download the updated main.c. -
Patch serial.c for termios: The original
serial.c
needs to be patched to usetermios
for serial communication on Linux. A patch is available on the Ubuntu forums or you can download a pre-patched serial.c. -
Compile ScanTool: Run
make
in thescantool
directory. If you encounter compilation errors, double-check the Makefile modifications and installed dependencies.
6. Running ScanTool and Accessing OBD2 Data
ScanTool is configured to read serial data from /dev/ttyS3
, but Blueman creates a serial device at /dev/rfcomm0
. To bridge this gap, create a symbolic link:
cd /dev
sudo rm -f ttyS3
sudo ln -s rfcomm0 ttyS3
sudo chmod 766 rfcomm0
Now, run ScanTool by executing the compiled binary: ./ScanTool
in the scantool
directory.
You might see a warning message upon startup – simply click “CONTINUE”.
To view real-time sensor data, click “Sensor Data”. You should see screens displaying various parameters like engine temperature, RPM, and more. Initially, without the engine running, values might be zero or static.
7. Analyzing Logged OBD2 Data
ScanTool logs data to a file named comm_log.txt
. With the timestamp modification, each log line includes a timestamp, like this example:
[Sat Feb 14 21:54:29 2015][TX]010D[/TX] [Sat Feb 14 21:54:29 2015][RX]41 0D 00 >[/RX] [Sat Feb 14 21:54:29 2015][TX]0104[/TX] [Sat Feb 14 21:54:30 2015][RX]41 04 00 >[/RX] [Sat Feb 14 21:54:30 2015][TX]010B[/TX] [Sat Feb 14 21:54:30 2015][RX]41 0B 65 >[/RX] [Sat Feb 14 21:54:30 2015][TX]0110[/TX] [Sat Feb 14 21:54:31 2015][RX]41 10 00 00 >[/RX]
The data logging rate is approximately two data points per second. The number of sensors you choose to monitor affects this rate. Selecting fewer sensors will result in a higher sampling rate for the selected data.
To process this log data and create graphs, I developed a Perl script, process_comm_log.pl
. You’ll need to adjust the date format regular expression on line 16 of the script. Run it with: process_comm_log.pl comm_log.txt
to generate trip.dat
, a data file suitable for Gnuplot.
Download the Perl script: process_comm_log.pl
Finally, use Gnuplot and the provided trip.gp
script to generate graphs. Download the Gnuplot script: trip.gp. Execute it with gnuplot trip.gp
. This will produce trip.png
, the graph image similar to the one shown at the beginning of this article, visualizing your car’s data.
This comprehensive guide should equip you to set up linux obd2 bluetooth diagnostics for your car. Explore the data, experiment with different sensors, and unlock valuable insights into your vehicle’s performance.