New I2C Adapter doesn't work, two other OBD tools do

Inquiry and support for Freematics products
Post Reply
element22
Posts: 12
Joined: Tue Oct 28, 2014 2:25 pm

New I2C Adapter doesn't work, two other OBD tools do

Post by element22 »

We have a problem here. I see several messages about the I2C Adapter not working, which are being shrugged off. My freshly bought I2C Adapter Model B doesn't work. To verify that everything is OK with OBD in my car I used two independent tools: a MaxiScan LCD scanner and a Bluetooth OBD adapter that links to an Android tablet. Both work fine (see images below). When I plug in the I2C Adapter with Arduino Uno with the standard code (below), it doesn't work. I added a LED signal function to see exactly where I get stuck and it's on obd.init(). After that, every 10 seconds the blue light in the I2C adapter flashes and nothing happens. This doesn't tell me much. It would be much more useful if obd.init() reported an error code (not just a bool) that would tell me exactly what's going on (lack of physical connection, unsupported protocol, etc). This is a brand new adapter, so if this problem isn't fixed I'll want a refund.

Image

ImageImage

Code: Select all

#include <Arduino.h>
#include <Wire.h>
#include <OBD.h>

#define LEDPin 13

COBDI2C obd;

void flashLED (int times) {
  int pls=180;
  for (int i=0;i<times;i++) {
    digitalWrite(LEDPin,HIGH);
    delay(pls);
    digitalWrite(LEDPin,LOW);
    delay(pls);
  }
}

void setup()
{
  // we'll use the debug LED as output
  pinMode(13, OUTPUT);
  // start communication with OBD-II UART adapter
  flashLED(4);
  delay(500); 
  obd.begin();
  flashLED(6); 
  // initiate OBD-II connection until success
  while (!obd.init());
  flashLED(8); 
}

void loop()
{
  int value;
  if (obd.read(PID_RPM, value)) {
    // RPM is successfully read and its value stored in variable 'value'
    // light on LED when RPM exceeds 3000
    digitalWrite(13, value > 2000 ? HIGH : LOW);
  }
}
stanley
Site Admin
Posts: 1027
Joined: Sat Mar 01, 2014 3:15 am

Re: New I2C Adapter doesn't work, two other OBD tools do

Post by stanley »

I see some people connecting I2C adapter to Arduino's Rx and Tx and apparently Rx and Tx pins are not for I2C communication. Did you connect the wires correctly?
element22
Posts: 12
Joined: Tue Oct 28, 2014 2:25 pm

Re: New I2C Adapter doesn't work, two other OBD tools do

Post by element22 »

Nothing connected to Tx/Rx on Arduino. Yellow lead from I2C Adapter plugged into SCL, blue into SDA, power red/blue to Vin/GND. The power from OBD seems to work, as Arduino boots up.
stanley
Site Admin
Posts: 1027
Joined: Sat Mar 01, 2014 3:15 am

Re: New I2C Adapter doesn't work, two other OBD tools do

Post by stanley »

I've just modifyied the library a bit. Please update the OBD library with this:
http://freematics.com/dl/OBD_library_20141221.7z
element22
Posts: 12
Joined: Tue Oct 28, 2014 2:25 pm

Re: New I2C Adapter doesn't work, two other OBD tools do

Post by element22 »

Downloaded the new lib, recompiled, uploaded to Arduino, same thing: it gets stuck on obd.init().
stanley
Site Admin
Posts: 1027
Joined: Sat Mar 01, 2014 3:15 am

Re: New I2C Adapter doesn't work, two other OBD tools do

Post by stanley »

If your car is an older one with ISO9141-2, this product might not working. Only some ofold ISO9141-2 vehicles are supported.
element22
Posts: 12
Joined: Tue Oct 28, 2014 2:25 pm

Re: New I2C Adapter doesn't work, two other OBD tools do

Post by element22 »

My car was bought new in 2010 in the US, so it uses the ISO 15765 CAN. Quote: "2008: All cars sold in the United States are required to use the ISO 15765-4 signaling standard (a variant of the Controller Area Network (CAN) bus)." ( Source: http://en.wikipedia.org/wiki/On-board_diagnostics )

Images showing the CAN high and low pins in my car's OBD port:

Image

Image

Image
stanley
Site Admin
Posts: 1027
Joined: Sat Mar 01, 2014 3:15 am

Re: New I2C Adapter doesn't work, two other OBD tools do

Post by stanley »

You can try manually setting the protocol used by the adapter like this:

Code: Select all

setProtocol(PROTO_CAN_29B_500K)
element22
Posts: 12
Joined: Tue Oct 28, 2014 2:25 pm

Re: New I2C Adapter doesn't work, two other OBD tools do

Post by element22 »

After lots of work I've achieved some shaky communication, by looping through protocols and hitting on the right one:

Code: Select all

void setup() {
   obd.begin();
   conn=obd.init();
   if (!conn) {
      for (int i=0; i<4; i++) { 
         if (i==0) obd.setProtocol(PROTO_CAN_11B_500K);
         else if (i==1) obd.setProtocol(PROTO_CAN_11B_250K);
         else if (i==2) obd.setProtocol(PROTO_CAN_29B_250K);
         else if (i==3) obd.setProtocol(PROTO_CAN_29B_500K);
         flashLED(2);
         conn=obd.init();
         if (conn) break;
      }
   }
   if (conn) flashLED(6);
}


Then, if I read nothing but PID_RPM and step on the gas pedal, it works (LED turns on when RPM>1500, goes out if RPM<1500):

Code: Select all

void loop() {
  int value;
  if (conn) {
    if (obd.read(PID_RPM, value)) {
      digitalWrite(13, value > 1500 ? HIGH : LOW);
    }
  } else {
    flashLED(3);
    delay(1000);
  }
}


However, as soon as I try reading PID_RUNTIME, something gets messed up. The adapter flashes every 6 sec and there's either no reaction to my stepping on the gas, or the reaction is very strange: delayed by 20 sec and lasts forever. Is there something special about reading PID_RUNTIME?

Code: Select all

void loop() {
   int value; // save RPM here
   int runTime=-1;
   if (conn) {
      obd.read(PID_RUNTIME,runTime);
      delay(1500);
      if (obd.read(PID_RPM, value)) {
         digitalWrite(13, value > 1500 ? HIGH : LOW);
      }
   } else {
      flashLED(3);
      delay(1000);
   }
}
element22
Posts: 12
Joined: Tue Oct 28, 2014 2:25 pm

Re: New I2C Adapter doesn't work, two other OBD tools do

Post by element22 »

I got it to work, though the OBD communication is still shaky (it takes several tries for obd.init to succeed). For whatever reason I can only make one reliable obd.read() call per loop. I only need PID_RUNTIME, so I removed PID_RPM and things seem to work.
Post Reply