Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,
I'm new member here and also a joiner in programming
i try to extract information from my vehicle using OBD-II cable adapter. I try simple code to read the RPM and successfully got it and print it in serial monitor but i face a simple problem. Serial monitor display the PID-Code + current value of RPM as shown below:

010C849 010C: refer to RPM-PID used and 849: current value of RPM

so can i cutout the HEX number from the result and just display the value of RPM such as (849)

i used the following code:

#include <OBD2UART.h>
COBD obd;
void setup()
{
  pinMode(13, OUTPUT);
  obd.begin();
  while (!obd.init());
}
void loop()
{
  int value;
  if (obd.readPID(PID_RPM, value)) {
        Serial.println(value);
        delay(1000);
  }
}


What I have tried:

using the following
int x;
  int y="010C";
      x=value-y;
       Serial.println(x);
Posted
Updated 19-Jul-20 16:08pm

1 solution

Well .. if you have to use obd.readPID... instead of just
obd.read(PID_RPM,value)
I would do something like
Serial.println((unsigned int)value % 10000)
 
Share this answer
 
Comments
Hussein Awadh1 20-Jul-20 14:08pm    
thank you for your response i try to add line that you mention but when i go to serial monitor it still the same issue 010C+Current RPM as shown below:

010C680
010C685
010C685
010C710
Garth J Lancaster 20-Jul-20 18:53pm    
what is the exact code you have now ? (that didnt work)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900