Trouble Initializing OBD-II Model B
Posted: Thu Jan 22, 2015 12:39 pm
I'm having issues initializing the OBD-II adapter that I just received. I don't have a display so I couldn't use one of the example sketches included with the library. I am running the code below and I only see the "About to start" message and then the "Ugh!!!" message repeats. The light on Pin13 stays on and never goes off. I've tried it on both I2C connections on my Arduino Mega. I've also tried it on my UNO and my Nano Arduinos. Could someone give me some pointers on how to get my adapter working? I just installed the libraries and have not modified any of the header or cpp files.
Code: Select all
#include <Wire.h>
#include <OBD.h>
COBDI2C obd;
void setup()
{
//start the serial connection
Serial.begin(115200);
// we'll use the debug LED as output
pinMode(13, OUTPUT);
// start communication with OBD-II adapter
obd.begin();
Serial.println("About to start");
digitalWrite(13,HIGH);
// initiate OBD-II connection until success
while (!obd.init()) {
Serial.println("Ugh!!!");
}
}
void loop()
{
Serial.println("You're in the loop!!!");
digitalWrite(13,LOW);
int value;
// save engine RPM in variable 'value', return true on success
if (obd.read(PID_RPM, value)) {
// light on LED on Arduino board when the RPM exceeds 3000
digitalWrite(13, value < 3000 ? HIGH : LOW);
}
}