4
votes

I'm making an android app that connects to an OBD-II device (ELM327 - http://www.dx.com/p/elm327-bluetooth-odb2-v1-5-car-diagnostic-interface-126921#.V86wdih97IU) via Bluetooth.

I'm also using the https://github.com/pires/obd-java-api/ library to get the data from the device.

I am able to connect to the device and get data without any problems but when I try to retrieve distance it always returns it in KM. Is there a way to get the distance of a trip in meters instead?

I tried using the Torque Lite app (https://play.google.com/store/apps/details?id=org.prowl.torquefree&hl=en) and its able to return Trip distance in KM with one decimal place (0.0 KM).

Would like to know what command it uses to actually get the values or does it derive it from something else.

4
What command are you using to get the distance in km now?Jon
I'm using the new DistanceSinceCCCommand(); which sends a "01 31" command.lordian
@lordian - How did you achieve this? I am stuck with the same problemSahana Prabhakar

4 Answers

7
votes

Unfortunately, a standard PID for distance traveled simply doesn't exist. See this for a list of standard PIDs.

The code you are using now, DistanceSinceCCCommand, uses standard Mode 01 PID 0x31 to retrieve the distance driven since the last clear codes command. The PID has units of integer kilometers and thus cannot give you the precision you are seeking.

I tried using the Torque Lite app (https://play.google.com/store/apps/details?id=org.prowl.torquefree&hl=en) and its able to return Trip distance in KM with one decimal place (0.0 KM).

The torque app used location(GPS) information from the android device to record geo location. I'd guess that it is using that information to determine the trip distance to the precision of 0.1km.

Recommendation

I'd recommend you follow their lead and use location data to determine distance traveled if you need that sort of accuracy.

Use a Location Listener from the google location api and Location.distanceTo(location) to determine the incremental location changes.

More On Enhanced PIDs

Enhanced PIDs (also called DIDs) are mode 22 parameters that are vehicle specific.

There exist many other vehicle parameters that are not publicly documented and may offer better precision. They are vehicle specific (but usually common to a subset of vehicles from the same manufacturer). They are Mode 22 enhanced PIDs. Here's a list of old Ford DIDs. If anyone can find a newer list of mode 22 DIDs, please edit my post and add it as I know there are many more than I've found available publicly.

3
votes

You could read the OBD-II Mode 1, PID 0D to get the speed at regular intervals. This would give a decent distance reading in metres if you read often enough and apply the distance = speed * time calculation.

0
votes

Most of the classes implement

ObdCommand 

which has a method

useImperialUnits(boolean)

so, if you use, say, DistanceSinceCCCommand, then

DistanceSinceCCCommand distanceSinceCCCommand = new DistanceSinceCCCommand();
distanceSinceCCCommand.useImperialUnits(true);

would do the conversion. You can find interesting stuff if you examine the library source.

0
votes

You can also use

getImperialUnit()

if you just want the numeric value rather than the string with a trailing units label.