Closed satungen closed 2 years ago
It sounds like a baud mismatch between the Arduino/bluetooth module/ELM327. Are you using an ESP32 or an HC-05 for the bluetooth? Either way, try different bauds and see if you get better results.
I am using wires for my serial connection.
You're absolutely right, 38400 baud rate solved my problem. Thanks for the quick response, and thanks for the great library! Happy holidays
Sorry, again to bother. Probably not an issue with your library per se but I might as well ask since you seem helpful and knowledgable.
Running this code I get characters I can't seem to figure out why they appear.
`#include
SoftwareSerial mySerial(8, 9); // RX, TX
ELM327 myELM327; Adafruit_SSD1351 tft = Adafruit_SSD1351(SCREEN_WIDTH, SCREEN_HEIGHT, CS_PIN, DC_PIN, MOSI_PIN, SCLK_PIN, RST_PIN);
uint32_t rpm = 0; int32_t kph = 0; int errorcount = 0;
void setup() { tft.begin(); tft.fillScreen(BLACK); tft.setTextColor(WHITE, BLACK);
pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, LOW);
Serial.begin(38400); ELM_PORT.begin(38400);
Serial.println("Attempting to connect to ELM327..."); tft.println("Attempting to connect to ELM327...");
if (!myELM327.begin(ELM_PORT, true, 5000)) { Serial.println("Couldn't connect to OBD scanner"); tft.println("Could not connect to OBD scanner"); while (1); }
Serial.println("Connected to ELM327"); tft.println("Connected to ELM327"); delay(500); tft.fillScreen(BLACK); }
void loop() { float tempRPM = myELM327.rpm();
if (myELM327.status == ELM_SUCCESS) { rpm = (uint32_t)tempRPM; kph = (int32_t)kph; Serial.print("RPM: "); Serial.println(rpm); Serial.print("KM/H: "); Serial.println(kph); tft.setCursor(64,54); tft.setTextSize(2); tft.println(rpm); tft.setCursor(64,74); tft.println(kph); } else printError();
} void printError() { Serial.print("Received: "); for (byte i = 0; i < myELM327.recBytes; i++) Serial.write(myELM327.payload[i]); Serial.println();
if (myELM327.status == ELM_SUCCESS) Serial.println(F("\tELM_SUCCESS")); else if (myELM327.status == ELM_NO_RESPONSE) Serial.println(F("\tERROR: ELM_NO_RESPONSE")); else if (myELM327.status == ELM_BUFFER_OVERFLOW) Serial.println(F("\tERROR: ELM_BUFFER_OVERFLOW")); else if (myELM327.status == ELM_UNABLE_TO_CONNECT) Serial.println(F("\tERROR: ELM_UNABLE_TO_CONNECT")); else if (myELM327.status == ELM_NO_DATA) Serial.println(F("\tERROR: ELM_NO_DATA")); else if (myELM327.status == ELM_STOPPED) Serial.println(F("\tERROR: ELM_STOPPED")); else if (myELM327.status == ELM_TIMEOUT) Serial.println(F("\tERROR: ELM_TIMEOUT")); else if (myELM327.status == ELM_TIMEOUT) Serial.println(F("\tERROR: ELM_GENERAL_ERROR"));
tft.fillRect(0, 0, 128, 20, BLACK); tft.setCursor(0,0); errorcount++; tft.println(myELM327.payload); delay(100); }`
While this is appearing in my serial monitor `13:17:38.594 -> Attempting to connect to ELM327... 13:17:38.919 -> Clearing input serial buffer
13:17:38.919 -> Sending the following command/query: AT D
13:17:38.966 -> Received char: S
13:17:38.966 -> Received char: T
13:17:38.966 -> Received char: O
13:17:38.966 -> Received char: P
13:17:38.966 -> Received char: P
13:17:38.966 -> Received char: E
13:17:38.966 -> Received char: D
13:17:39.011 -> Received char: \r
13:17:39.011 -> Received char: \r
13:17:39.011 -> Received char: >
13:17:39.011 -> Delimiter found
13:17:39.011 -> All chars received: STOPPED
13:17:39.011 -> ELM responded with errror "STOPPED"
13:17:39.105 -> Clearing input serial buffer
13:17:39.105 -> Sending the following command/query: AT Z
13:17:39.904 -> Received char: \r
13:17:39.904 -> Received char: \r
13:17:39.904 -> Received char: E
13:17:39.904 -> Received char: L
13:17:39.904 -> Received char: M
13:17:39.951 -> Received char: 3
13:17:39.951 -> Received char: 2
13:17:39.951 -> Received char: 7
13:17:39.951 -> Received char:
13:17:39.951 -> Received char: v
13:17:39.951 -> Received char: 2
13:17:39.951 -> Received char: .
13:17:39.951 -> Received char: 1
13:17:39.951 -> Received char: \r
13:17:39.998 -> Received char: \r
13:17:39.998 -> Received char: >
13:17:39.998 -> Delimiter found
13:17:39.998 -> All chars received: ELM327v21
13:17:40.090 -> Clearing input serial buffer
13:17:40.090 -> Sending the following command/query: AT E0
13:17:40.090 -> Received char: Q
13:17:40.090 -> Received char: ⸮
13:17:40.090 -> Received char:
13:17:40.140 -> Received char: ⸮
13:17:40.140 -> Received char: ⸮
13:17:40.140 -> Received char: \r
13:17:40.140 -> Received char: O
13:17:40.140 -> Received char: K
13:17:40.140 -> Received char: \r
13:17:40.140 -> Received char: \r
13:17:40.140 -> Received char: >
13:17:40.140 -> Delimiter found
13:17:40.140 -> All chars received: QOK
13:17:40.231 -> Clearing input serial buffer
13:17:40.231 -> Sending the following command/query: AT S0
13:17:40.278 -> Received char: O
13:17:40.278 -> Received char: K
13:17:40.278 -> Received char: \r
13:17:40.278 -> Received char: \r
13:17:40.278 -> Received char: >
13:17:40.278 -> Delimiter found
13:17:40.278 -> All chars received: OK
13:17:40.372 -> Clearing input serial buffer
13:17:40.372 -> Sending the following command/query: AT AL
13:17:40.417 -> Received char: O
13:17:40.417 -> Received char: K
13:17:40.417 -> Received char: \r
13:17:40.417 -> Received char: \r
13:17:40.417 -> Received char: >
13:17:40.417 -> Delimiter found
13:17:40.417 -> All chars received: OK
13:17:40.511 -> Clearing input serial buffer
13:17:40.511 -> Sending the following command/query: AT ST 00
13:17:40.558 -> Received char: O
13:17:40.558 -> Received char: K
13:17:40.558 -> Received char: \r
13:17:40.558 -> Received char: \r
13:17:40.558 -> Received char: >
13:17:40.558 -> Delimiter found
13:17:40.558 -> All chars received: OK
13:17:40.652 -> Clearing input serial buffer
13:17:40.652 -> Sending the following command/query: AT TP A0
13:17:40.699 -> Received char: O
13:17:40.699 -> Received char: K
13:17:40.699 -> Received char: \r
13:17:40.699 -> Received char: \r
13:17:40.699 -> Received char: >
13:17:40.699 -> Delimiter found
13:17:40.699 -> All chars received: OK
13:17:40.699 -> Connected to ELM327
13:17:42.105 -> Service: 1
13:17:42.105 -> PID: 12
13:17:42.105 -> Normal length query detected
13:17:42.105 -> Query string: 010C
13:17:42.105 -> Clearing input serial buffer
13:17:42.105 -> Sending the following command/query: 010C
13:17:42.247 -> Received char: S
13:17:42.247 -> Received char: E
13:17:42.247 -> Received char: A
13:17:42.247 -> Received char: R
13:17:42.247 -> Received char: C
13:17:42.247 -> Received char: H
13:17:42.247 -> Received char: I
13:17:42.294 -> Received char: N
13:17:42.294 -> Received char: G
13:17:42.294 -> Received char: .
13:17:42.294 -> Received char: .
13:17:42.294 -> Received char: .
13:17:42.294 -> Received char: \r
13:17:47.119 -> All chars received: SEARCHING
13:17:47.119 -> Timeout detected with overflow of 0ms
13:17:47.119 -> Received:
13:17:47.119 -> ERROR: ELM_TIMEOUT
13:17:47.449 -> Service: 1
13:17:47.449 -> PID: 12
13:17:47.449 -> Normal length query detected
13:17:47.449 -> Query string: 010C
13:17:47.449 -> Clearing input serial buffer
13:17:47.449 -> Sending the following command/query: 010C
13:17:47.449 -> Received char: Q
13:17:47.449 -> Received char: =
13:17:47.449 -> Received char: A
13:17:47.495 -> Received char: *
13:17:47.495 -> Received char:
13:17:47.495 -> Received char: ⸮
13:17:47.495 -> Received char: ⸮
13:17:47.732 -> Received char: S
13:17:47.732 -> Received char: E
13:17:47.732 -> Received char: A
13:17:47.732 -> Received char: R
13:17:47.732 -> Received char: C
13:17:47.732 -> Received char: H
13:17:47.732 -> Received char: I
13:17:47.779 -> Received char: N
13:17:47.779 -> Received char: G
13:17:47.779 -> Received char: .
13:17:47.779 -> Received char: .
13:17:47.779 -> Received char: .
13:17:47.779 -> Received char: \r
13:17:52.464 -> All chars received: QASEARCHING
13:17:52.464 -> Timeout detected with overflow of 0ms
13:17:52.464 -> Received:
13:17:52.464 -> ERROR: ELM_TIMEOUT
13:17:52.792 -> Service: 1
13:17:52.792 -> PID: 12
13:17:52.792 -> Normal length query detected
13:17:52.792 -> Query string: 010C
13:17:52.792 -> Clearing input serial buffer
13:17:52.792 -> Sending the following command/query: 010C
13:17:52.792 -> Received char: Q
13:17:52.839 -> Received char: =
13:17:52.839 -> Received char: A
13:17:52.839 -> Received char: A
13:17:52.839 -> Received char: B
13:17:52.839 -> Received char: j
13:17:52.839 -> Received char: ⸮
13:17:53.026 -> Received char: S
13:17:53.026 -> Received char: E
13:17:53.026 -> Received char: A
13:17:53.026 -> Received char: R
13:17:53.026 -> Received char: C
13:17:53.026 -> Received char: H
13:17:53.026 -> Received char: I
13:17:53.075 -> Received char: N
13:17:53.075 -> Received char: G
13:17:53.075 -> Received char: .
13:17:53.075 -> Received char: .
13:17:53.075 -> Received char: .
13:17:53.075 -> Received char: \r
13:17:57.802 -> All chars received: QAABjSEARCHING
13:17:57.802 -> Timeout detected with overflow of 0ms
13:17:57.802 -> Received:
13:17:57.802 -> ERROR: ELM_TIMEOUT
13:17:58.176 -> Service: 1
13:17:58.176 -> PID: 12
13:17:58.176 -> Normal length query detected
13:17:58.176 -> Query string: 010C
13:17:58.176 -> Clearing input serial buffer
13:17:58.176 -> Sending the following command/query: 010C
13:17:58.176 -> Received char: Q
13:17:58.222 -> Received char: =
13:17:58.222 -> Received char: A
13:17:58.222 -> Received char:
13:17:58.222 -> Received char:
13:17:58.222 -> Received char: j
13:17:58.222 -> Received char: ⸮
13:17:58.411 -> Received char: S
13:17:58.411 -> Received char: E
13:17:58.411 -> Received char: A
13:17:58.411 -> Received char: R
13:17:58.411 -> Received char: C
13:17:58.411 -> Received char: H
13:17:58.411 -> Received char: I
13:17:58.457 -> Received char: N
13:17:58.457 -> Received char: G
13:17:58.457 -> Received char: .
13:17:58.457 -> Received char: .
13:17:58.457 -> Received char: .
13:17:58.457 -> Received char: \r
13:18:03.196 -> All chars received: QAjSEARCHING
13:18:03.196 -> Timeout detected with overflow of 0ms
13:18:03.196 -> Received:
13:18:03.196 -> ERROR: ELM_TIMEOUT
13:18:03.524 -> Service: 1
13:18:03.524 -> PID: 12
13:18:03.524 -> Normal length query detected
13:18:03.524 -> Query string: 010C
13:18:03.524 -> Clearing input serial buffer
13:18:03.524 -> Sending the following command/query: 010C
13:18:03.571 -> Received char: Q
13:18:03.571 -> Received char: =
13:18:03.571 -> Received char: A
13:18:03.571 -> Received char:
13:18:03.571 -> Received char:
13:18:03.571 -> Received char: j
13:18:03.571 -> Received char: ⸮
13:18:03.756 -> Received char: S
13:18:03.756 -> Received char: E
13:18:03.756 -> Received char: A
13:18:03.756 -> Received char: R
13:18:03.805 -> Received char: C
13:18:03.805 -> Received char: H
13:18:03.805 -> Received char: I
13:18:03.805 -> Received char: N
13:18:03.805 -> Received char: G
13:18:03.805 -> Received char: .
13:18:03.805 -> Received char: .
13:18:03.805 -> Received char: .
13:18:03.805 -> Received char: \r
13:18:08.549 -> All chars received: QAjSEARCHING
13:18:08.549 -> Timeout detected with overflow of 0ms
`
Any clues as to why these extra characters are appearing?
I apologize for the formatting, ill try to fix it when I get home
I'm not sure why these characters are showing up - probably an issue with the ELM327 (it's probably a cheap Chinese clone). The library will automatically ignore non-ascii characters, so it shouldn't be an issue as long as the data is being returned.
Hello,
Sorry in advance for the perhaps silly question; I am quite new to all of this!
Trying the Arduino Software Serial test example you have provided, I only get gibberish characters in return for the commands.
I get the same gibberish when I try to send any of the commands through Serial communication. Do you have any idea what's happening?
Thank you in advance!