Skip to content
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

couldn't connect to OBD scanner #253

Open
mohamedsadok7 opened this issue Jun 15, 2024 · 5 comments
Open

couldn't connect to OBD scanner #253

mohamedsadok7 opened this issue Jun 15, 2024 · 5 comments
Assignees
Labels
question Further information is requested

Comments

@mohamedsadok7
Copy link

Hi! great work here. for my project, i'm using the OBDLink SX as my OBD2 cable ( i'm pretty sure it does support ELM327 and work with same protocols) and i'm connecting it to USB host shield that is mounted on my arduino UNO (i need the USB host because the arduino board doesn't have a USB port). Now when i upload the usb host shield code it works perfectly but when i upload the slightly altered multiple PIDs code, this is what the serial monitor displays:
Attempting to connect to ELM327... Clearing input serial buffer Sending the following command/query: AT D AT D Timeout detected with overflow of 0ms Clearing input serial buffer Sending the following command/query: AT Z AT Z Timeout detected with overflow of 0ms Clearing input serial buffer Sending the following command/query: AT E0 AT E0 Timeout detected with overflow of 0ms Clearing input serial buffer Sending the following command/query: AT S0 AT S0 Timeout detected with overflow of 0ms Clearing input serial buffer Sending the following command/query: AT AL AT AL Timeout detected with overflow of 1ms Clearing input serial buffer Sending the following command/query: AT ST 00 AT ST 00 Timeout detected with overflow of 0ms Clearing input serial buffer Sending the following command/query: AT SP A0 AT SP A0 Timeout detected with overflow of 0ms Setting protocol via AT TP A%c did not work - trying via AT SP %c Clearing input serial buffer Sending the following command/query: AT SP 0 AT SP 0 Timeout detected with overflow of 0ms Setting protocol via AT SP %c did not work Couldn't connect to OBD scanner Query string: 010C1 Clearing input serial buffer Sending the following command/query: 010C1 010C1 Timeout detected with overflow of 1000ms Service: 1 PID: 12 Normal length query detected Query string: 010C1 Clearing input serial buffer Sending the following command/query: 010C1 010C1 Timeout detected with overflow of 0ms Service: 1 PID: 12 Normal length query detected Query string: 010C1 Clearing input serial buffer Sending the following command/query: 010C1 010C1 Timeout detected with overflow of 1ms Service: 1 PID: 12 Normal length query detected Query string: 010C1 Clearing input serial buffer Sending the following command/query: 010C1
this is my code :
`#include "ELMduino.h"

#define ELM_PORT Serial

const bool DEBUG = true;
const int TIMEOUT = 2000;
const bool HALT_ON_FAIL = false;

ELM327 myELM327;

void setup() {
Serial.begin(115200);
ELM_PORT.begin(115200);

Serial.println("Attempting to connect to ELM327...");

if (!myELM327.begin(ELM_PORT, DEBUG, TIMEOUT)) {
Serial.println("Couldn't connect to OBD scanner");

if (HALT_ON_FAIL) {
  while (1);
}

}

Serial.println("Connected to ELM327");
}

void loop() {
float coolantTemp = myELM327.engineCoolantTemp();
float rpm = myELM327.rpm();
float speed = myELM327.kph();

if (myELM327.nb_rx_state == ELM_SUCCESS) {
Serial.print("Temperature: ");
Serial.println(coolantTemp);
Serial.print("RPM: ");
Serial.println(rpm);
Serial.print("Speed: ");
Serial.println(speed);

// Send data in a single line for easy parsing
Serial.print("DATA,");
Serial.print(coolantTemp);
Serial.print(",");
Serial.print(rpm);
Serial.print(",");
Serial.println(speed);

} else if (myELM327.nb_rx_state != ELM_GETTING_MSG) {
myELM327.printError();
}

delay(1000); // Adjust delay as needed
}
`
i even tried the software serial test and it gave me pretty much the same output . am i missing something here ?

@mohamedsadok7 mohamedsadok7 added the question Further information is requested label Jun 15, 2024
@PowerBroker2
Copy link
Owner

Please reformat your post properly

@mohamedsadok7
Copy link
Author

this is what the serial monitor displays:

Attempting to connect to ELM327...
Clearing input serial buffer
Sending the following command/query: AT D
AT D
Timeout detected with overflow of 0ms
Clearing input serial buffer
Sending the following command/query: AT Z
AT Z
Timeout detected with overflow of 0ms
Clearing input serial buffer
Sending the following command/query: AT E0
AT E0
Timeout detected with overflow of 0ms
Clearing input serial buffer
Sending the following command/query: AT S0
AT S0
Timeout detected with overflow of 0ms
Clearing input serial buffer
Sending the following command/query: AT AL
AT AL
Timeout detected with overflow of 1ms
Clearing input serial buffer
Sending the following command/query: AT ST 00
AT ST 00
Timeout detected with overflow of 0ms
Clearing input serial buffer
Sending the following command/query: AT SP A0
AT SP A0
Timeout detected with overflow of 0ms
Setting protocol via AT TP A%c did not work - trying via AT SP %c
Clearing input serial buffer
Sending the following command/query: AT SP 0
AT SP 0
Timeout detected with overflow of 0ms
Setting protocol via AT SP %c did not work
Couldn't connect to OBD scanner
Query string: 010C1
Clearing input serial buffer
Sending the following command/query: 010C1
010C1 Timeout detected with overflow of 1000ms
Service: 1
PID: 12
Normal length query detected
Query string: 010C1
Clearing input serial buffer
Sending the following command/query: 010C1
010C1 Timeout detected with overflow of 0ms
Service: 1
PID: 12
Normal length query detected
Query string: 010C1
Clearing input serial buffer
Sending the following command/query: 010C1
010C1
Timeout detected with overflow of 1ms
Service: 1
PID: 12
Normal
length query detected
Query string: 010C1
Clearing input serial buffer
Sending the following command/query: 010C1

and this is the code that i'm working on (multiple PIDs but slightly altered):

`#include "ELMduino.h"

#define ELM_PORT Serial

const bool DEBUG = true;
const int TIMEOUT = 2000;
const bool HALT_ON_FAIL = false;

ELM327 myELM327;

void setup() {
Serial.begin(115200);
ELM_PORT.begin(115200);

Serial.println("Attempting to connect to ELM327...");

if (!myELM327.begin(ELM_PORT, DEBUG, TIMEOUT)) {
Serial.println("Couldn't connect to OBD scanner");

if (HALT_ON_FAIL) {
while (1);
}
}

Serial.println("Connected to ELM327");
}

void loop() {
float coolantTemp = myELM327.engineCoolantTemp();
float rpm = myELM327.rpm();
float speed = myELM327.kph();

if (myELM327.nb_rx_state == ELM_SUCCESS) {
Serial.print("Temperature: ");
Serial.println(coolantTemp);
Serial.print("RPM: ");
Serial.println(rpm);
Serial.print("Speed: ");
Serial.println(speed);

// Send data in a single line for easy parsing
Serial.print("DATA,");
Serial.print(coolantTemp);
Serial.print(",");
Serial.print(rpm);
Serial.print(",");
Serial.println(speed);
} else if (myELM327.nb_rx_state != ELM_GETTING_MSG) {
myELM327.printError();
}

delay(1000); // Adjust delay as needed
}
`
there is a problem with the connection between the arduino and the ELM327, like it detects that there is an ELM327 device but in can't communicate with it, and i can't reaally point out the problem

@jimwhitelaw
Copy link
Collaborator

Your sketch has the debug port and ELM PORT both designated as Serial, which is the UNO onboard serial port. So the code is trying to connect to the ELM on the same port.

Your serial shield will likely be defined by its own TX and RX pins. Work that out and then try the simple serial sketch to confirm a connection.

@mohamedsadok7
Copy link
Author

i tried using the software serial example and created digital TX and RX for the arduino (i removed the shield ) and connected my board to an USB to ttl adapter(FT232BL) and connected that to my OBDLink SX . this is the new arduino code :

#include "ELMduino.h"
#include <SoftwareSerial.h>

// Define the pins for SoftwareSerial
#define ELM_TX_PIN 10 // Arduino pin to ELM327 Rx
#define ELM_RX_PIN 11 // Arduino pin to ELM327 Tx

SoftwareSerial elmSerial(ELM_RX_PIN, ELM_TX_PIN); // RX, TX

#define ELM_PORT elmSerial

const bool DEBUG = true;
const int TIMEOUT = 2000;
const bool HALT_ON_FAIL = false;

ELM327 myELM327;

void setup() {
Serial.begin(115200); // Start the hardware serial for debugging
ELM_PORT.begin(115200); // Start the SoftwareSerial for ELM327

Serial.println("Attempting to connect to ELM327...");

if (!myELM327.begin(ELM_PORT, DEBUG, TIMEOUT)) {
Serial.println("Couldn't connect to OBD scanner");

if (HALT_ON_FAIL) {
  while (1);
}

}

Serial.println("Connected to ELM327");
}

void loop() {
float coolantTemp = myELM327.engineCoolantTemp();
float rpm = myELM327.rpm();
float speed = myELM327.kph();

if (myELM327.nb_rx_state == ELM_SUCCESS) {
Serial.print("Temperature: ");
Serial.println(coolantTemp);
Serial.print("RPM: ");
Serial.println(rpm);
Serial.print("Speed: ");
Serial.println(speed);

// Send data in a single line for easy parsing
Serial.print("DATA,");
Serial.print(coolantTemp);
Serial.print(",");
Serial.print(rpm);
Serial.print(",");
Serial.println(speed);

} else if (myELM327.nb_rx_state != ELM_GETTING_MSG) {
myELM327.printError();
}

delay(1000); // Adjust delay as needed
}

i'm somehow still getting the same error :
Attempting to connect to ELM327...
Clearing input serial buffer
Sending the following command/query: AT D
Timeout detected with overflow of 0ms
Clearing input serial buffer
Sending the following command/query: AT Z
Timeout detected with overflow of 0ms
Clearing input serial buffer
Sending the following command/query: AT E0
Timeout detected with overflow of 0ms
Clearing input serial buffer
Sending the following command/query: AT S0
Timeout detected with overflow of 0ms
Clearing input serial buffer
Sending the following command/query: AT AL
Timeout detected with overflow of 1ms
Clearing input serial buffer
Sending the following command/query: AT ST 00
Timeout detected with overflow of 0ms
Clearing input serial buffer
Sending the following command/query: AT SP A0
Timeout detected with overflow of 0ms
Setting protocol via AT TP A%c did not work - trying via AT SP %c
Clearing input serial buffer
Sending the following command/query: AT SP 0
Timeout detected with overflow of 0ms
Setting protocol via AT SP %c did not work
Couldn't connect to OBD scanner
Connected to ELM327
Service: 1
PID: 5
Normal length query detected
Query string: 01051
Clearing input serial buffer
Sending the following command/query: 01051
Timeout detected with overflow of 1000ms
Service: 1
PID: 12
Normal length query detected
Query string: 010C1
Clearing input serial buffer
Sending the following command/query: 010C1
Timeout detected with overflow of 0ms
Service: 1
PID: 12
.
.
.
I'm really confused

@jimwhitelaw
Copy link
Collaborator

A few thoughts:

/ Define the pins for SoftwareSerial
#define ELM_TX_PIN 10 // Arduino pin to ELM327 Rx
#define ELM_RX_PIN 11 // Arduino pin to ELM327 Tx

This code doesn't match the comments. It could be correct, but worth checking that you don't have RX & TX swapped.

void loop() {
float coolantTemp = myELM327.engineCoolantTemp();
float rpm = myELM327.rpm();
float speed = myELM327.kph();

This is not the correct way to use loop() to query multiple PIDs. See the multiple pids example for the correct method.

From the looks of it, you are not getting a valid serial connection to the adapter. I'd start there before moving on to specific queries. Start with this simple software serial example and get your connection working, then move on to running the multiple query example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants