Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added function to clear diagnostic trouble codes (DTC) #7

Merged
merged 10 commits into from
Jan 23, 2021
Merged

Added function to clear diagnostic trouble codes (DTC) #7

merged 10 commits into from
Jan 23, 2021

Conversation

JasonJoyner01
Copy link
Contributor

Created function to clear DTC codes from vehicle ECU using Service 04 functionality, using format documented at:

https://en.wikipedia.org/wiki/OBD-II_PIDs#Service_04
https://en.wikipedia.org/wiki/OBD-II_PIDs#Query

ECU should return 0 data bytes. PID not required. This is part of Open Issue #5

Copy link
Owner

@sandeepmistry sandeepmistry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tonkaman awesome work! Thanks for opening this pull request!

I've left a few minor comments, please let me know what you think!

src/OBD2.cpp Outdated Show resolved Hide resolved
src/OBD2.cpp Outdated
@@ -695,6 +695,36 @@ int OBD2Class::supportedPidsRead()
return 1;
}

int OBD2Class::clearAllStoredDTC() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add an entry for clearAllStoredDTC in both keywords.txt and API.md.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I'll add the function to the keywords.txt file. How do you feel about this for the API.md?

Clear Stored Diagnostic Trouble Codes (DTC)

Clears any stored DTCs in the vehicle ECU, and turns off Malfunction Indicator Light (MIL, more commonly known as the Check Engine light).

int success = OBD2.clearAllStoredDTC();

Returns 1 if successful, or 0 on failure

Copy link
Owner

@sandeepmistry sandeepmistry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tonkaman updates look good!

I'm just going to make some minor style changes before merging.

src/OBD2.cpp Outdated Show resolved Hide resolved
src/OBD2.cpp Outdated Show resolved Hide resolved
src/OBD2.cpp Outdated Show resolved Hide resolved
src/OBD2.cpp Outdated Show resolved Hide resolved
src/OBD2.cpp Outdated Show resolved Hide resolved
@sandeepmistry sandeepmistry merged commit 20ef945 into sandeepmistry:master Jan 23, 2021
@sandeepmistry
Copy link
Owner

@tonkaman awesome work!

@JasonJoyner01
Copy link
Contributor Author

JasonJoyner01 commented Jan 24, 2021

@sandeepmistry No problem. Eventually when I have time I want to tackle trying to read the DTC codes from a vehicle as well. That's not quite as simple as clearing them. Apologies for the messiness of my commits. This was my first time using Git, and I'm still learning the proper workflow.

@jLynx
Copy link

jLynx commented Dec 21, 2021

@tonkaman I was writing a reply on my issue on your repo, but you made it private so I could not do it. All I was going to say is I found that repo because of your PR here. I am going to test what I mentioned in your issue with am obd2 scanner and clear the codes and sniff the bus to see what command actually gets sent. I can then update you with what the command is from here if it differs

@JasonJoyner01
Copy link
Contributor Author

JasonJoyner01 commented Dec 21, 2021 via email

@jLynx
Copy link

jLynx commented Dec 21, 2021

Hmm, this is really strange. I wasn't able to see the clear fault codes command when I executed it with my obd2 adapter

@JasonJoyner01
Copy link
Contributor Author

JasonJoyner01 commented Dec 21, 2021

I figured out how to purposely trigger a fault code on my 2011 Chevy Cruze by unplugging the O2 sensor. You are correct the function as written does not work. I'm stumped at the moment because I seem to get the response that it worked (returns 1), but the light doesn't go out on the dash. My guess is the message format is incorrect, but I can't find any documentation that's not behind an SAE or ISO paywall.

`
int OBD2Class::clearAllStoredDTC()
{
//Function clears stored Diagnostic Trouble Codes (DTC)

// 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(0x00); // number of additional bytes
    CAN.write(0x04); // Mode / Service 4, for clearing DTC
    CAN.write(0x00);
    if (CAN.endPacket()) {
        // send success
        break;
    } else if (retries <= 1) {
        return 0;
    }
}

return 1;

}
`

@jLynx
Copy link

jLynx commented Dec 21, 2021

Ok well at least I am not going crazy. I am really interested in trying to get this working.
I have been doing a bunch of research too and I can hardly find any documentation about it. The best I can do is find the Wikipedia page which is where you mentioned you got this info from too.

I wonder if there is another way to sniff the bus to get this info?
Also I think the reason why I couldnt sniff it is because in my 2003 BMW the OBD2 port doesn't have the CAN wires, so it must be communicating with something else for diagnostics. Sadly I dont have any other cars where I could test this out on.

@jLynx
Copy link

jLynx commented Dec 21, 2021

Just an idea. Does it need to do some sort of search/request for error codes before it can clear them? I am doubtful as it doesn't pass and specific data when it clears. but its just an idea

@JasonJoyner01
Copy link
Contributor Author

I'm in the same boat. At least my Cruze is somewhat modern. My other vehicle is a 1997 pickup that predates CAN. My fiance also has a Cruze, so effectively we're limited to a single vehicle to test with at my house.

I'm going to keep trying things, but I think I might need to pony up the $85 for the 16 page SAE J2012_201612 document.

@jLynx
Copy link

jLynx commented Dec 21, 2021

Do you use Discord or something like that that we could collaborate a bit more together on @tonkaman ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants