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!