Wednesday, February 22, 2017

Guidelines for OBD Reader Android Application Development

OBD adapter is an electronic device that allows a computer to access the vehicle network through its ECU (Engine Control Unit). OBD2 adapter can be plugged into the OBD2 ports (Data Link Connector (DLC)) in a vehicle. Data coming from the ECU can be retrieved from an android application via Bluetooth connection. OBD2 provides real time data.

Data flows both ways through OBD2 to and from the ECU. This will be the flow of data
  1.  Mobile application sends request to the OBD adapter via Bluetooth interface (AT commands).
  2. OBD2 adapter receives the request.
  3. OBD2 retransmits the request to the ECU on one of the OBD protocols
  4. ECU responds back with the data to OBD2.
  5. OBD2 sends data to the mobile application.
A protocol is used for the communication between OBD device and android application. It is text based polling type protocol. That means you should send commands as requests in order to get a response. 

OBDSim

Since it is not possible always to test OBD2 related applications in a real environment with a vehicle there are existing application which has the capability to simulate a vehicle with an OBD device plugged in.

OBDSim is one such simulator which we have used to test our mobile application. This is a cross platform and works on Windows/ Linux software platforms. Similar to ELM327 OBD2 adapter this also works on AT commands which are used to configure an ELM327.

Installing OBDSim

You can download it from this link http://icculus.org/obdgpslogger/.
Useful links to set up OBDSim
  1. http://stackoverflow.com/questions/13164150/obd2-elm327-bluetooth-simulator?lq=1
  2.  http://stackoverflow.com/questions/21957505/connect-obdsim-to-torque-on-windows-through-bluetooth
  3. http://stackoverflow.com/questions/25720469/connect-obdsim-to-torqueandroid-app-ubuntu/25763606#25763606
After installing and running the OBDSim we can manually change the parameters and test our application.


Developing Android Application

Application should be capable of performing following functionalities.
  • Connect to OBD device through its Bluetooth interface.
  • Initialize OBD adapter with AT commands.
o   AT SP 0 - This is to set the protocol to “AUTO”. That means we want the interface to automatically detect the protocol when we send the first OBD request. If it is successful reply will be “OK”.
o   AT DP - To verify the protocol (Display Protocol). Reply – “AUTO

  •      Continuously retrieve data from OBD adapter.

We have to use OBD-II Parameter IDs (On-Board Diagnostics Parameter IDs - PIDs) in order to communicate with the vehicle. Those individual PIDs provide some specific information on vehicular data. 
OBD-II PIDs (On-Board Diagnostics Parameter IDs) are codes used to request data from a vehicle. There is a standard set of PIDs which is defined by SAE standard J/1979. Other than that, manufacturers define their own PIDs.
Process of communication through PIDs.
1.  Mobile application sends PID s as requests to the OBD2 adapter.
2. OBD2 device sends it to the vehicle’s controller area network (CAN).
  1.  A device on the bus recognizes the PID as one it is responsible for, and reports the  value for that PID to the bus.
  2. OBD2 reads the response and send it back to the mobile application.
 Example PID s that are sent to get speed and RPM.

           o   010C – Get RPM. Example reply – “41 0C 0F A0”. The reply contains two bytes that identify it as a response to Mode 1, PID 0C request (41 0C), and two more bytes with the encoded RPM value (1/4 RPM per bit). To get the actual RPM value, convert the hex number to decimal, and divide it by four: 
                                                     0x0FA = 4000
                                                     4000/4 = 1000 rpm
o   010D – Get vehicle speed.  Reply – 41 0D FF. To get the speed have to convert this to decimal.

No comments:

Post a Comment