Get idea about What is OBD?, OBD Chip, How it works, OBD Simulator, Connection with OBD Adapter, OBD Configuration Commands, Measuring RPM & Speed, OBD II Trouble Codes, OBD Code Explained and more....
2. What is OBD?
OBD is an acronym for “on-board diagnostics”
and refers to vehicle's self-diagnostics and
reporting capability.
Originally it was intended to help mechanics
run quick vehicle diagnostics.
www.letsnurture.com
3. OBD Chip
First of all, you would need a OBDII adapter to be
able to use the OBDII interface. There are many
adapters from different manufacturers. Some of
them have a COM interface, others have a USB
interface, and some have a Bluetooth interface
www.letsnurture.com
4. www.letsnurture.com
How it works
Theoretically, any adapter can be used by the
Android application, but in practice, your best
choice is the Bluetooth interface.
Also, adapters can be differentiated by supported
OBDII protocols (i.e. by supported vehicles).
So if you have a car within reach and good OBDII
adapter we can start developing OBDII reader
application.
You can use OBD Simulator software also.
5. www.letsnurture.com
OBD Simulator
The one that worked for me is OBDSim: it is an
open source project available for different
platforms.
A hardware emulator can be used instead of a real
car. I used ECUsim 2000 standard with ISO 15765
(CAN) protocol enabled.
As for the OBDII adapter - I used ELM327 v.1.5
adapter.
6. www.letsnurture.com
Developing the application
Let's start with describing the protocol that is used
for communication between Android device and
OBDII adapter/vehicle.
It is text-based polling type protocol. This means
that all you need is to send a command to receive
a response. And knowing what commands to send
is key.
We will connect to the adapter through Bluetooth.
It seems that Bluetooth Low Energy API is just the
thing we should use.
7. www.letsnurture.com
The protocol supports AT commands like turning
echo and control line feed. Another part of the
protocol is OBDII control protocol itself.
The general workflow of the application
functionality should go like this:
1) connect to the OBDII adapter through
Bluetooth;
2) initialize OBDII adapter with AT commands;
3) continuously get data from the vehicle through
issuing the corresponding PID codes.
8. www.letsnurture.com
Connecting to the OBDII adapter is straightforward. But one thing you need to do before connecting is to select the Bluetooth device.
Displaying an alert dialConnecting to the OBDII adapter is straightforward. But one thing you need to do before connecting is to select the
Bluetooth device. Displaying an alert dialogue with single choice items is a good way to go:ogue with single
choice items is a good way to go:
Connection with OBD Adapter
Connecting to the OBDII adapter is straightforward.
But one thing you need to do before connecting is to
select the Bluetooth device. Displaying an alert dialogue
with single choice items is a good way to go.
The UUID I mentioned represents a “serial” interface
through Bluetooth. Of course, this code should be
executed in a non-UI thread.
Also, I would recommend checking this article for details
and a solution of a bug in Android that can lead to
connection failure in some cases.
Don't forget to initialize the OBDII adapter first by issuing
configuration commands
9. www.letsnurture.com
new EchoOffObdCommand().run(socket.getInputStream(), socket.getOutputStream());
new LineFeedOffObdCommand().run(socket.getInputStream(), socket.getOutputStream());
new TimeoutObdCommand().run(socket.getInputStream(), socket.getOutputStream());
new SelectProtocolObdCommand(ObdProtocols.AUTO).run(socket.getInputStream(), socket.getOutputStream());
OBD Configuration Commands
new
EchoOffObdCommand().run(socket.getInputStream(),
socket.getOutputStream());
new
LineFeedOffObdCommand().run(socket.getInputStream(),
socket.getOutputStream());
new
TimeoutObdCommand().run(socket.getInputStream(),
socket.getOutputStream());
new
SelectProtocolObdCommand(ObdProtocols.AUTO).run(s
ocket.getInputStream(), socket.getOutputStream());
10. www.letsnurture.com
Measuring RPM & Speed
EngineRPMObdCommand engineRpmCommand = new
EngineRPMObdCommand();
SpeedObdCommand speedCommand = new SpeedObdCommand();
while (!Thread.currentThread().isInterrupted())
{
engineRpmCommand.run(sock.getInputStream(),
sock.getOutputStream());
speedCommand.run(sock.getInputStream(), sock.getOutputStream());
// TODO handle commands result
Log.d(TAG, "RPM: " + engineRpmCommand.getFormattedResult());
Log.d(TAG, "Speed: " + speedCommand.getFormattedResult());
}
11. www.letsnurture.com
OBD II Trouble Codes
OBD-II codes consist of a number of parts. Here is a
sample OBD2 code:
P0171
The first character identifies identifies the system related
to the trouble code. P = Powertrain B = Body C = Chassis
U = Undefined
The second digit identifies whether the code is a generic
code (same on all OBD-II equpped vehicles), or a
manufacturer specific code. 0 = Generic (this is the digit
zero -- not the letter "O") 1 = Enhanced (manufacturer
specific)
12. www.letsnurture.com
new EchoOffObdCommand().run(socket.getInputStream(), socket.getOutputStream());
new LineFeedOffObdCommand().run(socket.getInputStream(), socket.getOutputStream());
new TimeoutObdCommand().run(socket.getInputStream(), socket.getOutputStream());
new SelectProtocolObdCommand(ObdProtocols.AUTO).run(socket.getInputStream(), socket.getOutputStream());
The third digit denotes the type of sub-system that
pertains to the code
1 = Emission Management (Fuel or Air)
2 = Injector Circuit (Fuel or Air)
3 = Ignition or Misfire
4 = Emission Control
5 = Vehicle Speed & Idle Control
6 = Computer & Output Circuit
7 = Transmission
8 = Transmission
9 = SAE Reserved
0 = SAE Reserved
13. www.letsnurture.com
new EchoOffObdCommand().run(socket.getInputStream(), socket.getOutputStream());
new LineFeedOffObdCommand().run(socket.getInputStream(), socket.getOutputStream());
new TimeoutObdCommand().run(socket.getInputStream(), socket.getOutputStream());
new SelectProtocolObdCommand(ObdProtocols.AUTO).run(socket.getInputStream(), socket.getOutputStream());
OBD Code Explained
The most common OBD-II codes are P0xxx powertrain
codes, along with P2xxx generic & P3xxx generic codes
(please scroll down).
For the other OBD-II codes, choose from Bxxxx - B Codes
- OBD-II Body Codes or Cxxxx - C Codes - Chassis
Codes, and Uxxxx - U - Network Codes.
If your DTC (diagnostic trouble code) begins with P1xxx,
that means it's a manufacturer specific code