Page 1 of 1

Passes init(), but fails to read

Posted: Mon Aug 11, 2014 12:36 am
by Wehrdo
Hi, I'm hoping to use this OBD-II adapter as an MPG gauge in my 2009 Scion tC, using the speed and MAF sensors.

Using the example sketch of turning a light on if RPM exceeds 3000 (I lowered to 1200), the light never turns on. Modifying that to also write to an OLED screen, so I can see that after a few seconds, it gets past the while(!obd.init()) portion, but calling obd.read(...) returns false. I'm sure my vehicle's protocol is supported, as all cars since 2008 are required to support ISO-15765-4.

Here's my code:

Code: Select all

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

COBD obd;

Adafruit_CharacterOLED lcd(OLED_V2, 6, 7, 8, 9, 10, 11, 12);

void setup() {
  lcd.begin(16, 2);
  lcd.print("starting");
  obd.begin();
  while (!obd.init());
}

void loop() {
  boolean succeed = true;
  int vss;
  int maf;
  if (!obd.read(PID_SPEED, vss)) {
    succeed = false;
  }
  if (!obd.read(PID_MAF_FLOW, maf)) {
    succeed = false;
  }
  if (succeed) {
    float mpg;
    mpg = 710.734 * vss / maf;
 
    lcd.setCursor(0, 0);
    lcd.print(mpg);
    lcd.setCursor(0, 1);
    char both [16];
    sprintf(both, "%d, %d", vss, maf);
    lcd.print(both);
  }
  else {
    lcd.setCursor(0, 0);
    lcd.print("fail");
  }
}

Any ideas? Thanks!

Re: Passes init(), but fails to read

Posted: Mon Aug 11, 2014 11:22 am
by stanley
Could you find another car to test?

Re: Passes init(), but fails to read

Posted: Mon Aug 11, 2014 11:58 am
by Wehrdo
Thanks for the quick response!

I also tested on a 2001 Chevrolet Cavalier, with the same results. Today I connected to the adapter with USB, so I could directly send commands and see the results. I can get something like the following:

Serial Console
atz
OBDUART v1.0
atrv
12.9V
0100 (I believe this is the command for seeing which PIDs are supported?)
SEARCHING...UNABLE TO CONNECT

So, as I suspected, the adapter runs, but cannot connect to the car properly.

Re: Passes init(), but fails to read

Posted: Mon Aug 11, 2014 12:06 pm
by Wehrdo
Forgot to mention, I also can send the command "atsp0" with a response of "OK", meaning it successfully detected the protocol, right? Or does that just mean it successfully changed its mode to auto detect the protocol? I do this before sending command "0100", with the same error message.

Re: Passes init(), but fails to read

Posted: Sun Aug 17, 2014 11:40 am
by stanley
The response of UNABLE TO CONNECT indicates that the car's protocol is not supported. ATSP0 just sets the protocol to auto detecting.