Good morning,
I am currently working on my thesis project, which focuses on communication with the ECU of a 2024 Suzuki GSX-S150 motorcycle using an OBDII adapter cable. Our goal is to extract key information such as speed, RPM, fuel consumption, among others, through the diagnostic pins.
However, we have encountered an issue: we are unable to establish communication or retrieve any values. We suspect it may be related to the baud rate. According to the theory, to initiate communication, a hexadecimal code 33 is sent at 5 baud, and the ECU should respond with a hexadecimal 55 at 10400 baud. Despite following this procedure, we are not receiving any response.
We have also tried using an ELM327 adapter, but it returns an error, which I will attach along with the code we have been using for the project.
Any input or suggestions you can provide on how to proceed would be greatly appreciated.
Here is the code we are using:
#include <AltSoftSerial.h>
// Definir pines y constantes
AltSoftSerial KLine; // Usaremos AltSoftSerial para la lectura de la respuesta
#define KLINE_PIN 9 // Pin para la K-Line
void setup() {
// Inicializar la comunicación serie para depuración
Serial.begin(9600);
// Iniciar la comunicación serial en la K-Line
KLine.begin(10400); // Comenzar a 10400 baudios para leer la respuesta
// Realizar secuencia de Wakeup
Serial.println("Iniciando secuencia de Wakeup...");
wakeupSequence();
}
void loop() {
// Realizar Handshake a 5 baudios hasta que sea exitoso
Serial.println("Iniciando handshake...");
while (!handshakeSequence()) {
Serial.println("Handshake fallido. Reintentando...");
delay(1000); // Esperar un momento antes de reintentar
}
Serial.println("Comunicación establecida.");
}
void wakeupSequence() {
// Enviar el bit de wakeup manualmente
pinMode(KLINE_PIN, OUTPUT); // Control manual de la K-Line
// Wakeup: Baja la K-Line a 0 por 200 ms, luego la sube a 12V (HIGH) por 20 ms
digitalWrite(KLINE_PIN, LOW);
delay(200); // Baja a 0 por 200 ms
digitalWrite(KLINE_PIN, HIGH);
delay(20); // Sube a HIGH por 20 ms
Serial.println("Wakeup finalizado.");
}
bool handshakeSequence() {
pinMode(KLINE_PIN, OUTPUT);
Serial.println("Enviando byte 0x33 a 5 baudios...");
// Secuencia de bits para 0x33 a 5 baudios:
// Start bit (0) - 200 ms
digitalWrite(KLINE_PIN, LOW);
delay(200);
// Bit 1 - 400 ms (dos bits 1 en 0x33)
digitalWrite(KLINE_PIN, HIGH);
delay(400);
// Bit 0 - 400 ms (dos bits 0 en 0x33)
digitalWrite(KLINE_PIN, LOW);
delay(400);
// Bit 1 - 400 ms (dos bits 1 en 0x33)
digitalWrite(KLINE_PIN, HIGH);
delay(400);
// Bit 0 - 400 ms (dos bits 0 en 0x33)
digitalWrite(KLINE_PIN, LOW);
delay(400);
// Bit de parada (1) - 200 ms
digitalWrite(KLINE_PIN, HIGH);
delay(200);
// Cambiar el pin K-Line a entrada para recibir la respuesta
pinMode(KLINE_PIN, INPUT);
// Esperar y leer la respuesta del ECU
delay(25); // Pequeño retraso para permitir que la ECU responda
if (KLine.available()) {
uint8_t response = KLine.read();
if (response == 0x55) {
Serial.println("Respuesta de la ECU recibida: 0x55.");
return true; // Handshake exitoso
} else {
Serial.print("Respuesta inesperada de la ECU: ");
Serial.println(response, HEX);
}
} else {
Serial.println("No se recibió respuesta de la ECU.");
}
return false; // Handshake fallido, se repetirá
}
And this is the error returned by the OBDII:
"Protocol check: 3) ISO 9141-2 (5 baud init, 10.4 kbaud) The ignition must be on or the engine must be started!"