0% found this document useful (0 votes)
49 views

Displaying Vehicle Information With Raspberry PI

This document describes an open source project called "OBD display" that uses a Raspberry Pi to interface with a vehicle's OBD-II port and display real-time vehicle data and diagnostic information. It extracts data like VIN, engine parameters, emissions readings, and fault codes via the CAN bus interface and makes it available through a web server and JSON API for mobile apps. The software is written in C, uses GTK+ for the GUI, and loads databases to convert codes and provide context for the retrieved vehicle data.

Uploaded by

Richard Mancilla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Displaying Vehicle Information With Raspberry PI

This document describes an open source project called "OBD display" that uses a Raspberry Pi to interface with a vehicle's OBD-II port and display real-time vehicle data and diagnostic information. It extracts data like VIN, engine parameters, emissions readings, and fault codes via the CAN bus interface and makes it available through a web server and JSON API for mobile apps. The software is written in C, uses GTK+ for the GUI, and loads databases to convert codes and provide context for the retrieved vehicle data.

Uploaded by

Richard Mancilla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Displaying vehicle information with Raspberry PI

Engineering

Introduction of the open source project “OBD display” for the world of
Internet-of-Things (IoT) including an app.

Figure 1: OBD display interfaces (Source: MHS-Elektronik)

V ia the OBD-II interface, measurement data (SID 01h),


vehicle information such as chassis number/vehicle
identification number (SID 09 h) and fault memory
configure and open CAN interface, forward received
CAN messages and send CAN messages (can_
device.c)
(diagnostic trouble codes, SID 03 h are queried via a 2. Monitor the connection and disconnection of the
CAN network. A list of all values that can be displayed is Tiny-CAN interface (can_dev_pnp.c)
shown in the appendix. A Tiny-CAN is used as an 3. Driver for the ISO-TP protocol (isotp.c), sending of
interface adapter from the CAN network to the USB single and segmented ISO-TP messages with data
network. By using a standard USB-CAN adapter, the flow control. Receive single and segmented ISO-TP
program can be used on any Linux PC. The software messages, including generated CAN messages for
is written in C. GTK+ is used as GUI (graphical user data flow control
interface). The graphic illustrates the functionality in a very 4. Establish OBD connection, read VIN and supported
simplified way. PIDs, cyclically read the life data and read the error
The program flow even more detailed: memory, errors are not deleted.
1. Load CAN API driver libmhstcan.so, query The vin_db.c module contains utility functions for
information about driver and Tiny-CAN hardware, breaking down the VIN in manufacturer, country, etc. The

34 CAN Newsletter 4/2019


Table: List of all values that can be displayed. The prerequisite, of course, is that the vehicle also provides the data. The
provided data is determined via supported PIDs

Value Mode PID Value Mode PID


Supported PIDs in the range 01 - 20 01h 00 h Oxygen sensor 7 01h 2Ah
Monitor status since DTCs cleared 01h 01h Oxygen sensor 8 01h 2Bh
Freeze DTC 01h 02h Commanded EGR 01h 2Ch
Fuel system status 01h 03h EGR error 01h 2Dh
Calculated engine load 01h 04h Commanded evaporative purge 01h 2Eh
Engine coolant temperature 01h 05h Fuel tank level input 01h 2Fh
Short term fuel trim Bank 1 01h 06 h Warm-ups since codes cleared 01h 30 h
Long term fuel trim Bank 1 01h 07h Distance traveled since codes cleared 01h 31h
Short term fuel trim Bank 2 01h 08h Evaporative system vapor pressure 01h 32h
Long term fuel trim Bank 2 01h 09h Absolute barometric pressure 01h 33h
Fuel pressure (gauge pressure) 01h 0Ah Oxygen sensor 1 01h 34h
Intake manifold absolute pressure 01h 0Bh Oxygen sensor 2 01h 35h
Engine RPM 01h 0Ch Oxygen sensor 3 01h 36 h
Vehicle speed 01h 0Dh Oxygen sensor 4 01h 37h
Timing advance 01h 0Eh Oxygen sensor 5 01h 38h
Intake air temperature 01h 0Fh Oxygen sensor 6 01h 39h
MAF air flow rate 01h 10 h Oxygen sensor 7 01h 3Ah
Throttle position 01h 11h Oxygen sensor 8 01h 3Bh
Commanded secondary air status 01h 12h Catalyst temperature, bank 1, sensor 1 01h 3Ch
Oxygen sensors present 01h 13h Catalyst temperature, bank 2, sensor 1 01h 3Dh
Oxygen sensor 1 01h 14h Catalyst temperature, bank 1, sensor 2 01h 3Eh
Oxygen sensor 2 01h 15h Catalyst temperature, bank 2, sensor 2 01h 3Fh
Oxygen sensor 3 01h 16 h Supported PIDs in the range 41 - 60 01h 40 h
Oxygen sensor 4 01h 17h Monitor status this drive cycle 01h 41h
Oxygen sensor 5 01h 18h Control module voltage 01h 42h
Oxygen sensor 6 01h 19h Absolute load value 01h 43h
Oxygen sensor 7 01h 1Ah Fuel-air commanded equivalence
01h 44h
Oxygen sensor 8 01h 1Bh ratio
Relative throttle position 01h 45h
OBD standards this vehicle conforms to 01h 1Ch
Ambient air temperature 01h 46 h
Oxygen sensors present in 4 banks 01h 1Dh
Absolute throttle position B 01h 47h
Auxiliary input status 01h 1Eh
Absolute throttle position C 01h 48h
Run time since engine start 01h 1Fh
Accelerator pedal position D 01h 49h
Supported PIDs in the range 21 - 40 01h 20 h
Distance traveled with malfunction Accelerator pedal position E 01h 4Ah
01h 21h
indicator lamp on Accelerator pedal position F 01h 4Bh
Engineering

Fuel rail pressure (relative to mainfold Commanded throttle actuator 01h 4Ch
01h 22h
vacuum
Time run with MIL on 01h 4Dh
Fuel rail gauge pressure (diesel, or
01h 23h Time since trouble codes cleared 01h 4Eh
gasoline direct injection)
Oxygen sensor 1 01h 24h Get DTCs 01h 00 h
Oxygen sensor 2 01h 25h Supported PIDs 01h 00 h
Oxygen sensor 3 01h 26 h VIN message count 01h 01h
Oxygen sensor 4 01h 27h Get VIN 01h 02h
Oxygen sensor 5 01h 28h ECU name message count 01h 09h
Oxygen sensor 6 01h 29h Get ECU name 01h 0Ah

CAN Newsletter 4/2019 35


Engineering

Figure 2: Program flow chart (Source: MHS-Elektronik)

manufacturer code is broken down using the wmi.db data-


base. The dtc_db.c module converts diagnostic trouble
codes into plain text. The error database dtc.db is loaded
for this purpose.
Without IoT (Internet-of-Things), nothing runs today.
The most important vehicle data is provided as HTML5 The app can also send commands to the software.
page via an Apache web server. A JSON over TCP/IP Here is an example of a command and its response:
interface is available for apps.
The xml_database.c cyclically writes the dashboard. {"command":"platform","unix_time":0,"bypass":
xml and status.xml files with the current measured values false," bus":0,"enabled":false}\0
via the XMLDatabaseUpdate function. Here is an excerpt {"command_response": "platform", "message":
from the XML file: "Tiny-CAN & Pi", "status": true}\0

<?xml version="1.0" encoding="utf-8"?> The open source project is hosted on Github and is
<dashboard> licensed under the MIT license. The GIT project homepage
<Speed> 0</Speed> describes the compilation, the required hardware, and the
<Rpm> 0</Rpm> packages to be installed. Also the license text, numerous
.... useful tips, e.g. how to turn off the mouse pointer, and
</dashboard> some screenshots can be found there. The sources of
the libmhstcan.so (Tiny-CAN API) are included in the
Since the XML files are only simple static one-dimen- Tiny-CAN software package and not part of the GIT
sional structures, no XML library was used to write the files. repository. t
Instead g_strdup_printf and the standard file I/O functions
are used.
A Java script of the HTML page cyclically triggers
a GET request, which reads the corresponding XML file
according to the displayed page. The two modules sock_
lib.c und open_xc.c are responsible for TCP/IP commu-
nication. The sock_lib.c module creates its own thread in
which new socket connections and received data are pro-
cessed. The open_xc.c module also generates an auxil-
iary thread that triggers the cyclic transmission of the OBD
data. The used JSON message format is compatible to the
open source project Open XC of Ford Bug Labs, so the
Android, iOS libraries and apps of Open XC can be used.
As soon as an app opens the TCP/IP socket, the OBD
data is also transferred cyclically. Example of a data
record:

{"name": "vehicle_speed", "value": 45}\0 Author

A data record is completed with \0. It is also possible Klaus Demlehner


to send several data records in one package. Example: MHS-Elektronik
[email protected]
{"name": ...}\0{"name": ...}\0 www.mhs-elektronik.de

36 CAN Newsletter 4/2019


Meet and discuss latest
CAN-related solutions with CAN experts
March 17 to 18, 2019
Register at www.can-cia.org/icc

For details regarding sponsorship, please contact CiA office:


Phone: +49-911-928819-22 • email: [email protected]

Sponsors

You might also like