OBD-Pi

289,191

1,474

76

Published

Introduction: OBD-Pi

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

Share

    Recommendations

    • Woodworking Contest

      Woodworking Contest
    • Make it Move Contest

      Make it Move Contest
    • Casting Contest

      Casting Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    2 Questions

    great project Where can I get an aftermarket head unit? My car is old, a 2000 SAAB

    or can I use a laptop in lieu of the head unit?

    thanks for a great start on OBD-II

    Can we add other functionality along with diagnostics to the Raspberry pi ?( viz. sensors)

    76 Comments

    Total Pi noob here... I followed your instructions and can't get the piobd-py.git part to work for me. It does nothing when I type that line in. I tried the link which sent me to github, and searched not knowing wth to do there. I'm sure it's on my end, the knowledge part. This is all experimental for me, I can already do this and more with my phone, like checking the other modules, airbag, ABS, etc.. There's also a wall I'd like to breakthrough here, the one between car types and computer types. I'd eventually like to run my car reliably on a PI or a stack if need be. I'd be impressed if the stock ecu runs at 20mhz. Anywho, step 1 is getting this to work.

    1 reply

    I assume your talking about
    git clone https://github.com/Pbartek/pyobd-pi.git

    There should be some output from running that command

    when you type git clone does it tell you command not found? If so, run the command sudo apt-get install git (this will install git) and then try again.

    Are you getting a permissions error? add sudo before git clone -or- run the command on a directory that you have permission to write in.

    When you run this command successfully, it should create a directory and download all of the files from the repository into it.

    Hi. Thank you for sharing this great project! But I have one question about fuel level is "fuel system stat" means fuel level (because I getting 0100 all the time and S-T and L-T fuel trim at 0)?

    1 reply

    ST and LT are short term and long term fuel trim. That has nothing to do with how full your gas tank is. It’s a measurement on if your engine is running lean or rich. If they are both running at 0 that’s perfect for your engine.

    Can you update the instructions using a RPi3 or Zero W? Thanks!

    Hi install and bt connection all good however I get a blank screen and this:

    ['/dev/rfcomm0']

    Opening interface (serial port)

    Interface successfully /dev/rfcomm0 opened

    Connecting to ECU...

    atz response:ELM327 v2.1

    Got nothing

    Got nothing

    Got nothing

    Got nothing

    Got nothing

    ate0 response:ate0

    0100 response:0100NO DATA

    Connected to /dev/rfcomm0

    Any suggestions??

    I have used this for a month now it works good. Just a few problems. The numbers are refresing only every second if not longer. Is this a limitation on my ELM327 USB Cable?? But i have the exact same as on the link. Or is this how the cars ECU outputs.

    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.

    1 reply

    I had the same problem,bought a usb bluetooth on amazon and started researching on forums,to be honest i don't know what worked as i tryed too many thing at the same time,i thing everything revolves around bluez.i know it doesn't help but it is possible to make it work

    Very good!!!

    Does it work without X and GUI?

    I`m interested in elm327 <-> bluetooth <-> virtual serial port channel?

    7 replies

    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 ;)

    which file in your Github page is non GUI version? obd_capture? I ask you this because that file doesn't return anything in console. Thanks for the attention :)

    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??!

    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??!

    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.

    I would be very thankful.

    Here is my email rdbg.03(at)gmail(dot)com

    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 :)

    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...

    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 =).

    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 https://www.autopi.io

    It seems to do some of the same things. I will see if I can get the head unit or maybe a tablet.
    Anyway, thank you :-)
    Cheers

    Great tutorial, questions from a new guy; What is an aftermarket head unit and will it work with a PI3?

    Great project CowFish ..

    Thanks for posting such a detailed tutorial. Have forked pyobd-pi and works a treat with a USB OBD reader and an Ubuntu laptop.

    We are looking to port this to Kivy which we already have some animated RPM, Temp gauges ect developed.

    Happy to send through the repo once done :)