Search code examples
androiddistancepidobd-ii

Android OBD-II distance travelled (PID31)


I am trying to read the distance traveled since some codes were cleared from the OBD with an Android application.

I have managed to get the RPM and fuel % to work but the distance traveled is higher than what I would expect.

case 49: //PID(31): Distance Travelled(A*256)+B
  Double miles = (((valueA*256)+valueB)*0.62137;
  String displayDistance = String.valueOf("Miles: " + miles);    

Anyone know where I've gone wrong?


Solution

  • I have discovered the code is right but not 100% accurate because I parsing the bytes into an int and therefore calculation is out by about 7 miles. Will need to find a way to parse as a double. The issue when I am thousands of miles out is a concurrent issue with interleaving of a shared variable.