I made a little project using an Arduino UNO, a 3.5" display, a HC-05 bluetooth module and an ELM327 (cheap ebay clone). I managed to establish communication, read the data, interpret and display it, but only one problem remains that keeps bothering me.
After some exchanges of data between Arduino and the OBD2 adapter, communication just drops. I don't know if its from the HC-05 or ELM327. As far as I could debug it, the data from ELM327 comes incomplete. Usually the response from it, transformed into chars, is like "0103141 03 02 00 >" and I use the ">" char in the program as data exchange complete. When the problem occurs I receive fewer bytes from the OBD adapter and without the ">" char, something like "0103141 03 ".
I made a function that resets the HC-05 module and reconnects, but it takes a few seconds and I want my data to come as a continuous flow.
I tried a few methods of debugging, such as changing baud rate of the HC-05, and adding some delays, but I haven't come to a solution.
I believe that the problem might me one of these three:
- The cheap ebay clone messing things up.
- The HC-05 not sending the complete data.
- A problem with my code.
Below I have attached the part of the code that does the sending of the command and reading the response. When the problem occurs, it gets stuck in the while loop because I have no terminating ">" char and I have to break it, call another function that re-establishes communication and so on.
So my question is: has anyone confronted this problem where ELM327 sends incomplete data that cannot be used?
BTSerial.println("010F1");
BTSerial.flush();
delay(10);
if (BTSerial.available()>0)
busy = true;
while(busy = true && inData != 62)
{
temp++;
if (temp>500000){
resetBT();
BTSerial.println("ATWS");
break;
}
if (BTSerial.available()>0){
inData=0;
inData = BTSerial.read();
if(inData != 32) {
buf[i] = inData;
Serial.print(char(buf[i]));
i++;
}
}
}
Serial.println();
busy=false;
inData = 0;
i = 0;
memset(buf, 0, sizeof(buf));
temp = 0;
while
loop and just dump the received data to the terminal window .... analyze the data .... there may be something that you are overlooking ..... post the data into your question, if there is not way too much of it .... maybe some pattern may be found