OBD-Pi

301,193

1,485

83

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

    • Audio Contest 2018

      Audio Contest 2018
    • Electronics Tips & Tricks Challenge

      Electronics Tips & Tricks Challenge
    • Plastics Contest

      Plastics Contest

    83 Discussions

    0
    None
    DavidH1076

    7 weeks ago

    I Have

    https://www.amazon.com/dp/B01C6CZ0SQ/ref=sspa_dk_...

    This OBDII module, and a Raspiberry Pi 3B+ Bluetooth connection no
    problem, rfcomm bind 0 00:1D:A5:68:98:8C also no problem, start the
    app, continue to get the following error :

    read failed: device reports readiness to read but returned no data
    (device disconnected)

    Any help would be great please.

    0
    None
    KeithP78

    2 months ago

    If you purchased an OBDII Wifi only dongle ELM327 and want to make this work, I found a way.

    apt install socat

    Had to make a virtual serial port ttyUSB0 with socat on raspbian stretch.

    socat pty,link=/dev/ttyUSB0,waitslave tcp:192.168.0.10:35000&

    python obd_gui.py

    The script came up and displayed the data on the screen.

    0
    None
    AnandM12

    2 months ago on Step 5

    The actual article was written 4 yrs ago (6/25/2014). Lot of things have changed since then, esp bluetooth connection. Bluez doesn't work anymore and the Bluetooth GUI is different now. There is no option to trust a device and no option to Connect to SPP Dev. I'm struck in that part.

    After some googling and trying out, I think I now have connected the bluetooth to the serial port. It says "Connected /dev/rfcomm0 to xx:xx:....:xx on channel 1"
    But still when I run the program, it says "trying to connect" and then the screen goes blank. I'm not sure what is the issue
    I run an app in my phone, connected to the OBD device and I'm able to view the data.

    0
    None
    qqmajikpp

    3 months ago

    Did this in my RAV4. Expect a USB scantool today. Hopefully its faster and more reliable than the BT scantool. Exploring adding more PIDs. Very exciting stuff. Thanx for sharing.

    1 reply
    0
    None
    EricH307

    Question 7 months ago on Introduction

    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

    0
    None
    MordechaiF

    8 months ago

    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
    0
    None
    supawiz6991MordechaiF

    Reply 8 months ago

    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.

    0
    None
    Pavankumar33

    Question 8 months ago on Step 1

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

    0
    None
    MariusV26

    1 year ago

    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
    0
    None
    JeffA110MariusV26

    Reply 10 months ago

    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.

    0
    None
    dconsuegra

    10 months ago

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

    0
    None
    michaelpko

    1 year ago

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

    0
    None
    alphazero1990

    1 year ago

    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.

    0
    None
    TimoR13

    1 year ago

    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
    0
    None
    RuzroxTimoR13

    Reply 1 year ago

    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

    0
    None

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

    0
    None
    pippo92CowFish

    Reply 1 year ago

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

    0
    None
    PrasanthR1CowFish

    Reply 2 years ago

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