loading

In this instructable you will learn how to connect your Raspberry Pi to a Bluetooth OBD-II adapter and display realtime engine data to your cars aftermarket head unit!

Step 1: Hardware Required:

  1. Raspberry Pi Model B or B+
  2. Aftermarket head unit (Note: Must support Auxiliary input)

  3. Plugable USB Bluetooth 4.0 Low Energy Micro Adapter

  4. 2A Car Supply / Switch or Micro USB Car Charger

  5. ELM327 Bluetooth Adapter or ELM327 USB Cable

  6. RCA cable

  7. Keyboard (*optional)

Step 2: What Is OBD-II?

OBD stands for On-Board Diagnostics, and this standard connector has been mandated in the US since 1996. Now you can think of OBD-II as an on-board computer system that is responsible for monitoring your vehicle’s engine, transmission, and emissions control components.

Vehicles that comply with the OBD-II standards will have a data connector within about 2 feet of the steering wheel. The OBD connector is officially called a SAE J1962 Diagnostic Connector, but is also known by DLC, OBD Port, or OBD connector. It has positions for 16 pins, and looks like this:

Step 3: PyOBD?

pyOBD (aka pyOBD-II or pyOBD2) is an open source OBD-II (SAE-J1979) compliant scantool software written entirely in Python. It is designed to interface with low-cost ELM 32x OBD-II diagnostic interfaces such as ELM-USB. It will basically allow you to talk to your car's ECU, display fault codes, display measured values, read status tests, etc.

I took a fork of pyOBD’s software from their GitHub repository, https://github.com/peterh/pyobd, and used this as the basis for my program.

The program will connect through the OBD-II interface, display the gauges available dependent on the particular vehicle and display realtime engine data to the cars aftermarket head unit in an interactive GUI.

Step 4: Software Installation

Before you start you will need a working install of Raspbian with network access.

We'll be doing this from a console cable connection, but you can just as easily do it from the direct HDMI/TV console or by SSH'ing in. Whatever gets you to a shell will work!

Note: For the following command line instructions, do not type the '#', that is only to indicate that it is a command to enter.

Before proceeding, run:

#  sudo apt-get update
#  sudo apt-get upgrade
#  sudo apt-get autoremove
#  sudo reboot

Install these components using the command:

#  sudo apt-get install python-serial
#  sudo apt-get install bluetooth bluez-utils blueman
#  sudo apt-get install python-wxgtk2.8 python-wxtools wx2.8-i18n libwxgtk2.8-dev
#  sudo apt-get install git-core#  sudo reboot

Next, download the OBD-Pi Software direct from GitHub.

(https://github.com/Pbartek/pyobd-pi.git)

Or using the command:

#  cd ~
#  git clone https://github.com/Pbartek/pyobd-pi.git

Step 5: Vehicle Installation

The vehicle installation is quite simple.

1. Insert the USB Bluetooth dongle into the Raspberry Pi along with the SD card.

2. Insert the OBD-II Bluetooth adapter into the SAE J196216 (OBD Port) connector.

3. Connect you RCA cable to the back of your aftermarket head unit and plug the other end into your Raspberry Pi.

4.Install your 2A Car Supply / Switch or Micro USB Car Charger.

5. Finally turn your key to the ON position and navigate your head unit to Auxiliary input.

6. Enter your login credentials and run:

# startx 

7. Launch BlueZ, the Bluetooth stack for Linux. Pair + Trust your ELM327 Bluetooth Adapter and Connect To: SPP Dev. You should see the Notification "Serial port connected to /dev/rfcomm0"

Note: Click the Bluetooth icon, bottom right (Desktop) to configure your device. Right click on your Bluetooth device to bring up Connect To: SPP Dev.

8. Open up Terminal and run:

# cd pyobd-pi

# sudo su

# python obd_gui.py

Use the Left and Right arrow keys to cycle through the gauge display.

To exit the program just press Control and C or Alt and Esc.

Step 6: Data Logging

If you would like to log your data run:

#  cd pyobd-pi
#  python obd_recorder.py

The logged data file will be saved under:

/home/username/pyobd-pi/log/


Enjoy and drive safe!

Step 7: Step by Step Video

<p>Great project CowFish, thanks for sharing. I was thinking about using the new Raspberry Pi Zero W instead, as it has build in bluetooth. I was looking around for other projects and fell over this <a href="https://www.autopi.io" rel="nofollow">https://www.autopi.io</a></p><p>It seems to do some of the same things. I will see if I can get the head unit or maybe a tablet. <br>Anyway, thank you :-)<br>Cheers<br><br></p>
<p>Can anyone explain how to establish a bluetooth connection to the obd adapter with pi3, it always raises the error, no service found for that device... . I asked in several forums but no luck.</p>
<p>Great tutorial, questions from a new guy; What is an aftermarket head unit and will it work with a PI3?</p>
<p>Thank you CowFish for sharing this!</p><p>But I run into problem <br>when I tried to run obd_gui.py from my laptop I get an strange atz <br>response and at the end an error, please see the pictures. And then I tried to run from my raspberry and get bit different results first get message 'Get nothing' few times and then same error. Any idea how can I fix this?</p>
<p>Great project <a href="https://www.instructables.com/member/CowFish/" rel="nofollow">CowFish</a> .. <br><br>Thanks for posting such a detailed tutorial. Have forked pyobd-pi and works a treat with a USB OBD reader and an Ubuntu laptop. <br><br>We are looking to port this to Kivy which we already have some animated RPM, Temp gauges ect developed.<br><br>Happy to send through the repo once done :)</p>
<p>Morning campervancoder,</p><p>Sounds like an awesome project, can't wait to see it up and running!</p><p>Cheers!</p>
<p>Quick update on the Kivy port .. We now have the ECU telemetry being displayed on our beta rev gauge.. <br><br>We will publish the codebase on github once we have cleaned it up and added some exception handling for the OBD connection (Which does not always connect first time :) ..)<br><iframe allowfullscreen="" frameborder="0" height="281" src="//www.youtube.com/embed/UuviKGKJdLQ . The codebase will be published on github once we have cleaned it up.. " width="500"></iframe><br>Thanks again to <a href="https://www.instructables.com/member/CowFish/" rel="nofollow">CowFish</a> for the great work. </p>
<p>Issue with embedded link please go to https: //youtu.be/UuviKGKJdLQ</p>
hello cowfish or any1 who can help<br>I am unable to connect my bluetooth obd to the Serial Port i dont seem to have the option to connect as mentioned in the instructions. Also the bluetooth package mentioned in the instructions have been replaced. So i instead of bluez-utils i just installed bluez. Could this be the reason for my problems? <br>thanks u
<p>Any solution yet. I was facing the same problem. The thing is that the old bluez-util is discontinued and is replaced by &quot;bluez5.0&quot; which is supposedly causing this problem. I tried recompiling the old Bluetooth utility but due to lack of time was not able to fully operate it. If you have found any solution, please post me about it.</p><p>Thanks!</p>
<p>Which make / model head unit did you use for this? </p>
It's stuck on &quot;trying to connect...&quot; Do you know how to fix this?
r u having trouble connecting the bluetooth obd to the pi? If so, I am having the same issue. Maybe we can help eachother out. I cant connect the OBD to a serial port.
<p>Very good!!! </p><p>Does it work without X and GUI? </p><p>I`m interested in elm327 &lt;-&gt; bluetooth &lt;-&gt; virtual serial port channel?</p>
<p>Thanks for reaching out! I actually have a non GUI version which outputs via terminal. If you are interested in this version please let me know! I will be more than happy to post it on my Github page ;) </p>
<p>Nice work Cowfish, I am eagerly looking for the non GUI version to get the output through terminal. could you please give the link for the code page??!</p>
<p>Nice work Cowfish, I am eagerly looking for the non GUI version to get the output through terminal. could you please give the link for the code page??!</p>
<p>Hi CowFish, I'm working on a C++ RPi project and I need to send some variables to my application like rpm and load. I would love to get an non-GUI version if you don't mind.</p><p>I would be very thankful.</p><p>Here is my email rdbg.03(at)gmail(dot)com</p>
<p>I'd be very interested in a non-GUI version (as well as the GUI version). I would love to be able to ssh into my Pi and get readings from the car in the driveway :)<br><br>I'm also having trouble with using the desktop bluetooth manager to connect-the icon is there but the GUI never shows up when I click on it. Any idea why that might be? I'm considering just getting a USB OBDII connector to avoid that particular hurdle...</p>
<p>I want to manage my Raspberry Pi using the buttons on the steering wheel. I hope your utility can help me identify the button codes. And to learn how it works =).</p>
<p>Great instructable. I'm confused on how you're interfacing the touch display on your Alpine with the Pi. I have a Jensen, and it supports AUX Video input, but how do you interface the touch?</p>
<p>I am having some trouble, </p><p>I type the command </p><p>sudo apt-get install git-core which works fine</p><p>then i type sudo reboot and the pi starts to reboot but when it boots back on there is just a black screen with one blinking underscore, I cant type anything or get anywhere at this point</p>
<p> sudo apt-get install python-wxgtk2.8 python-wxtools wx2.8-i18n libwxgtk2.8-dev</p><p>is this the install request line if we choose to use the hardwired OBDII snesor instead of the BT OBDII?</p>
<p>Great Work, and Great Project. I am new to the RPi but i am going to give this project a try because I would like to track my vehicles Performance.</p>
<p>Hi,</p><p>i have worked my way through the tutorial today and it worked really well. I have combined the Rasperry Pi with the new Rasperry touch screen and I am looking forward to finish a contineous installation. I think it will be a great asset to my car.</p><p>Thanks a lot for the instructable!</p>
<p>Hi lesincostan,</p><p><br>No problem, love your setup!</p><p><br>Cheers,</p>
<p>Hi,</p><p>I too have worked my way through the tut. But I however am having an issue I'm hoping you can help with. I am by no means a programmer so coding and figuring out what errors mean is something I am incapable of dealing with.here is what I'm using: </p><p>RPi 2</p><p>CSR V4.0 Bluetooth adapter</p><p>Raspbian wheezy</p><p>Here is the error:</p><p>pi@raspberrypi ~/pyobd-pi $ python obd_gui.py</p><p>(python:2639): GLib-GObject-WARNING **: Attempt to add property GtkSettings::gtk-button-images after class was initialised</p><p>(python:2639): GLib-GObject-WARNING **: Attempt to add property GtkSettings::gtk-scrolled-window-placement after class was initialised</p><p>(python:2639): GLib-GObject-WARNING **: Attempt to add property GtkSettings::gtk-label-select-on-focus after class was initialised</p><p>['/dev/rfcomm0']</p><p>Opening interface (serial port)</p><p>Interface successfully /dev/rfcomm0 opened</p><p>Connecting to ECU...</p><p>atz response:ELM327 v2.1</p><p>ate0 response:OK</p><p>0100 response:SEARCHING...UNABLE TO CONNECT</p><p>Connected to /dev/rfcomm0</p><p>Traceback (most recent call last):</p><p> File &quot;obd_gui.py&quot;, line 394, in connect</p><p> self.textCtrl.AddText(str(self.c.get_output()))</p><p> File &quot;obd_gui.py&quot;, line 50, in get_output</p><p> return self.c.capture_data()</p><p> File &quot;/home/pi/pyobd-pi/obd_capture.py&quot;, line 44, in capture_data</p><p> self.supp = self.port.sensor(0)[1]</p><p> File &quot;/home/pi/pyobd-pi/obd_io.py&quot;, line 226, in sensor</p><p> r = self.get_sensor_value(sensor)</p><p> File &quot;/home/pi/pyobd-pi/obd_io.py&quot;, line 215, in get_sensor_value</p><p> data = sensor.value(data)</p><p> File &quot;/home/pi/pyobd-pi/obd_sensors.py&quot;, line 112, in hex_to_bitstring</p><p> v = eval(&quot;0x%s&quot; % i)</p><p> File &quot;&lt;string&gt;&quot;, line 1</p><p> 0xH</p><p> ^</p><p>SyntaxError: invalid token</p><div>Thanks for any help you can give</div>
<p>Good Morning.</p><p>I have been working on this instructable, but have ran into a snag. I have a TAXO USB 2.5 OBD cable I got for my car to reprogram a couple of keys for it. </p><p>I can't seem to get this cable to work with the Pi. Is this due to the cable? Here is an amazon link of what I have, and it really only talks about the Volkswagen card, not more generic OBD data collection.</p><p><a href="http://www.amazon.com/OBD2-TACHO-TAXO-Diagnostic-Tacho2-5/dp/B00EPFBNSY" rel="nofollow">http://www.amazon.com/OBD2-TACHO-TAXO-Diagnostic-T...</a></p><p>Would the python script automatically detect a usb cable plugged into the Pi and initialize if it was working? I don't have a bluetooth one yet. I have ordered one, but it isn't here yet.</p>
<p>Hi I have been trying to get this working on my RPi2 but have issues with the USB serial port i have a UART GPS connected to the GPIO pins and when i connect my usb obdii device the gps stops working if you have any ideas would be appreciated. I'm sure its not a power issue i have a 5Amp 5V power supply connected to the powered USB hub and have set USB_MAX_CURRENT=1 on the Pi</p>
<p>Hello CowFish, first of all congrats for your Instructable. </p><p>I'm writing you because I'm having problems lauching the obd_gui.py. The system keeps saying there's an error with the Import wx , line 11, &quot;modules&quot;. </p><p>Can you enlighten me on this ? Is there anything I can do to repair the installation or make it to work ? </p>
<p>I have a OBD-II wifi adapter, would the setup be similar?</p>
<p>Hello Dplus12,</p><p>To answer your question yes! You will need to modify file &quot;obd_utils.py&quot;.</p><p>Cheers!</p>
<p>Hi CowFish can you please help me to configure my obd_utils.py for wifi connection?</p>
<p>Hey,</p><p>I want to log the data using obd_recorder.py. But is it printing &quot;logging items&quot; and then &quot;not connected&quot;. What may be the problem? Can you please help asap.</p><p>Ps: i am able to get real time data by obd_gui.py</p>
<p>*using bluetooth adapter.</p>
<p>Good idea!!</p>
<p>Awesome... i do it in my CarPC proyect and this is so interesting</p>
<p>Hi! Thanks so much for this great Instuctable with clear steps; however, I am having some issues. </p><p>I can get the RPi to connect to the Bluetooth ODBII adapter and the Bluetooth on the RPi says it's connected on the serial port, but the gui is displaying what is attached (images). </p><p>Any suggestions on what the problem may be? </p><p>Thanks again. This is actually my first project with the RPi, however I would consider myself quite well versed in Linux. </p>
<p>UPDATE: I got it to work. I edited obd_capture.py and changed &quot;len(self.supp)&quot; to &quot;32&quot; on line 50. </p>
Hi CowFish! Really amazing project! I cant find the obd_utils.py for the wifi adapter. Would you please help me?
<p>It is located on the RPi in /home/(username)/pyobd-pi/</p><p>You can either use the file viewer in x, or you can use the terminal. Since my username is 'pi', I can run &quot;nano /home/pi/pyobd-pi/obd_utils.py&quot; to edit it. </p>
Great project, I am going to do a similar project this summer! Just a note for the Linux side of things: the # is typically used to denote a command run as root, and the $ is used for non-root user. e.g. # apt-get update<br>is just a simpler way of saying $ sudo apt-get update.
<p>I was just thinking about this last week! I even ordered a Bluetooth OBDII device on Friday! I was going to use that really popular mini screen for a backup camera, so looks like I'm sticking that and this together! Maybe I'll learn to make a basic GUI in python and make the pi switch to its camera when backing up.</p>
<p>Sounds like a great project! Good luck :)</p>
<p>Just curious, what's the difference between OBD and CAN bus?</p>
<p>Hey Cat,</p><p>I actually wrote a lecture / tutorial discussing CAN and OBD-II. Please see the link below: </p><p><a href="http://www.cowfishstudios.com/blog/canned-pi-part1" rel="nofollow">http://www.cowfishstudios.com/blog/canned-pi-part1</a></p><p>Cheers,</p>
<p>Awesome! Thanks :)</p>
<p>No problem, happy to help!</p>
<p>Great instructable! I've been wanting to do something like this for a while. could you also just connect the pi to any screen with an rca port? </p>
<p>Hey dstech,</p><p>To answer your question yes, HDMI or RCA will work!</p><p>Cheers,</p>

About This Instructable

235,403views

1,421favorites

License:

More by CowFish:OBD-Pi 
Add instructable to: