0

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:

  1. The cheap ebay clone messing things up.
  2. The HC-05 not sending the complete data.
  3. 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;
1
  • reduce your code to bare minimum ..... remove the whole 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
    – jsotola
    Commented Aug 30, 2018 at 2:04

2 Answers 2

1

I managed to solve the issue. After some more testing, I ended up noticing that the problem was somehow the data exchange through the HC-05 bluetooth module. I changed it from being via SoftwareSerial library to the main serial com port and I had no issues since then. I don't know how that library may have caused the problem, but that was it.

1

You can much more easily interface your Arduino with an ELM327 in software with the library ELMduino.h. It's downloadable through the Arduino IDE and includes examples.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.