- Sun Oct 07, 2018 1:12 am
#200578
I am trying to read some PID's from a Subaru Forester using a Spark Fun OBD II Uart and an arduino.
I can read the normal PID mode 01 codes, however i wish to read an extended OBD II code.
It is mode 0x22 PID 0x0005. How can I achieve this?
There is also another code that I would also like to read, I believe that it is can bus.
The code id is:
TDX 07E1221017
RXF C46205103617
RDX 3008
MTH 00010001FFCE
I believe that the Sparkfun OBDII UART can read canbus as it has the correct chip set.
If someone can help with the code please.
The code I am currently using is shown below
I can read the normal PID mode 01 codes, however i wish to read an extended OBD II code.
It is mode 0x22 PID 0x0005. How can I achieve this?
There is also another code that I would also like to read, I believe that it is can bus.
The code id is:
TDX 07E1221017
RXF C46205103617
RDX 3008
MTH 00010001FFCE
I believe that the Sparkfun OBDII UART can read canbus as it has the correct chip set.
If someone can help with the code please.
The code I am currently using is shown below
Code: Select all
// This is a character buffer that will store the data from the serial port:
char rxData[20];
char rxIndex = 0;
char inChar = 0;
String message;
// Variables to hold the speed and the RPM data:
int vTemp = 0;
// Statistics
Statistic CoolStats;
void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC);
display.clearDisplay();
display.display();
rpmStats.clear();
//Reset the OBD-II-UART
Serial.println("ATZ");
//Wait for a bit before starting to send commands after the reset.
delay(2000);
//Delete any data that may be in the serial port before we begin.
Serial.flush();
}
void loop() {
getCoolTemp();
}
void getCoolTemp(void){
message = "0105";
Serial.println(message);
delay(200);
//wait for the response from the car
getResponse();
vTemp = strtol(&rxData[6], 0, 16); // in the unit of C but offset by 40 degrees
vTemp = vTemp - 40; // offset by 0
CoolStats.add(vTemp);
display.setTextSize(2);
display.setTextColor(WHITE,BLACK);
display.setCursor(0,40);
display.print(CoolStats.maximum(), 0);
display.print((char)247);display.print("C max ");
display.setCursor(0,20);
display.print(vTemp);
// print the degree C
display.print((char)247);display.print("C Temp ");
display.display();
}
void getResponse(void){
while(Serial.available() > 0) {
// Start by checking if we've received the end of message character ('\r').
if(Serial.peek() == '\r'){
// reach the end of the message, clear the Serial buffer
inChar = Serial.read();
rxData[rxIndex] = '\0';
// Reset the buffer index so that the next character goes back at the beginning of the string
rxIndex = 0;
}
// If we didnt get the end of the message character, just add the new character to the string
else{
// Get the new character from the Serial port:
inChar = Serial.read();
// add the new character to the string, and increase the index variable:
rxData[rxIndex++] = inChar;
}
}
}
void resetBuffer(void){
for (int i = 0; i < 20; i++){
rxData[i] = 0;
}
}