Linux tip, Fedora tip / howto: setting up an OBD2 Bluetooth adapter |
Try my online puzzle page with Calcudoku, Killer Sudoku and online Sudoku.
setting up an OBD2 Bluetooth adapter My car was behaving a bit more sluggishly than I expected, so I decided to investigate. The goal was to plug an OBD2 bluetooth adapter into the OBD2 port of my car (a 2004 Opel/Vauxhall Astra 1.6) and make it talk to an Acer Aspire One laptop running Linux (CentOS 6.3).The end goal is to get graphs like this one (click on it for a larger version): We'll work our way from the car "upwards":
1. The carMost recent cars will have an OBD2 connector. Here's what it looks like on my car: Check your service manual or look online to find the location of the connector in your car. In my case I had to use a flat head screwdriver to flip open a panel below the handbrake to expose the connector. 2. The OBD2 bluetooth adapterThere are very many of these. If you're looking to use one of the several iPad apps for connecting to your car, you may want to look into a Wifi OBD2 adapter instead.After browsing some reviews, I ended up getting this one: "Supper Mini Bluetooth Car Code Reader / ELM327 Power 2" (for £11.95). This is what it looks like (note the small bluetooth symbol after the "POWER2"): And this is what it looks like connected (the red light is always on): Note: just now I found that my car battery is dead, after not having used the car for a few days, and left the adapter in. I can't be sure it was the adapter that drained the battery (I won't leave it in anymore though). 3. Getting bluetooth to work on my Linux laptopMy very simple Acer Aspire One laptop (1GB memory, Intel Atom 1.6 GHz processor, running CentOS 6.3) does not have bluetooth, so I first had to get a USB bluetooth adapter. I bought this Belkin mini bluetooth adapter for about 13 pounds. Note that it works fine under Linux (the product page only mentions Windows). If you get a different/newer adapter, do verify that it works under Linux (often people mention this in product reviews).The adapter is tiny (those squares are 5mm x 5mm): After connecting it, lsusb shows this (the various numbers may be different for you): I had most success with the blueman bluetooth software. To install, run: The gnome bluetooth software only gave me trouble. You can ditch it by running (as root): Once installed, there should appear a small bluetooth icon in your panel (you can double check you're using the Blueman applet by selecting the "About" option). 4. Connecting to the bluetooth adapterGet into your car and turn the ignition key to "II" (or whatever setting powers the car without starting the engine).Turn on the laptop, and once started up and logged in, right-click the bluetooth icon in the panel and select "Setup new device...", then click the "Forward" button. In the dialog that appears next, a device "OBDII" should show up in the list. Select it, and then click "Forward". Next, select "Use Custom Passkey", and type "1234" as the key (this number may be different for your OBD2 adapter): Next, select "Serial Port": After that, you should get a confirmation like this: 5. Setting up software to read the OBD2 informationWhat we now need is a piece of software that supports the OBDII protocol and allows us to log the incoming values.I managed this with the "ScanTool" program, downloaded from the ScanTool.net downloads page. Get the scantool_net121src.zip source archive. There may be other, better solutions by now (send me a note using the form below if you know of one :-). For example, freediag looks interesting. Create a directory for it, and unzip the source: Some changes need to be made to the makefile and source code:
In the file globals.h, uncomment line 9: I fixed a bug in the logging code in main.c, and added the logging of timestamps. Download a copy of the updated main.c. The file serial.c must be changed so it uses termios: there's a patch for this on the ubuntu forums. Alternatively, download an already patched version of serial.c. Now you should be good to compile, so run make (send me a note if you get any compilation errors). 6. Running ScanToolBecause ScanTool expects to read its serial data from /dev/ttyS3, and the bluetooth software created a serial device /dev/rfcomm0, we should first point one to the other. As root, do:cd /dev rm -f ttyS3 ln -s rfcomm0 ttyS3 chmod 766 rfcomm0 When you run ScanTool, it'll show you a warning (just click "CONTINUE"): Next, click "Sensor Data" to see screens like this one (as you can see from the numbers, I didn't start the engine yet): 7. Processing logged dataScanTool logs to a file comm_log.txt. With my timestamp update, log lines now look like this: [Sat Feb 14 21:54:29 2015][TX]010D[/TX] You can see the incoming data rate is about 2 pieces of information a second. You can set which data ScanTool should query, so bear in mind that if you're reading a lot of them, the resulting resolution will not be great (conversely, if you'd like to log the engine RPM twice a second, for example, enable the reading of that sensor only). I wrote a small Perl script: process_comm_log.pl that converts the logfile to a data file that gnuplot can use.
|
Send me your comments!
Something didn't work as expected? You'd like to add some useful info to this tip? Use the form below to send me your comments. (Don't forget to fill out the super-lame CAPTCHA below..)