Hi folks, I successfully connected Arduino via Bluetooth module HC-05 to my car’s ELM327 OBD2 bluetooth adapter.
Currently I’m able to send PID requests and read their responded values on Arduino’s LCD display and also in serial port monitor.
Harder part for me is to understand how to obtain correct values for equation after converting HEX response to DEC value.
If someone experienced can help me resolve this I will be very grateful.
Here’s part of Arduino code:
BuildINString = ""; Serial.println("213E1"); //PID request 21 3E 1 delay(1000); //wait 1 sec. ReadData(); WorkingString = BuildINString.substring(1,9); //Obtain data for equation here I'm not sure if (1,9) is OK A = strtol(WorkingString.c_str(),NULL,16); //Converts HEX to DEC; A is defined as Long WorkingString = BuildINString.substring(9,17); //Obtain data for equation here I'm not sure if (9,17) is OK B = strtol(WorkingString.c_str(),NULL,16); //Converts HEX to DEC; B is defined as Int DisplayValue = (((A*256)+B)*0.02)-40; //Equation DisplayString = String(DisplayValue) + "°C"; //Result of equation with °C Serial.println(DisplayString); //Shows result of equation in serial port monitor lcd.setCursor(0, 1); lcd.print(DisplayString); //Shows result of equation on Arduino's LCD display
Responded value from serial port monitor of PID 213E1 were 61 3E 0C 13.
In this case I need to convert 0C to decimal and use it as A in equation; and also convert 13 to decimal and use it as B in equation.
HEX 0C to DEC = 12 HEX 13 to DEC = 19
Steps of equation should then looks like: (((A*256)+B)*0.02)-40 (((12*256)+19)*0.02)-40 (3091*0.02)-40 21.82 °C