PowerBroker2 / ELMduino

Arduino OBD-II Bluetooth Scanner Interface Library for Car Hacking Projects
MIT License
667 stars 125 forks source link

Receiving weird characters from my ELM327 #100

Closed satungen closed 2 years ago

satungen commented 2 years ago

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.

02:59:03.419 -> Attempting to connect to ELM327... 02:59:03.756 -> Clearing input serial buffer 02:59:03.756 -> Sending the following command/query: AT D 02:59:03.756 -> Received char: ⸮ 02:59:03.756 -> Received char:  02:59:05.720 -> All chars received: 02:59:05.720 -> Timeout detected with overflow of 0ms 02:59:05.863 -> Clearing input serial buffer 02:59:05.863 -> Sending the following command/query: AT Z 02:59:05.863 -> Received char:  02:59:05.863 -> Received char: ⸮ 02:59:05.863 -> Received char: ⸮ 02:59:05.863 -> Received char: ⸮ 02:59:05.863 -> Received char: ⸮ 02:59:07.826 -> All chars received: 02:59:07.826 -> Timeout detected with overflow of 0ms 02:59:07.922 -> Clearing input serial buffer 02:59:07.922 -> Sending the following command/query: AT E0 02:59:07.970 -> Received char: ⸮ 02:59:07.970 -> Received char:  02:59:07.970 -> Received char:  02:59:07.970 -> Received char:  02:59:09.935 -> All chars received: 02:59:09.935 -> Timeout detected with overflow of 0ms 02:59:10.031 -> Clearing input serial buffer 02:59:10.031 -> Sending the following command/query: AT S0 02:59:10.031 -> Received char: ⸮ 02:59:10.031 -> Received char:  02:59:10.031 -> Received char:  02:59:10.079 -> Received char:  02:59:12.043 -> All chars received: 02:59:12.043 -> Timeout detected with overflow of 0ms 02:59:12.139 -> Clearing input serial buffer 02:59:12.139 -> Sending the following command/query: AT AL 02:59:12.139 -> Received char: ⸮ 02:59:12.139 -> Received char:  02:59:12.139 -> Received char:  02:59:12.139 -> Received char:

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!

PowerBroker2 commented 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.

satungen commented 2 years ago

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

satungen commented 2 years ago

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

include "ELMduino.h"

include

include

include

SoftwareSerial mySerial(8, 9); // RX, TX

define ELM_PORT mySerial

define SCREEN_WIDTH 128

define SCREEN_HEIGHT 128

define RST_PIN 3

define DC_PIN 4

define CS_PIN 5

define SCLK_PIN 6

define MOSI_PIN 7

define BLACK 0x0000

define BLUE 0x001F

define RED 0xF800

define GREEN 0x07E0

define CYAN 0x07FF

define MAGENTA 0xF81F

define YELLOW 0xFFE0

define WHITE 0xFFFF

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);

if LED_BUILTIN

pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, LOW);

endif

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

PowerBroker2 commented 2 years ago

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.