-
Notifications
You must be signed in to change notification settings - Fork 72
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
Mode 04 Clear Trouble Codes, CEL, MIL #8
Comments
Hi Crashmaxx,
You are correct, there is no code that does this.
Yeah I think so! I considered implementing this when I worked on it. But since I had no way to test this I chose not to do a blind implementation. Having non working code is worse than not having that code, as it creates false expectations. The implementation should indeed be something along the lines of: bool OBD9141::clearTroubleCodes(){
uint8_t message[4] = {0x68, 0x6A, 0xF1, 0x04};
// 0x04 without PID value should clear the trouble codes / malfunction indicator lamp.
bool res = this->request(&message, 4, /* return probably same length? */ 4);
return res;
} Wikipedia says there are no data bytes returned. The return format is a bit of a mystery unfortunately, I expect the response to be the same length as the request if the data length is zero. That would continue the pattern set for the other PID's (see the getPID method). If you have a vehicle where you can safely trigger a trouble code, feel free to test the above snippet. If the malfunction light goes off but the method returns false, increase the return length from Let us know how this works out! |
Wow! Thank you for the quick response! I have a car with an engine swap, so it is missing some sensors. It will get trouble codes as soon as it starts and the CEL will come on in a few minutes. I will test the code tomorrow and get back to you. I hope I can verify it well enough you can add it to the library. Thanks again! |
Attached is a zip with my modified OBD9141.h, OBD9141.cpp, the sketch I tested with (Clear_Codes2.ino), and the serial console data I recorded (ClearCodesData.text). It worked great! The CEL went away when I started the car. The function seems to return 0, but maybe I am collecting that data wrong. I wanted to have it only clear the codes when the car is on, but not running, and had driven at least 10 miles since the codes were last cleared. I couldn't get PID 31 (Distance since CEL cleared) to read though. I'd be happy to do more testing if you want to try anything different. Thanks a lot! |
Your zipfile is awesome! Very thoughtful of you to include the serial console data and code, that's great. I didn't see the file
Superb! Yes, the printout isn't entirely what you wanted I think, but because you included both the serial log and the code we can deduce exactly what happened, the part of the code where the new method is called: if (RPM == 0){
delay(5000);
res = obd.clearTroubleCodes();
if (res){
SerialUSB.print("Resetting CEL: ");
SerialUSB.println(obd.readUint8());
for (int t = 0; t < 10; t++) {
digitalWrite(DS3, LOW); // turn the LED on by making the voltage LOW
delay(100);
digitalWrite(DS3, HIGH); // turn the LED off by making the voltage HIGH
delay(100);
}
}
} And the output:
The thing is, the line That you couldn't receive res = obd.getCurrentPID(0x31, 2);
if (res){
SerialUSB.print("Result 0x31 (distance since CEL km): ");
uint16_t distance = obd.readUint16();
SerialUSB.println(distance);
} Another plausible reason is that this value will be zero since your test setup isn't really making a lot of distance if you are swapping the engine ;) Take a look at PID There are ways to check if your ECU supports a particular request. Wikipedia has a paragraph on how to interpret the bitmask returned by mode 1 PID The code to do this something along the lines of: res = obd.getCurrentPID(0x00, 4); // This is the block 0x01-0x20
// res = obd.getCurrentPID(0x20, 4); This is the block 0x21-0x40
if (res){
SerialUSB.println("Supported PIDs in range 0x21-0x40");
SerialUSB.print("a: 0x"); Serial.println(obd.readUint8(0), HEX);
SerialUSB.print("b: 0x"); Serial.println(obd.readUint8(1), HEX);
SerialUSB.print("c: 0x"); Serial.println(obd.readUint8(2), HEX);
SerialUSB.print("d: 0x"); Serial.println(obd.readUint8(3), HEX);
} Though, I don't really know if the Also, small tip; if you want to to run with #define OBD9141_DEBUG
#include <OBD9141.h>
#include <Arduino.h>
// Instead of having #define OBD9141_DEBUG here. This is because the flags / defines need to be set before the header file is included, otherwise setting it will have no effect. Alternatively (this is what I used during development), you can pass it as a flag to your compiler (add |
I've added the method to the library! Could you download a fresh version and check whether it also works with the one from the library? (Just to be 100% sure). |
That's awesome! Thanks for all the help! I'll download a fresh copy of the library and try it out tomorrow. I'll experiment with requesting the list of supported PIDs too. |
I downloaded a new copy of the library. None of my sketches work today. I've tried checking the OBD2 port, checking my wiring to the M2, and that the M2 still works. Everything seems good, but nothing will initialize. They all output the same as Console_Log.txt. I feel like I must have a problem with my setup, because the library looks fine. If you wouldn't mind looking at my sketches and letting me know if you see anything that looks wrong. Or if you could give me a really basic debugging sketch that just initializes and outputs as much as possible. Thanks for all the help so far. I want to help add more features if I can get everything to work again. |
Hey,
Yeah, I'm afraid it must be something with the hardware setup, the sketches look fine. Check wiring / pullup resistor / connectors, check voltage on the K-line (should be around battery voltage when no communication is happening). As you said the library is practically unchanged, the only difference is the commit with the new method, but that certainly won't cause the init to fail.
This is tricky, because I have no way to check if the debugging sketch I make works for your hardware. You should try to use the most simple example you have that used to work (probably #include "Arduino.h"
#include "OBD9141.h" into: #include "Arduino.h"
#define OBD9141_DEBUG
#include "OBD9141.h" But this is unlikely to solve the initialization problems you are having. I'm almost certain it's a wiring or hardware problem if it doesn't work with a simple sketch that used to work a few days ago. |
Thanks for the feedback. I'll do more diagnostics tomorrow and get back to you. I just wanted to make sure I didn't have a coding error I was copying over and over into all the sketches. |
after analyzing the method, you are wrong
you can return a report on the successful erasure of error codes, here is my log:
so I used the last returned byte 0хF8 and returned the marker for a successfully executed reset. |
With "No data is returned" I don't mean any bytes are returned, I just mean that the data part of the response will be zero, as per wikipedia.
Hmm... this
This 4 byte long request gets passed to the So the actual bytes transmitted during the request will be:
Since the tx and rx are both connected to the Kline transceiver chip, we will see anything we transmit as an echo on the In your results we see:
If we are to disregard the
Which is exactly what the code and I would expect, the response is the standard 4 byte to the request and the checksum to the bytes |
I understood, but how can I prevent the 0xc7 byte from appearing? increase time OBD9141_REQUEST_ECHO_MS_PER_BYTE? on how much? |
Change it from |
hello, it works, here's the log:
|
Awesome, that's great news, what value did you end up using for |
OBD9141_REQUEST_ECHO_MS_PER_BYTE I did not change, set by default, earned so |
I couldn't find anything in the current code that will put the ECU in Mode 04 to clear trouble codes, the CEL, and/or MIL. If this feature already exists, it needs to be documented.
Assuming it doesn't exist, it should be a simple feature to add as far as I understand it. A function called OBD9141::ClearCodes or similar would be created and it would just send the hex code for Mode 04 to the ECU.
The text was updated successfully, but these errors were encountered: