4

I working on an app that I need to calculate distance travelled from point A to point B (by car).

I asked Elm Electronics (chipset manufacturer) and they said there is no standard OBD-II PID to return mileage from odometer, although car manufacturers might provide a PID. Since this way is not standard then I found another way.

PID 0131 (Distance traveled since codes cleared), is returning something that I think might be helpful. IF i'm able to clear it at point A and read its value at point B then I'm done :)

I thought a lot to guess what does "codes cleared" mean but I couldn't realize what does it mean? and my another important question, how to clear code or reset this PID?

Any suggestion would be appreciated. Thanks.


Update

I just tested on two Cars.

  1. On Benz car no OBD-II command works. I couldn't get any data :(
  2. I got correct reply on Persona car (Local Malaysia) but 0x0131 PID was always returned 7F01 which is 16608KM even after passing few Kms. I tried to reset it by sending 04 command (as Eric suggested on his answer), However, nothing got clear :) and I still got 7F01 as response.

My Library can be used for anyone who is looking for OBD-II lib from here.

So, What I plan to do is, since I'm able to get speed (v) then I'm able to calculate distance based on d = v * t formula.

Hesam
  • 52,260
  • 74
  • 224
  • 365
  • Here's a hint, the codes can be cleared with any obd2 reader or by disconnecting the car battery. Basically, your method isn't going to work. – Elliott Frisch Jan 02 '15 at 02:47
  • @ElliottFrisch Thanks for fast reply. I'm actually using Bluetooth ELM327 which is a reader and is connected to my application. I can send a code and get result. But I'm wondering can I reset (clear code) by a command? – Hesam Jan 02 '15 at 02:51
  • 1
    According to [this](http://www.elmelectronics.com/ELM327/AT_Commands.pdf) yes. It's `Z`. – Elliott Frisch Jan 02 '15 at 03:01
  • @ElliottFrisch Thanks for spending time. Yup, ElmElectronics suggesting to start with "AT Z" command. I did it actually and got proper response which is name and version of ELM327. However by sending "0131" command I still get something "41 31 31 75". Therefore, Z command have not cleared it :( – Hesam Jan 02 '15 at 03:10
  • 1
    I have an Actron, so I can't really help further... good luck! – Elliott Frisch Jan 02 '15 at 03:11
  • The reason that "Z" command doesn't work is because it's ELM command and not OBD command. I'm looking for a command to reset OBD rather than my ELM device. – Hesam Jan 02 '15 at 08:16
  • Clearing is probably not a good idea. Better to store a "before" value in the app to subtract later. – Chris Stratton Jan 03 '15 at 11:35
  • 1
    @Mr.Hyde, nope, you should read `v` persecond and kepp it somewhere (in memory such as list or database) then add them all to find final distance. – Hesam Mar 26 '17 at 03:54

3 Answers3

2

Elm Electronics are right. The resetting trouble codes solution is a possible, but maybe unwanted workaround though.

Mode 04 is for resetting the codes. Sending 04 will reset the MIL (Malfunction Indicator Light) and reset the codes you want to reset.

In the comments, Chris suggested to use the value, and than keep track of this value yourself. That way you don't need to misuse the Mode 04. Th 0131 value overflows at 65535 km. But when you bring you car in for maintenance, they could reset this value, depending on who is maintaining your car ofcourse.

Source: Mode 04 - Wikipedia

Eric Smekens
  • 1,602
  • 20
  • 32
  • Clearing diagnostic codes for unrelated purposes doesn't sound like a good idea. – Chris Stratton Jan 03 '15 at 11:36
  • Indeed, so readers, beware! However, this is the only way he can make use of the 0131 PID that has been mentioned in the question. – Eric Smekens Jan 03 '15 at 11:39
  • 1
    Does that value overflow quickly? Otherwise storing the original value to subtract should work unless someone else (like legitimate engine service) clears it in between, but that would break this approach too. – Chris Stratton Jan 03 '15 at 11:42
  • @EricSmekens Thanks for your reply. I still haven't tested but I think it's correct based on your reference. Will test it soon. – Hesam Jan 05 '15 at 02:20
  • @EricSmekens, Have you get distance travelled ? I have to do same. Let me know for any solution. – Hiren Patel Jul 08 '15 at 09:39
1

There are two PIds: 0x0121 Distance travelled with malfunction indicator lamp (MIL) on which keeps the distance with MIL on and 0x0131 Distance travelled since codes cleared which keeps the distance after clearing the MIL by using mode 0x04. By saying code, it meant the Diagnostics Trouble Code (DTC). When one of them keeps counting the distance the other one is fixed and activation is done for them only based on MIL on or off.

For having the milage, afaik, you need to have current mileage from the odometer as the reference, in addition to those two PIDs. For example, if the current mileage on the odometer* is X and the first time readings for those two PIDs are Y and Z respectively, and x and y are real-time readings from those two PIDs, these two formulas can give you the mileage and trip distance:

Real-Time mileage** = X + (y - Y) + (z - Z)

Trip distance (MIL Off) = x(end) - x(start) 

Trip distance (MIL On) = y(end) - y(start) 

*The odometer is supposed to be available by PID 0x01A6 Odometer, but in almost all the vehicles, it's not supported.

**The overflow in readings from those two PIDs should be considered as well.

aLoneStrider
  • 343
  • 1
  • 6
  • 13
0

I think You can use the PID 0x011F (Run time since engine start) and PID 0x010D (Vehicle speed). If you save these values in an sd card then you can multiply these two values.

aLoneStrider
  • 343
  • 1
  • 6
  • 13
  • 1
    The simple multiplication does not give the correct answer here. You need to get the integral for speed readings on the trip duration. – aLoneStrider Oct 17 '19 at 01:16