-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added function to clear diagnostic trouble codes (DTC) (#7)
* Added function to clear diagnostic trouble codes (DTC) using Service 04 functionality. * Added clearAllStoredDTC function to keywords.txt file * Corrected return value of clearAllStoredDTC function to return 1 upon success
- Loading branch information
1 parent
28be93a
commit 20ef945
Showing
3 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20ef945
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only worked for me when line 714 changed to below:
CAN.write(0x01); // number of additional bytes
20ef945
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how can i clear the DTC based of that?
"int OBD2Class::clearAllStoredDTC()
{
//Function clears stored Diagnostic Trouble Codes (DTC)
}"
thats my .ino code in my arduino sketch |
"#include <CAN.h> // the OBD2 library depends on the CAN library
#include <OBD2.h>
bool running = false; // Variable to control data printing
void setup() {
Serial.begin(9600); // Initializes serial communication with a baud rate of 9600
while (!Serial); // Waits until the serial connection is established
Serial.println(F("OBD2 data printer"));
Serial.println(F("Type 'start' to begin or 'stop' to end printing data."));
// Attempt to connect to the OBD-II CAN bus
while (true) {
Serial.print(F("Attempting to connect to OBD2 CAN bus ... "));
}
Serial.println();
Serial.print("VIN = ");
Serial.println(OBD2.vinRead());
Serial.print("ECU Name = ");
Serial.println(OBD2.ecuNameRead());
Serial.println();
}
void loop() {
// Check if any data is available in the Serial buffer
if (Serial.available()) {
String command = Serial.readStringUntil('\n'); // Read the command until a newline
command.trim(); // Remove any leading/trailing whitespace
}
// Only process PIDs if running is true
if (running) {
for (int pid = 0; pid < 96; pid++) {
processPid(pid);
}
Serial.println(); // Empty line for readability
delay(1000); // Reduced delay for more frequent updates
}
}
void processPid(int pid) {
if (!OBD2.pidSupported(pid)) { // Check if PID is supported
return; // Skip unsupported PIDs
}
Serial.print(OBD2.pidName(pid));
Serial.print(F(" = "));
if (OBD2.pidValueRaw(pid)) {
unsigned long pidRawValue = OBD2.pidReadRaw(pid);
Serial.print(F("0x"));
Serial.print(pidRawValue, HEX);
} else {
float pidValue = OBD2.pidRead(pid);
if (isnan(pidValue)) {
Serial.print("error");
} else {
Serial.print(pidValue);
Serial.print(F(" "));
Serial.print(OBD2.pidUnits(pid));
}
}
delay(500);
Serial.println(); // New line after each PID output
}
"