What is OBD2 ?
OBD2 is an Automotive Diagnostic Protocol which all manufactures(OEM) follow and implement in their Vehicle Control Modules .It is an International Standard and describe the ways and format how and where specific error codes(DTC's) and parameters are stored at which addresses and how the data is scaled and specified.
Before we get too much farther, let's make sure we understand all the keywords used in these protocols.
Engine/Electronic Control Unit (ECU)
They monitor and control many functions of the system. These can be standard from the manufacturer, re-programmable, or have the capability of being daisy-chained for multiple features.
Some of the more common ECU types include:
Engine Control Module (ECM) - This controls the actuators of the engine, affecting things like ignition timing, air to fuel ratios, and idle speeds.
Vehicle Control Module (VCM) - Another module that controls the engine and vehicle performance.
Transmission Control Module (TCM) - Handles the transmission, including items like transmission fluid temperature, throttle position, and wheel speed.
Power-train Control Module (PCM) - Typically, a combination of an ECM and a TCM. This controls your power-train (Engine-Gearbox).
Electronic Brake Control Module (EBCM) - This controls and reads data from the anti-lock braking system (ABS).
Body Control Module (BCM) - The module that controls vehicle body features, such as power windows, power seats, etc.
The OBD2 Protocol Support Various Communication Interfaces and all vehicles has an onboard OBD2 connector located close and around the area of the driver seat and steering wheel as specified by the OBD2 Protocol however it can also be located in the passenger side it is manufacturer dependent where it is placed.
The table below show the various OBD2 communication protocols and the pins they are using in the OBD2 connector,In this article we look at the communication with the Sparkfun OBD2 board which uses the OBD2 IC ELM327 ans supports all these protocols.The table also shows the DB9 pinout of the Sparkfun board.
We take a look at the CAN communication and the UART communications The CAN Communication communicate is between the ELM327 and the various ECU's ,The UART communication issued by our Flowcode Program to send Commands to the ELM327 which parameters to read and read the data back from the ELM327 to the FC Program.
Note: The CAN Protocol is now the most used and is most common in vehicles the other protocols are more likely to be found on older vehicles.(1990-early 2000's) .
Diagnostic Trouble Code (DTC)
These codes are used to describe where an issue is occurring on the vehicle and are defined by SAE. These codes can either be generic or unique to the vehicle manufacturer.
These codes take the following format:
First unit identifies the type of error code:
Pxxxx for power-train
Bxxxx for body
Cxxxx for chassis
Uxxxx for class 2 network
Second digit shows whether the code is manufacturer unique or not:
x0xxx for government-required code
x1xxx for manufacturer-specific code
Third digit shows what system the trouble code references:
xx1xx/xx2xx show air and fuel measurements
xx3xx shows ignition system
xx4xx shows emissions systems
xx5xx references speed/idle control
xx6xx deals with computer systems
xx7xx/xx8xx involve the transmission
xx9xx notates input/output signals and controls
Digits four and five show the specific failure code.
xxx00 to xxx99 - these are based on the systems defined in the third digit
Parameter Identification (PID)
The PIDs are the definitions of the different parameters you could be interested in checking out. These are similar to the third digit in the DTCs. Not all PIDs are supported on all protocols, and there can be several unique, custom PIDs for each manufacturer. Unfortunately, these are not generally published, so we may need to do a lot of hunting and/or reverse engineering to determine to which system each PID relates.
There are different modes available, and each mode has several options of PIDs available in that mode. For more general information on that, check the PID wiki page .
Malfunction Indicator Lamp (MIL)
The MIL is the light in the dash that indicates a problem with a system.
OBD Command Format
The OBD commands are made up of hexadecimal codes written in ASCII characters. Generally, these commands contain 2 or more pairs of hexadecimal numbers, however there are a few commands that only require one hex pair.The first hex pair in the OBD command represents the OBD mode which should be used. Any following hex pairs after that represent the Parameter ID (PID) to be read from the specified mode. There are 10 OBD modes, not all 10 modes. Are used.
There is a general structure that all OBD responses have in common(board responses).The first response byte lists the mode that was requested in the command. The second byte is the parameter that was requested, Any following bytes are the responses to the command.
Example read the Engine Rpm(This is in Mode Current Data 01)
'Read Engine RPM'. Issue command "010C" (2 hex values) from a terminal program or in our case from Flowcode. The board will respond with a value listed in hex.
The response structure is 0x41 (0x40 + the mode which is 01) to state the board is in mode 01, followed by 0x0C to show that the board is looking at the RPM parameter. The returned value of 0x0E, 0x96 can then be converted into a decimal value of 3734. This is 4 times the actual RPM, as this value is listed in quarters of RPM. Once the value is divided by 4, we have an idling RPM of 933. See PID wiki Page for Commands and Parameters
The Returned value from the board is 41 0C 0E 96
From the ODB2 Protocol Wiki /Spesification you will find the PID Command and the Data which is returned for the command it also specify the scaling values and how to obtain the correct values. Example getting the Engine RPM below.
GUI/Flowcode send command “010C”
Mode = 01 --- PID = 0C
Board return: 0x41 + 0C and 2 data bytes Value: A, B
Range: 0-16383.75 Rpm
RPM = (256A+B)/4
Setting up the OBD2 Board
Configure the UART Connection in your Flowcode or Flowcode APP developer Place a UART component on the 2D panel and configure the Component properties for the Serial interface of the OBD2 board.Configure the serial connection to 9600 bps, 8 data bits, 1 stop bit and no parity.Once you have your serial connection set up, you will communicate with the OBD2 board by using AT commands.These commands always start with "AT".
The OBD2 board is case-insensitive, . You find a list of all the available AT commands in ELM327 chip manual.To start communicating with the board, send the "ATZ" command. This will reset the board. You should see some LEDs flash on the board and you should read back the start-up prompt Character > ,(This after sending the "ATZ"command read back from the board over the serial UART Connection).(Examples of our system on EBLOCK2 COMBO Board)
To read additional OBD parameters form the ECU, the OBD2 board must first be configured to the correct OBD protocol. There are several different OBD protocols, so it can be confusing attempting to find the correct one. However, this OBD2 board automatically detects the protocol. To use this auto-detect feature, the system ignition (KL15) must be in the 'On' position. The Engine doesn’t necessarily need to be running, however. Once the ignition is on, send the command "ATSP0" (that's a trailing zero). The board will then reply with "OK" once the correct protocol has been detected.
The OBD2 board is now in operation mode and you can send the command as your application requires .
Our Engine RPM Example in the real world
It is very easy to build your own OBD2 Scanner /Reader using the ELM327 OBD2 IC and a High level programming language such as Flowcode.
Using Flowcode APP builder you can realize a PC Application that reads and display the Commands and Data received with very nice graphics ,
If there is interest in this article and OBD2 related reading, we could consider making a Flowcode component for Flowcode users to make it easier to work with OBD2 in Flowcode.
Please send us your request by using the Contact forms available on the Home page.