Page 1 of 1

Unable to connect using OBD UART with Arduino

Posted: Thu May 26, 2016 6:30 am
by Bogdan
Hey,

I bought the OBD UART adapter in February, but got busy with work so I just managed to get around my project using it this week.

However, I haven't been able to successfully connect to the car...
Even with the simplest code, it goes past obd.begin() but never successfully returns from obd.init()...


My setup:
Arduino UNO
Wiring: red wire connected to 5V on Arduino, black to ground, green connected to RX and white connected to TX.
Car: 2007 Mazda RX-8


Things I tried:
- Tried connecting red wire from OBD to Vin instead of 5V on Arduino
- Tried swapping TX and RX connections in case I messed up the wiring
- Tried with another Arduino UNO (thinking that maybe something got fried with the first one?) but that didn't change anything (and whatever else I run on those Arduinos works fine...)
- Tried using different wires (male-male connected from OBD adapter to breadboard) in case there's something wrong there
- Tried powering Arduino from 9V battery instead of OBD Vcc, with shared ground
- Tried powering Arduino from USB connected to laptop
- Changing from COBD to COBDI2C (even though I didn't think that would help, I have the UART/Serial model of OBD adapter)
- I wanted to try with "SoftwareSerial" but for some reason I'm seeing only gibberish in the Serial Monitor in Arduino IDE... How should it be used? What am I missing?
- Running this sketch: https://github.com/stanleyhuangyc/Ardui ... d_uart.ino but it appears to be getting stuck in the loop with obd.init()
- Running this sketch: https://github.com/stanleyhuangyc/Ardui ... t_test.ino but I'm only seeing some gibberish (nothing like what's passed to println())


Video showing the adapter with solid red led (I'm assuming power), and shortly blinking orange (communication?):
https://1drv.ms/v/s!An97xZQnw4Pvjqt2RzaeAXBhoOTehw
The code is simply obd.begin() and then obd.init() with 1 second delay between attempts and piezo beep to indicate that it's happening (very quietly heard in the video).
TX/RX leds are not blinking on Arduino at all during those attempts...


What am I missing?
Can it be that the adapter I received is faulty? Any way to confirm that?
If so, would it be possible to receive a replacement?

I'll be grateful for any help - I got to a dead end and am running out of ideas to try... :(

Thanks,
Bogdan

Re: Unable to connect using OBD UART with Arduino

Posted: Thu May 26, 2016 1:07 pm
by stanley
It is likely your car uses ISO9141-2 protocol which the adapter does not support.

Re: Unable to connect using OBD UART with Arduino

Posted: Thu May 26, 2016 3:31 pm
by Bogdan
Hey Stanley,

Thank you for your response.

In the meantime (yup, I spent most of the day today debugging the issue...) I tried on another car - 2008 Toyota Yaris. However, I'm getting exactly same results (as in, obd.init() never succeeds). Because of that I think it's not fault of an unsupported OBD protocol (Toyota isn't rare... ;) ).

I dug deeper in the OBD.cpp and this is what I found out:
- the "p" we receive in obd.init() is actually NULL,
- thus the version is never set and we return false

Code: Select all

bool COBD::init(OBD_PROTOCOLS protocol)
{
   const char *initcmd[] = {"ATZ\r","ATE0\r","ATL1\r","0100\r"};
   char buffer[64];

   m_state = OBD_CONNECTING;

   write("ATI\r");
   
   if (receive(buffer, sizeof(buffer), 100)) {
      char *p = strstr(buffer, "OBDUART");
      if (p) {
         p += 9;
         version = (*p - '0') * 10 + (*(p + 2) - '0');
         write("received" + *p);
      } else {
         // ######## THIS IS THE CASE I'M HITTING ########
      }
   }
   if (version == 0) {
      m_state = OBD_FAILED;
      return false;      // ######## THIS IS WHERE WE RETURN FALSE, SINCE VERSION HASN'T BEEN RETURNED/READ ########
   }


Why would the version not be getting set (value returned)?
Is this version being read from the car, or is expected to be returned by the OBD adapter itself? (code mentions it the "adapter version")

Would that point to a faulty adapter?

Thanks,
Bogdan

Re: Unable to connect using OBD UART with Arduino

Posted: Thu May 26, 2016 3:37 pm
by Bogdan
And to add to that, I also tried cycling through all supported protocols, for both of the cars, and it didn't help either :(

Code: Select all


  obdInitialized = false;
  OBD_PROTOCOLS protocols[] = {
    PROTO_AUTO,
    PROTO_ISO_9141_2,
    PROTO_KWP2000_5KBPS,
    PROTO_KWP2000_FAST,
    PROTO_CAN_11B_500K,
    PROTO_CAN_29B_500K,
    PROTO_CAN_29B_250K,
    PROTO_CAN_11B_250K
  };
 
  do {
    obd.begin();

    for (int i = 0; i < 5; i++) {
      for (int j = 0; j < 5; j++) {
        obdInitialized = obd.init(protocols[i]);

        if (obdInitialized) {
          break;
        }

        beep(50);
        delay(1000);
      }

      if (obdInitialized) {
          break;
      }
    }
  } while(!obdInitialized);




On a side note, what's the recommended way of working with OBD Adapter with Arduino being powered from external source (i.e. USB)?
I'm unplugging OBD Adapter whenever I plug in Arduino to program it, but it's getting a bit tedious so thought of checking if it's safe to leave the adapter plugged in (leave Vcc and GND plugged in, since as far as I know TX/RX just have to be unplugged to program Arduino UNO).

Re: Unable to connect using OBD UART with Arduino

Posted: Thu Jun 02, 2016 7:56 pm
by stanley
I just committed a fix for current issue. Please update your OBD library with the latest revision in github and give another try.

Re: Unable to connect using OBD UART with Arduino

Posted: Sun Jun 05, 2016 9:18 am
by Bogdan
Hmm interesting approach to customer support - approve posts selectively, don't respond to most of the questions, very generic replies that we have to wait days for - disappointing.

Stanley, I understand that it might be time consuming and it's all on you, but this just looks sketchy.
And the fact that we (customers) get to experience those practices only after the purchase... Oh well.

Anyways, I haven't tried with your "fixed" code, as I got it to work the way described in my investigation in my previous post (the one you didn't approve/publish...).

I wanted to ask what has changed that the code that worked previously (before you removed the version part in init) now had to be removed, but I don't anticipate any response really.

Good luck.

Re: Unable to connect using OBD UART with Arduino

Posted: Sun Jun 05, 2016 10:45 am
by stanley
I am not approving posts selectively. All of your posts are displayed. I just don't have time to read line by line and reply to all of them.
I reckon anyone knows how to see what has changed in code in github. That's called "history" on github.

Re: Unable to connect using OBD UART with Arduino

Posted: Mon Jun 06, 2016 8:21 am
by Bogdan
In all fairness, my previous post has now appeared. If the accusation was unjustified, then I apologize.

My question was targeted at the changes that caused the need to update the code (and yes, I've seen the code change, which is pretty much removal of a code I called out above). Were there some changes in firmware? How come device I've received ~3 months ago didn't work with the code base until now? Are there any other potential places that may be affected? (I haven't seen any more yet). It's a good practice to understand the root cause.

That said, it works, so I guess let's move on.

Thanks!