ELMduino
ELMduino copied to clipboard
ISO_15765_11_BIT_500_KBAUD - findResponse() function not parses correctly the buffered data
Hello all,
I am strugling for a while to read correctly the response recived by the car using ISO_15765_11_BIT_500_KBAUD. Previously I was using ISO_9141_5_BAUD_INIT on another car and everythink was perfect. With ISO 15765 I got always 0 for each request.
Logs below:
Service: 1 PID: 12 Normal length query detected Query string: 010C1 Clearing input serial buffer Sending the following command/query: 010C1 Received char: 0 Received char: 1 Received char: 0 Received char: C Received char: 1 Received char: \r Received char: 4 Received char: 1 Received char: _ Received char: 0 Received char: C Received char: _ Received char: 0 Received char: B Received char: _ Received char: B Received char: 1 Received char: _ Received char: 0 Received char: 0 Received char: _ Received char: 0 Received char: 0 Received char: _ Received char: 0 Received char: 0 Received char: _ Received char: \r Received char: > Delimiter found. All chars received: 010C1410C0BB1000000 Expected response header: 410C Single response detected 64-bit response: responseByte_0: 0 responseByte_1: 0 responseByte_2: 0 responseByte_3: 0 responseByte_4: 0 responseByte_5: 0 responseByte_6: 0 responseByte_7: 0
rpm = 0
You could see that chars are received but latter final response is always 0. I was playing a bit with findResponse() function but I gave up. Do You have any idea what could be the issue?
Thank You. Alex.
Hmm, looks like your ELM327 is responding with more chars than expected. I'll have to look into this and see if there's a straightforward fix
Allright, thanks! I am looking forward for any hint to help me resolve it :)
I updated conditionResponse() so that if the ELM327 responds with extra bytes, the function tests to see if the response has trailing or padding zeros. Based on that test, it should respond with the correct data (thus fixing your issue):
https://github.com/PowerBroker2/ELMduino/blob/7cd508077cb56796f7c78c4fc526c1de36d9ecfe/src/ELMduino.cpp#L358-L406
This update is on the main branch, can you verify it fixes things for you before I tag out a new version? Thanks!
Yeah, absolutly. Will test it tmrw and let You know. Thanks
Now that I think about it, since the ELM327 responds with more hex chars than can fit in a uint64_t, I don't think this fix works. I'll have to try a different approach...
I had opportunity to verify last solution but it seems it is still not working. Please see log below: Service: 1 PID: 4 Normal length query detected Query string: 01041 Clearing input serial buffer Sending the following command/query: 01041 Received char: 0 Received char: 1 Received char: 0 Received char: 4 Received char: 1 Received char: \r Received char: 4 Received char: 1 Received char: _ Received char: 0 Received char: 4 Received char: _ Received char: 7 Received char: 1 Received char: _ Received char: 0 Received char: 0 Received char: _ Received char: 0 Received char: 0 Received char: _ Received char: 0 Received char: 0 Received char: _ Received char: 0 Received char: 0 Received char: _ Received char: \r Received char: > Delimiter found. All chars received: 0104141047100000000 Expected response header: 4104 Single response detected 64-bit response: responseByte_0: 0 responseByte_1: 0 responseByte_2: 0 responseByte_3: 0 responseByte_4: 0 responseByte_5: 0 responseByte_6: 0 responseByte_7: 0 engineLoad() 0
I also checked other PIDs but all seems to be the same.
I think I may have finally fixed the issue here with my recent update to the main branch. Could you give it another test to verify? Thanks!
I'm having a similar problem with the same protocol, RPM always reads 884. Here is what I can get from the serial panel, for some reason I can't select all and copy, only copies whats visible.
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: 1 Received char: A Received char: 9 Received char: 0 Received char: \r Received char: \r Received char: > Delimiter found. All chars received: 410C1A90 Expected response header: 410C Single response detected 64-bit response: responseByte_0: 144 responseByte_1: 26 responseByte_2: 0 responseByte_3: 0 responseByte_4: 0 responseByte_5: 0 responseByte_6: 0 responseByte_7: 0 RPM: 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: 1 Received char: 9 Received char: D Received char: C Received char: \r Received char: \r Received char: > Delimiter found. All chars received: 410C19DC Expected response header: 410C Single response detected 64-bit response: responseByte_0: 220 responseByte_1: 25 responseByte_2: 0 responseByte_3: 0 responseByte_4: 0 responseByte_5: 0 responseByte_6: 0 responseByte_7: 0 RPM: 884 Service: 1 PID: 12 Normal length query detected
@CraigH78 Did you test the main branch? It's different than the latest release
@CraigH78 Did you test the main branch? It's different than the latest release
I downloaded the zip from the main page (https://github.com/PowerBroker2/ELMduino).
Hello @PowerBroker2 , hope you are doing great. I have the same issue than @CraigH78: RPM and all other queries are returning bad values and also don't change at all (RPM doesn't change even when I'm pushing the gas pedal).
I'm using ESP32 and main branch (last commit).
I modified ELMduino.cpp to put some logs:
findResponse():
response = 0;
for (uint8_t i = 0; i < numPayChars; i++)
{
uint8_t payloadIndex = firstDatum + i;
uint8_t bitsOffset = 4 * (numPayChars - i - 1);
response = response | (ctoi(payload[payloadIndex]) << bitsOffset);
}
log_d("response: %08X", (uint32_t)response);
conditionResponse():
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);
}
log_d("leadingResponse: %08X", (uint32_t)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);
}
log_d("laggingResponse: %08X", (uint32_t)laggingResponse);
if (leadingResponse > laggingResponse) {
float leading = ((float)leadingResponse * scaleFactor) + bias;
log_d("leading response: %08X - %.2f", leading, leading);
return leading;
}
float lagging = ((float)laggingResponse * scaleFactor) + bias;
log_d("lagging response: %08X - %.2f", lagging, lagging);
return lagging;
To read the RPM value, I'm using rpm() method in my main code:
case OBD2State::RPM:
{
float rpm = obd2.rpm();
if (obd2.nb_rx_state == ELM_SUCCESS) {
log_i("RPM: %.0f rpm", rpm);
obd2_state = OBD2State::STANDBY;
}
else if (obd2.nb_rx_state != ELM_GETTING_MSG) {
obd2.printError();
obd2_state = OBD2State::STANDBY;
}
} break;
My terminal looks like this:
[ 10231][I][main.cpp:88] usbRead(): -> r
[ 10231][D][main.cpp:142] usbRead(): Querying RPM
Service: 1
PID: 12
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
Received char: 4
Received char: 1
Received char: 0
Received char: C
Received char: 0
Received char: D
Received char: 2
Received char: D
Received char: \r
Received char: \r
Received char: >
Delimiter found.
All chars received: SEARCHING...410C0D2D
Expected response header: 410C
Single response detected
[ 13547][D][ELMduino.cpp:2571] findResponse(): response: 00000D2D
64-bit response:
responseByte_0: 45
responseByte_1: 13
responseByte_2: 0
responseByte_3: 0
responseByte_4: 0
responseByte_5: 0
responseByte_6: 0
responseByte_7: 0
[ 13571][D][ELMduino.cpp:414] conditionResponse(): leadingResponse: 00000DD0
[ 13573][D][ELMduino.cpp:425] conditionResponse(): laggingResponse: 00000DD0
[ 13581][D][ELMduino.cpp:434] conditionResponse(): lagging response: 00000000 - 884.00
[ 13589][I][main.cpp:254] processOBD2(): RPM: 884 rpm
As you can see, the variable response has the correct data (0D2D), but laggingResponse doesn't. I tested by pushing the gas pedal to different RPM levels, like 1000, 2000 and 3000, and the variable response always is correct. But laggingResponse (variable used as rpm() return value) is never correct.
I'll continue testing. Maybe this information helps you.
@PowerBroker2 I changed this line: https://github.com/PowerBroker2/ELMduino/blob/eabbb1a2e8e82d8fed1b758c0d893bc46efbe171/src/ELMduino.cpp#L393
to:
else if ((numExpectedBytes * 2) == numPayChars) {
And now it's working. That's because, as I understand, the variable numPayChars represents a nibble. Example:
response: 410C0D41recBytes: 8 (410C0D41)numPayChars: 4 (0D41)
So, when rpm() is called, the function processPID() would need the parameter numExpectedBytes to be 4.
There is another problem. When I try to use functions supportedPIDs_xx_xx(), there is a bad cast (float to uint32_t), which gives me a bad number. See my terminal (additional logs inserted):
[229977][I][main.cpp:88] usbRead(): -> 1
[229977][D][main.cpp:118] usbRead(): Querying Supported PIDs 1-20
Service: 1
PID: 0
Normal length query detected
Query string: 01001
Clearing input serial buffer
Sending the following command/query: 01001
Received char: 4
Received char: 1
Received char: 0
Received char: 0
Received char: B
Received char: E
Received char: 3
Received char: E
Received char: B
Received char: 8
Received char: 1
Received char: 1
Received char: \r
Received char: \r
Received char: >
Delimiter found.
All chars received: 4100BE3EB811
Expected response header: 4100
[230124][D][ELMduino.cpp:2538] findResponse(): firstHeadIndex: 0
[230129][D][ELMduino.cpp:2539] findResponse(): secondHeadIndex: 4294967295
[230137][D][ELMduino.cpp:2548] findResponse(): firstDatum: 4
Single response detected
[230154][D][ELMduino.cpp:2569] findResponse(): recBytes: 12
[230154][D][ELMduino.cpp:2570] findResponse(): numPayChars: 8
[230158][D][ELMduino.cpp:2579] findResponse(): p_idx: 4 - offset: 28 - val: B
[230166][D][ELMduino.cpp:2579] findResponse(): p_idx: 5 - offset: 24 - val: E
[230174][D][ELMduino.cpp:2579] findResponse(): p_idx: 6 - offset: 20 - val: 3
[230182][D][ELMduino.cpp:2579] findResponse(): p_idx: 7 - offset: 16 - val: E
[230189][D][ELMduino.cpp:2579] findResponse(): p_idx: 8 - offset: 12 - val: B
[230197][D][ELMduino.cpp:2579] findResponse(): p_idx: 9 - offset: 8 - val: 8
[230205][D][ELMduino.cpp:2579] findResponse(): p_idx: 10 - offset: 4 - val: 1
[230213][D][ELMduino.cpp:2579] findResponse(): p_idx: 11 - offset: 0 - val: 1
[230221][D][ELMduino.cpp:2582] findResponse(): response: BE3EB811
64-bit response:
responseByte_0: 17
responseByte_1: 184
responseByte_2: 62
responseByte_3: 190
responseByte_4: 255
responseByte_5: 255
responseByte_6: 255
responseByte_7: 255
[230248][D][ELMduino.cpp:395] conditionResponse(): numExpectedBytes == numPayChars: 00000000 - 1844674407376.00
[230255][I][main.cpp:186] processOBD2(): Supported PIDs 01-20: 0xFFFFFFFF
@alkonosst, thanks for the fix, I was not looking forward to relearning how the lib works to address this issue again, lol. As for the supportedPIDs_xx_xx() error - what is the expected output in your case? (I've never actually used this functionality myself)
@PowerBroker2 in the last example, supportedPIDs_01_20() should return BE3EB811 (that's the 'response' variable value), which contains the bit mask for the first 32 PID values. But actually returns FFFFFFFF. I think it is because you are casting a float to uint32_t, and the value changes because of that conversion:
https://github.com/PowerBroker2/ELMduino/blob/eabbb1a2e8e82d8fed1b758c0d893bc46efbe171/src/ELMduino.cpp#L581-L584
So far I've read float PIDs without issue, like rpm(), fuelLevel() and throttle().
@alkonosst & @PowerBroker2 - Thank you both, that did the trick!
@PowerBroker2 Hello all,
I'm having the same problem as @CraigH78, I made the bluetooth connection with my OBDII ELM327, I put the protocol used by my car, and I only get a rpm measurement of 884. So, I tried other protocols and, some I didn't get measurements and others I got the same result for rpm. I'm using the latest version of the library (3.0.2). I'm a student and I'm doing a final project in engineering, and I'm developing this project and I grabbed that part. From what I understood in the previous comments, this problem is in the library and I couldn't fix it. Can you help me please?
I'm uploading my full code here, thanks!
#include <ELMduino.h> #include <BluetoothSerial.h>
// esp_spp_sec_t sec_mask = ESP_SPP_SEC_NONE; // esp_spp_role_t role = ESP_SPP_ROLE_SLAVE;
BluetoothSerial SerialBT; ELM327 myELM327; //MAC = "00:10:cc:4f:36:03"; uint8_t MAC[6] = {0x00, 0x10, 0xcc, 0x4f, 0x36, 0x03}; bool connectOBD; int channel = 0; uint32_t rpm = 0;
void setup()
{
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
SerialBT.begin("ESP32", true);
//connectOBD = SerialBT.connect(MAC, channel, sec_mask, role);
connectOBD = SerialBT.connect(MAC);
if (connectOBD)
{
Serial.println("OBD - Phase 1");
if (myELM327.begin(SerialBT,false,2000,ISO_9141_5_BAUD_INIT))
{
Serial.println("OBD - Phase 2");
digitalWrite(LED_BUILTIN, HIGH);
}
}
}
void loop() { float tempRPM = myELM327.rpm(); if (myELM327.nb_rx_state == ELM_SUCCESS) { rpm = (uint32_t)tempRPM; Serial.print("RPM: "); Serial.println(rpm); } else if (myELM327.nb_rx_state != ELM_GETTING_MSG) myELM327.printError(); }
Try using what's on the main branch instead of the release
@PowerBroker2 Sorry but I didn't understand what you meant by that, could you explain? do you think the problem is in my code?
@PowerBroker2 I was able to understand what you said, and my answer is yes, I downloaded the library directly from the github site, from the main branch. I redid the entire library installation process and did the test again today and the rpm is still 884. My monitor serial is:
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: responseByte_0: 0 responseByte_1: 0 responseByte_2: 0 responseByte_3: 0 responseByte_4: 0 responseByte_5: 0 responseByte_6: 0 responseByte_7: 0 RPM: 884
@PowerBroker2 Hello all, I managed to solve the problem. The file ELMduino.cpp that is in the main branch is without the changes made by @alkonosst. So I made the same changes he made and it worked. Thanks!
Hello guys. Hope everybody doing great!
The
else if ((numExpectedBytes * 2) == numPayChars) {
solves the problem for me if I want to get just one pid information. RPM or KPH in my case.
The code is below.
#include "BluetoothSerial.h"
#include "ELMduino.h"
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
#include <SPI.h>
#include "EEPROM.h"
TFT_eSPI tft = TFT_eSPI();
//#define USE_NAME
const char *pin = "1234";
#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
#endif
BluetoothSerial SerialBT;
ELM327 myELM327;
int displayNum=0;
#define ELM_PORT SerialBT
uint32_t targetTime = 0;
uint16_t PAYLOAD_LEN;
//int PAYLOAD_LEN;
uint32_t rpm = 0;
uint32_t kph = 0;
uint32_t ECT = -1;
uint32_t oil = -1;
float fuelLevel = 0; // in %
//float tempBATTERY = myELM327.queryPID(SERVICE_01,CONTROL_MODULE_VOLTAGE);
//float tempCOOLANT = myELM327.queryPID(SERVICE_01,ENGINE_COOLANT_TEMP);
//float tempINTAKE = myELM327.queryPID(SERVICE_01,INTAKE_AIR_TEMP);
//float tempOIL = myELM327.queryPID(SERVICE_01,ENGINE_OIL_TEMP);
//float tempLOAD= myELM327.queryPID(SERVICE_01,ENGINE_LOAD);
//void(* resetFunc) (void) = 0;
#ifdef USE_NAME
String slaveName = "OBDII";
#else
String MACadd = "66:1e:31:f3:c1:d5"; // This only for printing
//uint8_t address[6] = {0x75, 0x57, 0x14, 0x21, 0x04, 0xf6};
//uint8_t address[6] = {0x66, 0x1e, 0x31, 0xf3, 0xc1, 0xd5};
////uint8_t address[6] = {0x00, 0x10, 0xcc, 0x4f, 0x36, 0x03};
uint8_t address[6] = {0x00, 0x1d, 0xa5, 0x69, 0x45, 0x45};
//uint8_t address[6] = {0x87, 0x78, 0x0f, 0x05, 0x91, 0xdb};
//uint8_t address[6] = {0x39, 0xd3, 0xa4, 0x9c, 0xea, 0x57};
#endif
String myName = "ESP32-BT-Master";
void setup()
{
bool connected;
tft.init();
tft.setTextColor(random(0xFFFF));
tft.drawString("Connecting to OBD-II", 10, 10, 4);
tft.setTextFont(4);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
targetTime = millis() + 1000;
Serial.begin(115200);
SerialBT.begin(myName, true);
Serial.printf("The device \"%s\" started in master mode, make sure slave BT device is on!\n", myName.c_str());
#ifndef USE_NAME
SerialBT.setPin(pin);
Serial.println("Using PIN");
#endif
#ifdef USE_NAME
connected = SerialBT.connect(slaveName);
Serial.printf("Connecting to slave BT device named \"%s\"\n", slaveName.c_str());
#else
connected = SerialBT.connect(address);
Serial.print("Connecting to slave BT device with MAC "); Serial.println(MACadd);
#endif
if(connected) {
Serial.println("Connected Successfully!");
} else {
while(!SerialBT.connected(10000)) {
Serial.println("Failed to connect. Make sure remote device is available and in range, then restart app1.");
while(1);
}
}
myELM327.begin(ELM_PORT, true);
}
void getKPH()
{
float tempSPEED=myELM327.kph();
if (myELM327.nb_rx_state == ELM_SUCCESS)
{
kph = (uint32_t)tempSPEED;
Serial.print("Speed: "); Serial.println(kph);
}
else if (myELM327.nb_rx_state !=ELM_GETTING_MSG)
myELM327.printError();
}
void getRPM()
{
float tempRPM=myELM327.rpm();
if (myELM327.nb_rx_state==ELM_SUCCESS)
{
rpm=(uint32_t)tempRPM;
Serial.print("RPM: "); Serial.println(rpm);
}
else if (myELM327.nb_rx_state !=ELM_GETTING_MSG)
myELM327.printError();
}
void loop()
{
getRPM();
{
tft.setCursor(30, 60);
tft.print("RPM: "); tft.print(rpm);
tft.fillRect(240, 240, 0, 0, TFT_BLACK);
}
delay(50);
//getKPH();
{
tft.setCursor(30, 30);
tft.print("Speed: "); tft.print(kph); tft.println(" km/h ");
tft.fillRect(240, 240, 0, 0, TFT_BLACK);
}
delay(50);
}
void printError()
{
Serial.print("Received: ");
for (byte i = 0; i < PAYLOAD_LEN; i++) {
Serial.write(myELM327.payload[i]);
Serial.println(rpm);
tft.fillRect(98, 100, 70, 85, TFT_BLACK);
}
if (myELM327.nb_rx_state == ELM_SUCCESS)
{Serial.println(F("\tELM_SUCCESS"));
tft.drawString("ELM SUCCESS", 10, 10, 4);}
//display.drawString(60, 20, String("\tELM_SUCCESS"));}
else if (myELM327.nb_rx_state == ELM_NO_RESPONSE)
{Serial.println(F("\tERROR: ELM_NO_RESPONSE"));
tft.drawString("ERROR: ELM_NO_RESPONSE", 10, 10, 4);}
//display.drawString(60, 20, String("\tERROR: ELM_NO_RESPONSE"));}
else if (myELM327.nb_rx_state == ELM_BUFFER_OVERFLOW)
{Serial.println(F("\tERROR: ELM_BUFFER_OVERFLOW"));
tft.drawString("ERROR: ELM_BUFFER_OVERFLOW", 10, 10, 4);}
//display.drawString(60, 20, String("\tERROR: ELM_BUFFER_OVERFLOW"));}
else if (myELM327.nb_rx_state == ELM_UNABLE_TO_CONNECT)
{Serial.println(F("\tERROR: ELM_UNABLE_TO_CONNECT"));
tft.drawString("ERROR: ELM_UNABLE_TO_CONNECT", 10, 10, 4);}
//display.drawString(60, 20, String("\tERROR: ELM_UNABLE_TO_CONNECT"));}
else if (myELM327.nb_rx_state == ELM_NO_DATA)
{Serial.println(F("\tERROR: ELM_NO_DATA"));
tft.drawString("ERROR: ELM_NO_DATA", 10, 10, 4);}
//display.drawString(60, 20, String("\tERROR: ELM_NO_DATA"));}
else if (myELM327.nb_rx_state == ELM_STOPPED)
{Serial.println(F("\tERROR: ELM_STOPPED"));
tft.drawString("ERROR: ELM_STOPPED", 10, 10, 4);}
//display.drawString(60, 20, String("\tERROR: ELM_STOPPED"));}
else if (myELM327.nb_rx_state == ELM_TIMEOUT)
{Serial.println(F("\tERROR: ELM_TIMEOUT"));
tft.drawString("ERROR: ELM_TIMEOUT", 10, 10, 4);}
//display.drawString(60, 20, String("\tERROR: ELM_TIMEOUT"));}
else if (myELM327.nb_rx_state == ELM_TIMEOUT)
{Serial.println(F("\tERROR: ELM_GENERAL_ERROR"));
tft.drawString("ERROR: ELM_GENERAL_ERROR", 10, 10, 4);}
//display.drawString(60, 20, String("\tERROR: ELM_GENERAL_ERROR"));}
delay(2000);
//resetFunc(); //call reset
}
But When I uncomment getKPH() in loop and want to get both gauges, sometimes I get true results but often the rpm is 0 or 884 and kph is 0 or 208. Here is the debug:
18:20:44.204 -> Connecting to slave BT device with MAC 66:1e:31:f3:c1:d5
18:20:44.204 -> Connected Successfully!
18:20:44.204 -> Clearing input serial buffer
18:20:44.204 -> Sending the following command/query: AT D
18:20:44.251 -> Received char: \r
18:20:44.251 -> Received char: O
18:20:44.251 -> Received char: K
18:20:44.251 -> Received char: \r
18:20:44.251 -> Received char: \r
18:20:44.251 -> Received char: >
18:20:44.251 -> Delimiter found.
18:20:44.251 -> All chars received: OK
18:20:44.374 -> Clearing input serial buffer
18:20:44.374 -> Sending the following command/query: AT Z
18:20:44.374 -> Received char: A
18:20:44.374 -> Received char: T
18:20:44.374 -> Received char: _
18:20:44.374 -> Received char: Z
18:20:44.374 -> Received char: \r
18:20:45.184 -> Received char: \r
18:20:45.216 -> Received char: \r
18:20:45.216 -> Received char: E
18:20:45.216 -> Received char: L
18:20:45.216 -> Received char: M
18:20:45.216 -> Received char: 3
18:20:45.216 -> Received char: 2
18:20:45.216 -> Received char: 7
18:20:45.216 -> Received char: _
18:20:45.216 -> Received char: v
18:20:45.216 -> Received char: 1
18:20:45.216 -> Received char: .
18:20:45.216 -> Received char: 5
18:20:45.216 -> Received char: \r
18:20:45.216 -> Received char: \r
18:20:45.216 -> Received char: >
18:20:45.216 -> Delimiter found.
18:20:45.216 -> All chars received: ATZELM327v1.5
18:20:45.295 -> Clearing input serial buffer
18:20:45.295 -> Sending the following command/query: AT E0
18:20:45.340 -> Received char: A
18:20:45.340 -> Received char: T
18:20:45.340 -> Received char: _
18:20:45.340 -> Received char: E
18:20:45.340 -> Received char: 0
18:20:45.340 -> Received char: \r
18:20:45.340 -> Received char: O
18:20:45.340 -> Received char: K
18:20:45.340 -> Received char: \r
18:20:45.340 -> Received char: \r
18:20:45.340 -> Received char: >
18:20:45.340 -> Delimiter found.
18:20:45.340 -> All chars received: ATE0OK
18:20:45.455 -> Clearing input serial buffer
18:20:45.455 -> Sending the following command/query: AT S0
18:20:45.493 -> Received char: O
18:20:45.493 -> Received char: K
18:20:45.493 -> Received char: \r
18:20:45.493 -> Received char: \r
18:20:45.493 -> Received char: >
18:20:45.493 -> Delimiter found.
18:20:45.493 -> All chars received: OK
18:20:45.586 -> Clearing input serial buffer
18:20:45.586 -> Sending the following command/query: AT AL
18:20:45.632 -> Received char: O
18:20:45.632 -> Received char: K
18:20:45.632 -> Received char: \r
18:20:45.632 -> Received char: \r
18:20:45.632 -> Received char: >
18:20:45.632 -> Delimiter found.
18:20:45.632 -> All chars received: OK
18:20:45.725 -> Clearing input serial buffer
18:20:45.725 -> Sending the following command/query: AT ST 00
18:20:45.771 -> Received char: O
18:20:45.771 -> Received char: K
18:20:45.771 -> Received char: \r
18:20:45.771 -> Received char: \r
18:20:45.771 -> Received char: >
18:20:45.771 -> Delimiter found.
18:20:45.771 -> All chars received: OK
18:20:45.865 -> Clearing input serial buffer
18:20:45.865 -> Sending the following command/query: AT TP A0
18:20:45.904 -> Received char: O
18:20:45.904 -> Received char: K
18:20:45.941 -> Received char: \r
18:20:45.941 -> Received char: \r
18:20:45.941 -> Received char: >
18:20:45.941 -> Delimiter found.
18:20:45.941 -> All chars received: OK
18:20:45.941 -> Service: 1
18:20:45.941 -> PID: 12
18:20:45.941 -> Normal length query detected
18:20:45.941 -> Query string: 010C1
18:20:45.941 -> Clearing input serial buffer
18:20:45.941 -> Sending the following command/query: 010C1
18:20:45.988 -> Received char: S
18:20:46.019 -> Received char: E
18:20:46.096 -> Received char: A
18:20:46.143 -> Received char: R
18:20:46.188 -> Received char: C
18:20:46.235 -> Received char: H
18:20:46.281 -> Received char: I
18:20:46.360 -> Received char: N
18:20:46.407 -> Received char: G
18:20:46.453 -> Received char: .
18:20:46.500 -> Received char: .
18:20:46.546 -> Received char: .
18:20:46.592 -> Received char: \r
18:20:46.951 -> Timeout detected with overflow of 33ms
18:20:46.951 -> Received: SEARCHING...
18:20:46.951 -> ERROR: ELM_TIMEOUT
18:20:47.121 -> Service: 1
18:20:47.121 -> PID: 13
18:20:47.121 -> Normal length query detected
18:20:47.121 -> Query string: 010D1
18:20:47.121 -> Clearing input serial buffer
18:20:47.121 -> Sending the following command/query: 010D1
18:20:47.200 -> Received char: S
18:20:47.245 -> Received char: T
18:20:47.324 -> Received char: O
18:20:47.370 -> Received char: P
18:20:47.464 -> Received char: P
18:20:47.510 -> Received char: E
18:20:47.557 -> Received char: D
18:20:47.603 -> Received char: \r
18:20:47.648 -> Received char: \r
18:20:47.725 -> Received char: >
18:20:47.725 -> Delimiter found.
18:20:47.725 -> All chars received: STOPPED
18:20:47.725 -> ELM responded with errror "STOPPED"
18:20:47.725 -> Received: STOPPED
18:20:47.725 -> ERROR: ELM_STOPPED
18:20:47.896 -> Service: 1
18:20:47.896 -> PID: 12
18:20:47.896 -> Normal length query detected
18:20:47.896 -> Query string: 010C1
18:20:47.896 -> Clearing input serial buffer
18:20:47.896 -> Sending the following command/query: 010C1
18:20:47.942 -> Received char: 4
18:20:47.988 -> Received char: 1
18:20:48.035 -> Received char: 1
18:20:48.066 -> Received char: 0
18:20:48.144 -> Received char: 0
18:20:48.190 -> Received char: 0
18:20:48.237 -> Received char: D
18:20:48.284 -> Received char: 9
18:20:48.330 -> Received char: \r
18:20:48.409 -> Received char: \r
18:20:48.454 -> Received char: >
18:20:48.454 -> Delimiter found.
18:20:48.454 -> All chars received: 411000D9
18:20:48.454 -> Expected response header: 410C
18:20:48.454 -> Response not detected
18:20:48.454 -> WARNING: Number of expected response bytes is greater than the number of payload chars returned by ELM327 - returning 0
18:20:48.454 -> Speed: 0
18:20:48.532 -> Service: 1
18:20:48.532 -> PID: 12
18:20:48.532 -> Normal length query detected
18:20:48.532 -> Query string: 010C1
18:20:48.532 -> Clearing input serial buffer
18:20:48.532 -> Sending the following command/query: 010C1
18:20:48.579 -> Received char: 4
18:20:48.624 -> Received char: 1
18:20:48.671 -> Received char: 0
18:20:48.717 -> Received char: C
18:20:48.794 -> Received char: 0
18:20:48.840 -> Received char: B
18:20:48.886 -> Received char: D
18:20:48.933 -> Received char: C
18:20:48.979 -> Received char: \r
18:20:49.057 -> Received char: \r
18:20:49.103 -> Received char: >
18:20:49.103 -> Delimiter found.
18:20:49.103 -> All chars received: 410C0BDC
18:20:49.103 -> Expected response header: 410C
18:20:49.103 -> Single response detected
18:20:49.103 -> 64-bit response:
18:20:49.103 -> responseByte_0: 220
18:20:49.103 -> responseByte_1: 11
18:20:49.103 -> responseByte_2: 0
18:20:49.103 -> responseByte_3: 0
18:20:49.103 -> responseByte_4: 0
18:20:49.103 -> responseByte_5: 0
18:20:49.103 -> responseByte_6: 0
18:20:49.103 -> responseByte_7: 0
18:20:49.103 -> Speed: 208
18:20:49.180 -> Service: 1
18:20:49.180 -> PID: 12
18:20:49.180 -> Normal length query detected
18:20:49.180 -> Query string: 010C1
18:20:49.180 -> Clearing input serial buffer
18:20:49.180 -> Sending the following command/query: 010C1
18:20:49.226 -> Received char: 4
18:20:49.304 -> Received char: 1
18:20:49.336 -> Received char: 0
18:20:49.383 -> Received char: C
18:20:49.429 -> Received char: 0
18:20:49.507 -> Received char: B
18:20:49.554 -> Received char: D
18:20:49.600 -> Received char: C
18:20:49.647 -> Received char: \r
18:20:49.678 -> Received char: \r
18:20:49.788 -> Received char: >
18:20:49.788 -> Delimiter found.
18:20:49.788 -> All chars received: 410C0BDC
18:20:49.788 -> Expected response header: 410C
18:20:49.788 -> Single response detected
18:20:49.788 -> 64-bit response:
18:20:49.788 -> responseByte_0: 220
18:20:49.788 -> responseByte_1: 11
18:20:49.788 -> responseByte_2: 0
18:20:49.788 -> responseByte_3: 0
18:20:49.788 -> responseByte_4: 0
18:20:49.788 -> responseByte_5: 0
18:20:49.788 -> responseByte_6: 0
18:20:49.788 -> responseByte_7: 0
18:20:49.788 -> Speed: 208
18:20:49.820 -> Service: 1
18:20:49.820 -> PID: 12
18:20:49.820 -> Normal length query detected
18:20:49.820 -> Query string: 010C1
18:20:49.820 -> Clearing input serial buffer
18:20:49.820 -> Sending the following command/query: 010C1
18:20:49.897 -> Received char: 4
18:20:49.928 -> Received char: 1
18:20:50.005 -> Received char: 0
18:20:50.052 -> Received char: C
18:20:50.098 -> Received char: 0
18:20:50.144 -> Received char: B
18:20:50.191 -> Received char: D
18:20:50.268 -> Received char: C
18:20:50.315 -> Received char: \r
18:20:50.360 -> Received char: \r
18:20:50.438 -> Received char: >
18:20:50.438 -> Delimiter found.
18:20:50.438 -> All chars received: 410C0BDC
18:20:50.438 -> Expected response header: 410C
18:20:50.438 -> Single response detected
18:20:50.438 -> 64-bit response:
18:20:50.438 -> responseByte_0: 220
18:20:50.438 -> responseByte_1: 11
18:20:50.438 -> responseByte_2: 0
18:20:50.438 -> responseByte_3: 0
18:20:50.438 -> responseByte_4: 0
18:20:50.438 -> responseByte_5: 0
18:20:50.438 -> responseByte_6: 0
18:20:50.438 -> responseByte_7: 0
18:20:50.438 -> Speed: 208
18:20:50.469 -> Service: 1
18:20:50.469 -> PID: 12
18:20:50.469 -> Normal length query detected
18:20:50.469 -> Query string: 010C1
18:20:50.469 -> Clearing input serial buffer
18:20:50.469 -> Sending the following command/query: 010C1
18:20:50.561 -> Received char: 4
18:20:50.607 -> Received char: 1
18:20:50.654 -> Received char: 0
18:20:50.700 -> Received char: C
18:20:50.731 -> Received char: 0
18:20:50.824 -> Received char: B
18:20:50.871 -> Received char: D
18:20:50.917 -> Received char: C
18:20:50.949 -> Received char: \r
18:20:51.028 -> Received char: \r
18:20:51.105 -> Received char: >
18:20:51.105 -> Delimiter found.
18:20:51.105 -> All chars received: 410C0BDC
18:20:51.105 -> Expected response header: 410C
18:20:51.105 -> Single response detected
18:20:51.105 -> 64-bit response:
18:20:51.105 -> responseByte_0: 220
18:20:51.105 -> responseByte_1: 11
18:20:51.105 -> responseByte_2: 0
18:20:51.105 -> responseByte_3: 0
18:20:51.105 -> responseByte_4: 0
18:20:51.105 -> responseByte_5: 0
18:20:51.105 -> responseByte_6: 0
18:20:51.105 -> responseByte_7: 0
18:20:51.105 -> Speed: 208
18:20:51.152 -> Service: 1
18:20:51.152 -> PID: 12
18:20:51.152 -> Normal length query detected
18:20:51.152 -> Query string: 010C1
18:20:51.152 -> Clearing input serial buffer
18:20:51.152 -> Sending the following command/query: 010C1
18:20:51.198 -> Received char: 4
18:20:51.276 -> Received char: 1
18:20:51.322 -> Received char: 0
18:20:51.368 -> Received char: C
18:20:51.415 -> Received char: 0
18:20:51.462 -> Received char: B
18:20:51.509 -> Received char: D
18:20:51.572 -> Received char: C
18:20:51.618 -> Received char: \r
18:20:51.665 -> Received char: \r
18:20:51.758 -> Received char: >
18:20:51.758 -> Delimiter found.
18:20:51.758 -> All chars received: 410C0BDC
18:20:51.758 -> Expected response header: 410C
18:20:51.758 -> Single response detected
18:20:51.758 -> 64-bit response:
18:20:51.758 -> responseByte_0: 220
18:20:51.758 -> responseByte_1: 11
18:20:51.758 -> responseByte_2: 0
18:20:51.758 -> responseByte_3: 0
18:20:51.758 -> responseByte_4: 0
18:20:51.758 -> responseByte_5: 0
18:20:51.758 -> responseByte_6: 0
18:20:51.758 -> responseByte_7: 0
18:20:51.758 -> Speed: 208
18:20:51.805 -> Service: 1
18:20:51.805 -> PID: 12
18:20:51.805 -> Normal length query detected
18:20:51.805 -> Query string: 010C1
18:20:51.805 -> Clearing input serial buffer
18:20:51.805 -> Sending the following command/query: 010C1
18:20:51.882 -> Received char: 4
18:20:51.928 -> Received char: 1
18:20:51.960 -> Received char: 0
18:20:52.039 -> Received char: C
18:20:52.085 -> Received char: 0
18:20:52.131 -> Received char: B
18:20:52.163 -> Received char: D
18:20:52.240 -> Received char: C
18:20:52.285 -> Received char: \r
18:20:52.332 -> Received char: \r
18:20:52.395 -> Received char: >
18:20:52.395 -> Delimiter found.
18:20:52.395 -> All chars received: 410C0BDC
18:20:52.395 -> Expected response header: 410C
18:20:52.395 -> Single response detected
18:20:52.395 -> 64-bit response:
18:20:52.395 -> responseByte_0: 220
18:20:52.395 -> responseByte_1: 11
18:20:52.395 -> responseByte_2: 0
18:20:52.395 -> responseByte_3: 0
18:20:52.395 -> responseByte_4: 0
18:20:52.395 -> responseByte_5: 0
18:20:52.395 -> responseByte_6: 0
18:20:52.395 -> responseByte_7: 0
18:20:52.395 -> Speed: 208
18:20:52.473 -> Service: 1
18:20:52.473 -> PID: 12
18:20:52.473 -> Normal length query detected
18:20:52.473 -> Query string: 010C1
18:20:52.473 -> Clearing input serial buffer
18:20:52.473 -> Sending the following command/query: 010C1
18:20:52.520 -> Received char: 4
18:20:52.599 -> Received char: 1
18:20:52.645 -> Received char: 0
18:20:52.691 -> Received char: C
18:20:52.737 -> Received char: 0
18:20:52.784 -> Received char: B
18:20:52.831 -> Received char: D
18:20:52.877 -> Received char: C
18:20:52.956 -> Received char: \r
18:20:53.002 -> Received char: \r
18:20:53.080 -> Received char: >
18:20:53.080 -> Delimiter found.
18:20:53.080 -> All chars received: 410C0BDC
18:20:53.080 -> Expected response header: 410C
18:20:53.080 -> Single response detected
18:20:53.080 -> 64-bit response:
18:20:53.080 -> responseByte_0: 220
18:20:53.080 -> responseByte_1: 11
18:20:53.080 -> responseByte_2: 0
18:20:53.080 -> responseByte_3: 0
18:20:53.080 -> responseByte_4: 0
18:20:53.080 -> responseByte_5: 0
18:20:53.080 -> responseByte_6: 0
18:20:53.080 -> responseByte_7: 0
18:20:53.080 -> Speed: 208
18:20:53.126 -> Service: 1
18:20:53.126 -> PID: 12
18:20:53.126 -> Normal length query detected
18:20:53.126 -> Query string: 010C1
18:20:53.126 -> Clearing input serial buffer
18:20:53.126 -> Sending the following command/query: 010C1
18:20:53.204 -> Received char: 4
18:20:53.251 -> Received char: 1
18:20:53.297 -> Received char: 0
18:20:53.343 -> Received char: C
18:20:53.389 -> Received char: 0
18:20:53.420 -> Received char: B
18:20:53.514 -> Received char: D
18:20:53.561 -> Received char: C
18:20:53.607 -> Received char: \r
18:20:53.654 -> Received char: \r
18:20:53.732 -> Received char: >
18:20:53.732 -> Delimiter found.
18:20:53.732 -> All chars received: 410C0BDC
18:20:53.732 -> Expected response header: 410C
18:20:53.732 -> Single response detected
18:20:53.732 -> 64-bit response:
18:20:53.732 -> responseByte_0: 220
18:20:53.732 -> responseByte_1: 11
18:20:53.732 -> responseByte_2: 0
18:20:53.732 -> responseByte_3: 0
18:20:53.732 -> responseByte_4: 0
18:20:53.732 -> responseByte_5: 0
18:20:53.732 -> responseByte_6: 0
18:20:53.732 -> responseByte_7: 0
18:20:53.732 -> Speed: 208
18:20:53.764 -> Service: 1
18:20:53.764 -> PID: 12
18:20:53.764 -> Normal length query detected
18:20:53.764 -> Query string: 010C1
18:20:53.764 -> Clearing input serial buffer
18:20:53.764 -> Sending the following command/query: 010C1
Any advice please. Maybe somthing wrong with code getting pid information sequence. Thank you.
.....UPDATE...... I somehow solved the previous problem by editing my loop.
void loop()
{
switch (obd_state)
{
case ENG_RPM:
{
rpm = myELM327.rpm();
if (myELM327.nb_rx_state == ELM_SUCCESS)
{
Serial.print("rpm: ");
Serial.println(rpm);
tft.setCursor(5, 60);
tft.print("RPM: "); tft.print(rpm);
obd_state = SPEED;
}
else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
{
myELM327.printError();
obd_state = SPEED;
}
break;
}
case SPEED:
{
kph = myELM327.kph();
if (myELM327.nb_rx_state == ELM_SUCCESS)
{
Serial.print("kph: ");
Serial.println(kph);
tft.setCursor(5, 30);
tft.print("SPEED: "); tft.print(kph);
tft.setCursor(150, 30);
tft.println(" kph ");
obd_state = ENG_RPM;
}
else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
{
myELM327.printError();
obd_state = ENG_RPM;
}
break;
}
}
}
Almost everything working good, but the next problem is getting wrong header than was expected about every 5-10 seconds. And rpm returns to 884 and kph returning 208.
11:45:53.034 -> Normal length query detected
11:45:53.034 -> Query string: 010D1
11:45:53.034 -> Clearing input serial buffer
11:45:53.034 -> Sending the following command/query: 010D1
11:45:53.068 -> Received char: 4
11:45:53.068 -> Received char: 1
11:45:53.068 -> Received char: 0
11:45:53.068 -> Received char: C
11:45:53.068 -> Received char: 3
11:45:53.068 -> Received char: 4
11:45:53.068 -> Received char: 2
11:45:53.068 -> Received char: 0
11:45:53.068 -> Received char: \r
11:45:53.068 -> Received char: \r
11:45:53.068 -> Received char: >
11:45:53.068 -> Delimiter found.
11:45:53.068 -> All chars received: 410C3420
11:45:53.068 -> Expected response header: 410D
11:45:53.068 -> Response not detected
11:45:53.068 -> kph: 208
11:45:53.068 -> Service: 1
11:45:53.068 -> PID: 12
Hello guys. Hope everybody doing great! The else if ((numExpectedBytes * 2) == numPayChars) solve my problem to.
But now, i discovered other other problems for my case. My car uses the '3' protocol, and how long to use other functions unfortunately the return is ELM_NO_DATA.
I'm sending all the data I'm able to read:
void loop() { switch(decisao) { case 1: // Velocidade (km/h) { valorLido = myELM327.kph(); if (myELM327.nb_rx_state == ELM_SUCCESS) { decisao++; reset = 0; kph = valorLido; } else if (myELM327.nb_rx_state == ELM_NO_DATA) reset++; break; } case 2: // Posição do acelerador em % { valorLido = myELM327.throttle(); if (myELM327.nb_rx_state == ELM_SUCCESS) { decisao++; reset = 0; if (valorLido != 0) { throttle = valorLido; } } else if (myELM327.nb_rx_state == ELM_NO_DATA) reset++; break; } case 3: // Temperatura do ar de admissão em C { valorLido = myELM327.intakeAirTemp(); if (myELM327.nb_rx_state == ELM_SUCCESS) { decisao++; reset = 0; if (valorLido != 0) { intakeAirTemp = valorLido; } } else if (myELM327.nb_rx_state == ELM_NO_DATA) reset++; break; } case 4: // Temperatura atual do líquido de arrefecimento { valorLido = myELM327.engineCoolantTemp(); if (myELM327.nb_rx_state == ELM_SUCCESS) { decisao++; reset = 0; if (valorLido != 0) { engineCoolantTemp = valorLido; } } else if (myELM327.nb_rx_state == ELM_NO_DATA) reset++; break; } case 5: // RPM { valorLido = myELM327.rpm(); if (myELM327.nb_rx_state == ELM_SUCCESS) { decisao++; reset = 0; if (valorLido != 0) { rpm = valorLido; } } else if (myELM327.nb_rx_state == ELM_NO_DATA) reset++; break; } case 6: // Voltagem da bateria { valorLido = myELM327.batteryVoltage(); if (myELM327.nb_rx_state == ELM_SUCCESS) { decisao++; reset = 0; if (valorLido != 0) { batteryVoltage = valorLido; } } else if (myELM327.nb_rx_state == ELM_NO_DATA) reset++; break; } case 7: // Carga do motor { valorLido = myELM327.engineLoad(); if (myELM327.nb_rx_state == ELM_SUCCESS) { decisao++; reset = 0; if (valorLido != 0) { engineLoad = valorLido; } } else if (myELM327.nb_rx_state == ELM_NO_DATA) reset++; break; } case 8: // Encontra a porcentagem de compensação de combustivel { valorLido = myELM327.longTermFuelTrimBank_1(); if (myELM327.nb_rx_state == ELM_SUCCESS) { decisao++; reset = 0; if (valorLido != 0) { shortTermFuelTrimBank_1 = valorLido; } } else if (myELM327.nb_rx_state == ELM_NO_DATA) reset++; break; } case 9: // Pressão de combustivel { valorLido = myELM327.manifoldPressure(); if (myELM327.nb_rx_state == ELM_SUCCESS) { decisao++; reset = 0; if (valorLido != 0) { manifoldPressure = valorLido; } } else if (myELM327.nb_rx_state == ELM_NO_DATA) reset++; break; } case 10: // Avanço de temporização em graus antes do ponto morto superior (TDC) { valorLido = myELM327.timingAdvance(); if (myELM327.nb_rx_state == ELM_SUCCESS) { decisao = 1; reset = 0; if (valorLido != 0) { timingAdvance = valorLido; } } else if (myELM327.nb_rx_state == ELM_NO_DATA) reset++; break; } } }
Does anyone have any idea how I can read more data from my vehicle?
NO_DATA means that the car's diagnostics computer doesn't have data for that PID at that protocol. Maybe try using the default library settings or using a different protocol?
I'm using the default library settings, protocol 3. I don't know why I couldn't read more data, but for the project I'm doing, the data I could read is enough. So thanks a lot for the help guys