arduino-OBD2 icon indicating copy to clipboard operation
arduino-OBD2 copied to clipboard

How to read the dtc codes

Open shivpj opened this issue 3 years ago • 9 comments

Hello, How to read the dtc codes?

int OBD2Class::ReadDtcs(uint8_t mode, void* data, int length) { // make sure at least 60 ms have passed since the last response unsigned long lastResponseDelta = millis() - _lastPidResponseMillis; if (lastResponseDelta < 60) { delay(60 - lastResponseDelta); } for (int retries = 10; retries > 0; retries--) { if (_useExtendedAddressing) { CAN.beginExtendedPacket(0x18db33f1, 8); } else { CAN.beginPacket(0x7df, 8); } CAN.write(0x02); // number of additional bytes CAN.write(mode); //CAN.write(pid); if (CAN.endPacket()) { // send success break; } else if (retries <= 1) { return 0; } } bool splitResponse = (length > 5); for (unsigned long start = millis(); (millis() - start) < _responseTimeout;) { if (CAN.parsePacket() != 0 && (splitResponse ? (CAN.read() == 0x10 && CAN.read()) : CAN.read()) && (CAN.read() == (mode | 0x40))) {

  _lastPidResponseMillis = millis();

  // got a response
  if (!splitResponse) {
    return CAN.readBytes((uint8_t*)data, length);
  }
  int read = CAN.readBytes((uint8_t*)data, 3);
  for (int i = 0; read < length; i++) {
    delay(60);

    // send the request for the next chunk
    if (_useExtendedAddressing) {
      CAN.beginExtendedPacket(0x18db33f1, 8);
    } else {
      CAN.beginPacket(0x7df, 8);
    }
    CAN.write(0x30);
    CAN.endPacket();
    // wait for response
    while (CAN.parsePacket() == 0 ||
           CAN.read() != (0x21 + i)); // correct sequence number
    while (CAN.available()) {
      ((uint8_t*)data)[read++] = CAN.read();
    }
  }
  _lastPidResponseMillis = millis();
  return read;
}

}

return 0; }

I have added a function like this. While running this function, there is no output. could you please suggest any changes.

Thanks

shivpj avatar Aug 12 '21 12:08 shivpj

Hello, Is the above code is correct to read the stored dtc codes?

shivpj avatar Aug 13 '21 22:08 shivpj

hi, you removed the pids byte, try the following: CAN.write(0x01); // number of additional bytes

se-pulvirenti avatar Sep 02 '21 16:09 se-pulvirenti

hi, you removed the pids byte, try the following: CAN.write(0x01); // number of additional bytes

Thanks for the response, I tried but the above function returned zero (0). I used this PID to get the status of the DTC codes. Capture3 It returned "516352" value. As per below table. image How should I encode this value.

shivpj avatar Sep 05 '21 09:09 shivpj

Hi, I tried on my car, it returns 0 but actually I don't have DTC code, like in your case: 516352 = binary 00000000 00000111 11100001 00000000 A = 00000000 B = 00000111 C = 11100001 D = 00000000 A7 is 0 (it means that the warning light on the dashboard is off) A6-A0 is 0 (no DTCs)

se-pulvirenti avatar Sep 05 '21 11:09 se-pulvirenti

Hi, Could you please provide an example as to how this function can be used to read DTCs? I don't understand the arguments I have to pass, besides 0x03 to select mode 3.

Thanks !

fsu-icx avatar Jul 05 '23 20:07 fsu-icx

That function is incomplete to read DTCs you have to do more work than what is done there

skndungu avatar Jul 06 '23 06:07 skndungu

Thank you for the reply!

Yes this is what I suspected, sadly I don't have the skill to complete the function, I tried but I'm too far off :)

Too bad Sandeep's great library doesn't provide this feature though.

Cheers!

fsu-icx avatar Jul 06 '23 06:07 fsu-icx