Hi! for my project, i'm using the OBDLink SX as my OBD2 cable and i'm connecting it to a USB-to-TTL adapter(FT232BL) so i can connect to the arduino through the TX and RX pins. for my code i'm using the ELM327 library (GitHub - PowerBroker2/ELMduino: Arduino OBD-II Bluetooth Scanner Interface Library for Car Hacking Projects). Now when i upload the code, this is what the serial monitor displays:
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
.
.
.
and this is the code that i'm using :
#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
}
ps i'm using digital tx and rx pins because according to what i read the "original" tx and rx pins are used for the connection to my pc and debugging. pls help i'mm really confused