Pi on a roll: Using a Raspberry Pi to read car sensors

Project objective

The Raspberry Pi is a very small but complete Linux system, so I’d like to see how I can use it in my car for functions such as diagnostics, navigation, dashcam and reverse cam, entertainment system, and more.

Resources

https://lists.gt.net/gentoo/user/286532 (BTctl cmds)

http://gersic.com/connecting-your-raspberry-pi-to-a-bluetooth-obd-ii-adapter/

http://www.cowfishstudios.com/blog/obd-pi-raspberry-pi-displaying-car-diagnostics-obd-ii-data-on-an-aftermarket-head-unit

https://www.raspberrypi.org/forums/viewtopic.php?p=947185#p947185 (SP profile)

https://raw.githubusercontent.com/mytrile/obd-trouble-codes/master/obd-trouble-codes.csv

http://pidashcam.blogspot.com/

https://python-obd.readthedocs.io/en/latest/

Required Parts

Raspberry Pi (any model will do, though you can only easily attach one USB device to the Zero/Zero W)

16 GB SD card (enough to hold lots of log data)

ELM327 USB OBD-II interface (such as a ScanTool OBDLink SX)

Mobile USB charger

Optional Parts

Pi TFT display (* if you want to see OBD-II stats without a mobile/tablet/computer)

PiNoir camera module

Goliton Bluetooth OBD-II interface (* can replace USB interface)

USB backup battery with pass-through charging

USB GPS, such as the u-Blox

Build notes: Reading and displaying On-Board Diagnostics (OBD-II)

Cars generate a lot of sensor and diagnostic data across their internal “Controller Area Network” (CANBUS), but the end user only sees a few of these such as speed, RPM, coolant temperature, fuel level, usually in analog format and sometimes just as a single colored light.  Further, diagnostics are distilled down to a single Malfunction Indicator Lamp or “MIL” that usually reads “Check Engine” or just shows an engine icon.  There’s a lot more going on in there though!

We can use the OBDLink to poll the car’s sensors and use a Python script to output the readings to a file.  The GitHub page below hosts the Python script as well as a service that can auto-start the script when the Pi starts:

https://github.com/bryanherger/obd-json-logger

The Python script reads all available sensors and outputs this as a JSON record with timestamp.  You can then pull in the JSON into an analytic engine like Vertica to profile and analyze the sensor readings.