Robert Cobden


Graduate programmer and aspiring game developer

RasPi-CarSpy Update #1

Written by Robert Cobden | 20th Aug, 2016

I love data. There are many hidden trends in the world that can be discovered through the analysis of data, and after seeing projects such as OBD GPS Logger, I got inspired.

The initial goal of this project is to set up a monitoring system in my car that automatically starts up and powers down (with the engine) and records all available engine diagnostics data. Future extensions may include adding a GPS module to simultaneously record location data and also to automate the uploading of recorded data to a database (when within range of saved wifi networks).

After doing some shopping, my initial parts list was as follows:

  • 1 x Raspberry Pi
  • 1 x OBD-II to usb adaptor
  • 1 x Wireless usb adaptor
  • 1 x Large USB Battery Pack
    (I chose to use a battery pack in order to test the concept before wiring into my car battery)

Step 1 - Install Raspbian

I chose to use Raspbian Jessie Lite as my Pi's OS because I'm not overly adept at using linux and while minimalist, it requires little setup. Download links found here: Raspbian.

Step 2 - Connect to my home WiFi network

For this step it was necessary for me to use a display with the Pi, as I couldn't connect remotely. So with a spare HDMI cable and my old flexible keyboard (which I only use on occasions such as this), I modified the wpa_supplicant.conf file and added an entry:

network={
    ssid="MyHomeNetwork"
    psk="password123"
    id_str="home"
}

After automatically connecting to the network, all future communication with my Pi was done through SSH.

Step 3 - Install Python & Libs

As I was not sure what language to use for this project, I decided to look at the available libraries for interfacing with OBD-II devices and I quickly found this: https://pypi.python.org/pypi/obd.
A clean, simple, and well written library for python. After a quick
apt-get install python3
and a
pip install obd
I was ready to go.

Step 4 - Get Programming

My first program's purpose was to test the functionality of the library and OBD-II cable I had purchased. It simply read the current RPM of the engine and printed it as output to the console, the code for this can be seen below.

import obd

connection = obd.OBD() # auto-connects to USB or RF port

cmd = obd.commands.RPM # selects an OBD command (sensor)

response = connection.query(cmd) # send the command, and parses the response

print(response) # returns values and their units

Next Update:

Asynchronous recording and logging to file.


Comments