Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android OBD-II: How to get distance traveled in meters?

Tags:

android

obd-ii

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.

like image 894
lordian Avatar asked Dec 24 '22 01:12

lordian


2 Answers

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.

  • GM Chevy Spark PIDs
like image 134
Jon Avatar answered Dec 26 '22 15:12

Jon


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.

like image 32
obdkey Avatar answered Dec 26 '22 16:12

obdkey