-
Notifications
You must be signed in to change notification settings - Fork 116
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
Wrong RPM #185
Comments
Everything looks ok except for two things:
|
Wait, I see now that the RPM should actually be 0. I will need to investigate a little more. It would be helpful if you could add more debug prints, especially in |
I put some additional debug code in conditionResponce(). if (numExpectedBytes > numPayChars) {
} else if (numExpectedBytes == numPayChars) { // If there were more payload bytes returned than we expected, test the first uint64_t leadingResponse = 0;
}
} if (leadingResponse > laggingResponse) And here is the result as logfile. The condition numExpectedBytes == numPayChars isn't valid in this example. leading Responce is equal to lagging Responce. In the LOG is an additional \r. |
To see more details, I just extend the debug info. if (debugMode) { if (numExpectedBytes > numPayChars) {
} else if (numExpectedBytes == numPayChars) { LOG: Hope it will help. |
Please format your code snippets properly, thanks |
Don't know how to format it. |
float ELM327::conditionResponse(const uint8_t &numExpectedBytes, const float &scaleFactor, const float &bias) { if (numExpectedBytes > numPayChars) { // If there were more payload bytes returned than we expected, test the first uint64_t leadingResponse = 0; if (leadingResponse > laggingResponse) |
to format arduino code, just type three back ticks "```c++", then a new line and paste all your code. At the end, put a newline then three more back ticks. Here's an example, except I replace backticks with another character so github doesn't format it so you can read it! '''c++ for your logs |
Got it. float ELM327::conditionResponse(const uint8_t &numExpectedBytes,
const float &scaleFactor, const float &bias) {
if (numExpectedBytes > 8) {
if (debugMode)
Serial.println(
F("WARNING: Number of expected response bytes is greater than 8 - "
"returning 0"));
return 0;
}
if (debugMode) {
Serial.print("numExpectedBytes: ");
Serial.println(numExpectedBytes);
Serial.print("numPayChars: ");
Serial.println(numPayChars);
}
if (numExpectedBytes > numPayChars) {
if (debugMode)
Serial.println(
F("WARNING: Number of expected response bytes is greater than the "
"number of payload chars returned by ELM327 - returning 0"));
return 0;
} else if (numExpectedBytes == numPayChars) {
if (debugMode) {
Serial.print("numExpectedBytes == numPayChars Response: ");
Serial.println(response);
}
return ((response * scaleFactor) + bias);
}
// If there were more payload bytes returned than we expected, test the first
// and last bytes in the returned payload and see which gives us a higher
// value. Sometimes ELM327's return leading zeros and others return trailing
// zeros. The following approach gives us the best chance at determining where
// the real data is. Note that if the payload returns BOTH leading and
// trailing zeros, this will not give accurate results!
uint64_t leadingResponse = 0;
for (uint8_t i = 0; i < numExpectedBytes; i++) {
uint8_t payloadIndex = PAYLOAD_LEN - numPayChars + i;
uint8_t bitsOffset = 4 * (numExpectedBytes - i - 1);
leadingResponse |= (ctoi(payload[payloadIndex]) << bitsOffset);
}
if (debugMode) {
Serial.print("leading Responce: ");
Serial.println(leadingResponse);
}
uint64_t laggingResponse = 0;
for (uint8_t i = 0; i < numExpectedBytes; i++) {
uint8_t payloadIndex = PAYLOAD_LEN - numExpectedBytes + i;
uint8_t bitsOffset = 4 * (numExpectedBytes - i - 1);
laggingResponse |= (ctoi(payload[payloadIndex]) << bitsOffset);
}
if (debugMode) {
Serial.print("lagging Responce: ");
Serial.println(laggingResponse);
}
if (leadingResponse > laggingResponse)
return ((float)leadingResponse * scaleFactor) + bias;
return ((float)laggingResponse * scaleFactor) + bias;
}
|
I'll have to look into this a little more, but I think I see your particular issue: Change:
I'm still wondering why the "leading/lagging" part of the code wasn't giving you 0 rpm, but the above updates should cause the |
Just changed it... and it works. Tested it with rpm and kph. Thanks for your support. |
@PowerBroker2 |
I'm encountering the same issue and I'm about to test the fix proposed above, but in the mean time, can someone help me understand why the value 884 is reported when this bug manifests? What's going on here? This might be more of a general programming question; I'm just not following what is happening that the same value is being returned regardless of the response from the ECU. |
Each response char from the ELM327 is a nibble since the response format of the ELM327 is in hex. The code tries to test and see if you have more, less, or exactly the expected number of bytes received from the ELM327. However, we need to convert the number of hex nibbles to number of bytes by dividing by two for a valid comparison. This is where the main bug is and the above edits should fix it. There may be another bug causing the |
I found the issue and fixed it. Try 3.1.0 |
Thanks for the explanation and the fix. I will give it a go shortly. |
Hi, I'm just trying to program a data logger for my motorbike.
It will combine GPS, Angle, rpm and kph.
SD for logging and a Display for setup and control.
Using ELM327 for rpm and kph.
Connection is established.
When I try to read rpm I always get the fix value 884.
In this LOG the ignition was on but the engine was not running.
Got the same when the engine is at different rpm.
Any idea?
LOG:
Clearing input serial buffer
Sending the following command/query: AT D
Received char: O
Received char: K
Received char: \r
Received char: \r
Received char: >
Delimiter found.
All chars received: OK
Clearing input serial buffer
Sending the following command/query: AT Z
Received char: A
Received char: T
Received char: Z
Received char: \r
Received char: \r
Received char: \r
Received char: E
Received char: L
Received char: M
Received char: 3
Received char: 2
Received char: 7
Received char: _
Received char: v
Received char: 1
Received char: .
Received char: 5
Received char: \r
Received char: \r
Received char: >
Delimiter found.
All chars received: ATZELM327v1.5
Clearing input serial buffer
Sending the following command/query: AT E0
Received char: A
Received char: T
Received char: E
Received char: 0
Received char: \r
Received char: O
Received char: K
Received char: \r
Received char: \r
Received char: >
Delimiter found.
All chars received: ATE0OK
Clearing input serial buffer
Sending the following command/query: AT S0
Received char: O
Received char: K
Received char: \r
Received char: \r
Received char: >
Delimiter found.
All chars received: OK
Clearing input serial buffer
Sending the following command/query: AT AL
Received char: O
Received char: K
Received char: \r
Received char: \r
Received char: >
Delimiter found.
All chars received: OK
Clearing input serial buffer
Sending the following command/query: AT ST 00
Received char: O
Received char: K
Received char: \r
Received char: \r
Received char: >
Delimiter found.
All chars received: OK
Clearing input serial buffer
Sending the following command/query: AT TP A0
Received char: O
Received char: K
Received char: \r
Received char: \r
Received char: >
Delimiter found.
All chars received: OK
Connected to ELM327
Service: 1
PID: 12
Normal length query detected
Query string: 010C1
Clearing input serial buffer
Sending the following command/query: 010C1
Received char: S
Received char: E
Received char: A
Received char: R
Received char: C
Received char: H
Received char: I
Received char: N
Received char: G
Received char: .
Received char: .
Received char: .
Received char: \r
Timeout detected with overflow of 0ms
Received: SEARCHING...
ERROR: ELM_TIMEOUT
Service: 1
PID: 12
Normal length query detected
Query string: 010C1
Clearing input serial buffer
Sending the following command/query: 010C1
Received char: 4
Received char: 1
Received char: 0
Received char: C
Received char: 0
Received char: 0
Received char: 0
Received char: 0
Received char: \r
Received char: \r
Received char: >
Delimiter found.
All chars received: 410C0000
Expected response header: 410C
Single response detected
64-bit response: 0
responseByte_0: 0
responseByte_1: 0
responseByte_2: 0
responseByte_3: 0
responseByte_4: 0
responseByte_5: 0
responseByte_6: 0
responseByte_7: 0
884
Service: 1
PID: 12
Normal length query detected
Query string: 010C1
Clearing input serial buffer
Sending the following command/query: 010C1
Received char: 4
Received char: 1
Received char: 0
Received char: C
Received char: 0
Received char: 0
Received char: 0
Received char: 0
Received char: \r
Received char: \r
Received char: >
Delimiter found.
All chars received: 410C0000
Expected response header: 410C
Single response detected
64-bit response: 0
responseByte_0: 0
responseByte_1: 0
responseByte_2: 0
responseByte_3: 0
responseByte_4: 0
responseByte_5: 0
responseByte_6: 0
responseByte_7: 0
884
The text was updated successfully, but these errors were encountered: