Read data from motorbike OBD

Hi everyone,
i'm working in a project for my motobike (guzzi). I want read all information that the control unit send throught the OBD.
I have already read the information with one bluetooth device (ELM327 chip) and the app "ScanM5X data logger" for my android smartphone. In this case all working perfectly.

The next step it was connect my arduindo UNO board at the same bluetooth device (ELM 327) throught one hc-05 module. I was able to establish the bluetooth connection from arduino UNO and ELM327.

But now the question is: How do i start comunication from arduino UNO and the motorbike unit control?
My motorbike have a protocol ISO:9141 and i've read that comunication start before with "Slow initialization" and only after arduino can recive the data from motorbike. This is correct? How should this "slow connection" take place?
Do you have more information about this connection?

Thanks guys :slight_smile:

Hi Fede93,

that´s quite simple!
Since you already established a connection over OBD2, you just have to emulate the OBD2 commands.
The initialization is done by the adapter automatically.

All control commands are called AT-commands.
You can find a little explanation here.

If you have had to reconfigure something on your ScanM5X App, you have to do that in you solution as well.
Otherwise, you just have to initialize the connection and start sending requests:

ATZ \r
01 0C\r

This will reset the ELM327 and request the RPM. All PID´s can be seen here. But not all of them are compatible with your bike.

The response will start with 41 (Which is the SID you´ve sent + 0x40) followed by two values A & B and a return \r>
From the PID List, you can use the equations and calc back the RPM (A * 256 + B) / 4.
That´s it :slight_smile:

To force the adapter to use ISO9141 you can also set the protocol manually:

AT SP 5

Good luck!

Thanks for your reply.

I have one question. For sending request, the command ATZ\r and 010C\r, must be sending in mode AT or in "normal" mode ?

Thanks :slight_smile:

No, don´t mix up the AT-Mode from the HC-05 / 06 and the AT-Commands from ELM327 ;D

The ELM just receives the AT´s like any other request.
Init your (Soft-)Serial and send out something like that:
ATZ
AT SP 3
01 05
01 0C
01 0d
01 11
ATPC

It might work with Serial.println(), but this sends CarriageReturn and NewLine. Some ELM327 dislike that.

Serial.print("ATZ");
Serial.print('\r');

Also the spaces between the SID and PID are optional.

The documentation seems to differ between the Set Protocol versions. Here is another List of AT-Commands.

To see what´s happening, I´d connect the HC via SoftSerial, so you can mirror all in- and outputs to your Serial by USB.

TriB:
ATZ
AT SP 3
01 05
01 0C
01 0d
01 11
ATPC

Unfortunately this not working for me :frowning:

This is my output after sending the codes:

ATZ -> ELM327 v2.1
ATSP3 -> OK
0100/0105/010C/.. -> BUS INIT... -> STOPPED

I have also used the command ATTPn (for trying the protocolln) but for every n value (0-9) the response is ever OK.

I'm not sure that the elm327 bluetooth module does the slow init automatically..

Where am I doing wrong? :frowning:

ATZ -> ELM327 v2.1
ATSP3 -> OK
Seems fine!

ATSP3 sets the protocol to ISO 9141-2 (5 baud init, 10.4 kbaud)
5 baud init means SlowInit. It implies the initialization setting the protocol to 3.
You can also do it manually by sending:
ATSI
The protocol has to be set to 3 or 4 first, to do that! Otherwise, you will receive an error.

Then the first request 0100 (Find supported PID´s) starts the initialization request, which answers with "BUS INIT". Also fine! But:
Before sending further requests (0105/010C/...) you have to wait for a response!

If it does not work sending

ATZ
ATSP3
0100

Try

ATZ
ATSP3
ATSI
delay(1000);
0100

You might play around a bit with the delay.

Last but not least, there is another auto-feature:
AT TP A3 (Try Protocol 3 with Auto search)

To ensure waiting for a valid response, I´d create something like:
(Not tested code! Just for understanding)

#define MAXSENDTIME 2000

void Test(){
  SendAndReadResponse("ATZ");
  SendAndReadResponse("ATSP3");
  SendAndReadResponse("0100");
}

void SendAndReadResponse(char *command){
Bluetooth.print(command);
Bluetooth.print('\r');

uint32_t startTime = millis();

while ((millis() - startTime) < MAXSENDTIME))
  while(Bluetooth.available()){
    char c = Bluetooth.read();
    Serial.write(c);
    if(c == '\r')
      break;
   }
}

After the BUS INIT was successful, you have to send a message at least every 2 seconds.
The ELM327 can do it for you with a keepalive signal:
AT WM 01 0C (Just gives you the RPM)
AT SW 32 (0x32 == 50 * 20miliseconds = 1sec)

But the baud rate of SoftwareSerial and Serial? Both initialized at 9600? Is correct?

#include <SoftwareSerial.h>

#define RxD 10                //Arduino pin connected to Tx of HC-05
#define TxD 11                //Arduino pin connected to Rx of HC-05

SoftwareSerial blueToothSerial(RxD,TxD);

void setup()
{
  Serial.begin(9600);
  blueToothSerial.begin(9600);
  
  pinMode(RxD, INPUT); // Pin 10 -> the pin on which to receive serial data
  pinMode(TxD, OUTPUT); // Pin 11 -> the pin on which to transmit serial data     
}

The baud does not really matter. The data was fine on both sides.
But off course faster is better :smiley:

You can go higher with the Hardware Serial easily.
Just rise it in the code and on the Serial Monitor from Arduino IDE.

To rise it on the Bluetooth side, it´s a bit more complicate and related to your HC module:

blueToothSerial.print(F("AT+BAUD7"));
//or
blueToothSerial.println(F("AT+UART=57600,0,0"));

The BT module must not be connected during the AT-Commands!
Just try out which command works for you. If you see crappy data, it worked and you have to change the baud from 9600 to 57600 also in the code.

Why 57600? This is more or less the maximum which works with software serial.
The good thing is, that the data is always exchanged after each other, so it does not block each other.