- Thu Feb 13, 2014 8:25 pm
#5853
Hey guys,
Got an adapter model A just yesterday, and now I have some questions! :D
So, for starters, I used the OBD.h library and the example sketch and it worked great. I mean, not the exact same sketch, but with the same PID, and outputed the RPM value to a LiquidCrystal LCD. Everything good so far.
But things started to de-rail right away.
When I tried to also see the Throttle Position PID, the reading was erroneous (like it outputed 18% at rest, and 22% at full throttle).
But that wasn't a big of a problem.
The big things was, I tried to put the LCD to display RPM, Ambient Temp, Oil Temp and HorsePower (dfrobot is calculated through torque).
Only the RPM is displayed, and all the other values stay at 0.
I commented everything except the Ambient Temp and tried it again and it now outputed that temp correctly.
I suppose using several PID readings at the same time messes things up, but I have no idea if that's the case, or how to fix it.
My code is here: (I know you won't probably like the If/else statements in there, but it was for formating the output on the LCD. I tested them independantly and they work perfectly, I may change them but only after I manage to deal with this issue :D )
#include <SPI.h>
#include <LiquidCrystal.h>
#include <Arduino.h>
#include <OBD.h>
#include <Wire.h>
COBD obd;
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
int load;
int rpm;
int tmp;
int oil;
int trq;
float dfrobot;
void setup()
{
lcd.begin(16, 2);
obd.begin();
while (!obd.init());
}
void loop()
{
obd.read(PID_RPM, rpm);
obd.read(PID_AMBIENT_TEMP, tmp);
obd.read(PID_ENGINE_OIL_TEMP, oil);
obd.read(PID_ENGINE_REF_TORQUE, trq);
dfrobot = ((trq * 0.737) * rpm) / 5252;
lcd.clear();
lcd.print(rpm);
lcd.print(" rpm");
if (tmp > 9)
{
lcd.setCursor(13, 0);
}
else if (tmp < 10)
{
lcd.setCursor(14, 0);
}
lcd.print(tmp);
lcd.write(223);
lcd.setCursor(0, 1);
lcd.print(oil);
lcd.write(223);
lcd.print("/oil");
if (dfrobot >= 100)
{
lcd.setCursor(10, 1);
}
else if (dfrobot > 9)
{
lcd.setCursor(11, 1);
}
else if (dfrobot < 10)
{
lcd.setCursor(12, 1);
}
lcd.print(dfrobot, 0);
lcd.print(" dfrobot");
delay(100);
}
Anyone knows what's going on? Or has the chance to test this?
BTW, the LCD is the SainSmart LCD Keypad Shield, which is a LiquidCrystal display (16x2).
Thank you!