Mit diesem Programm wurde der erste Testlauf durchgeführt.

Zuvor mussten jedoch einige Änderungen vorgenommen werden. Sowohl das CANdiy Shield, als auch das LCD-Display verwenden die selben Pins am Arduino Board. Wir beseitigten dieses Problem durch das Umlöten einiger Pins.

Dieser Testversuch lief jedoch leider nicht so ab wie wir es geplant hatten. Aufgrund eines Kurzschlusses brannte der Chip am CANdiy Shield durch und es war keine Kommunikation mehr mit dem Auto möglich.

Hier unser GUI-Design:

Und hier unser Source Code:

#include 
#include 
 
ObdInterface obd;
ObdMessage msg;
 
LiquidCrystal lcd(11,9,4,5,6,3);
 
int modeHorizontal = 0;
int modeVertical = -1;
 
String drivingMenu[][3] = {
                            {"Speed", " km/h","0"},
                            {"Engine RPM", " RPM","1"},
                            {"Engine Temp.", " °C","0"},
                            {"Turbo. Temp. 1", " °C","0"},
                            {"Turbo. Temp. 2", " °C","0"},
                            {"Turbo. RPM", " RPM","0"}
                          };
int drivingMenuPids[] = {0x0d,0x0c,0x05,0x75,0x76,0x74};
boolean drivingMenuPidsSupported[] = {false,false,false,false,false,false};
 
String generalMenu[][3] = {
                            {"Codes del. since", " km","0"},
                            {"Fuel", " %","1"},
                          };
int generalMenuPids[] = {0x31,0x2F};
boolean generalMenuPidsSupported[] = {false,false};
 
void setup()
{
  lcd.begin(16,2);
  lcd.print("Welcome!");
  lcd.setCursor(0,1);
  lcd.print("Starting...");
 
  Serial.begin(9600);
  Serial.println("Probing Bus settings...");
  //probing bus settings
  if (probe(false,false))
  {
    obd.setSlow(false);
    obd.setExtended(false);
    Serial.println("Bus settings found: false false");
  }
  else
  {
    if (probe(true,false))
    {
      obd.setSlow(true);
      obd.setExtended(false);
      Serial.println("Bus settings found: true false");
    }
    else
    {
      if (probe(false,true))
      {
        obd.setSlow(false);
        obd.setExtended(true);
        Serial.println("Bus settings found: false true");
      }
      else
      {
        if (probe(true,true))
        {
          obd.setSlow(true);
          obd.setExtended(true);
          Serial.println("Bus settings found: true true");
        }
        else
        {
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("No Connection!");
        }
      }
    }
  }
 
  obd.begin();
 
  //check which pids are supported
  for (int i = 0;i<sizeof(drivingMenuPidsSupported);i++)
  {
    boolean supported;
    obd.isPidSupported(drivingMenuPids[i],supported);
    if (supported)
      drivingMenuPidsSupported[i] = true;
  }
  for (int i = 0;i<sizeof(generalMenuPidsSupported);i++)
  {
    boolean supported;
    obd.isPidSupported(generalMenuPids[i],supported);
    if (supported)
      generalMenuPidsSupported[i] = true;
  }
}
 
void loop()
{
  lcd.clear();
  if (analogRead(A0)<20)    //right button
  {
    if (modeHorizontal <2)       modeHorizontal++;     else       modeHorizontal = 0;     modeVertical = -1;   }   if (analogRead(A0)>380 && analogRead(A0)<430)    //right button   {     if (modeHorizontal >0)
      modeHorizontal--;
    else
      modeHorizontal = 2;
    modeVertical = -1;
  }
  switch (modeHorizontal)
  {
    case 0:    //Driving values
      if (analogRead(A0)>220&&analogRead(A0)<300)    //down button
      {
        if (modeVertical<sizeof(drivingMenuPidsSupported)-1)         {           modeVertical++;           while (!drivingMenuPidsSupported[modeVertical])           {             if (modeVertical>=sizeof(drivingMenuPidsSupported))
              modeVertical = 0;
            modeVertical++;
          }
        }
        else
        {
          modeVertical=0;
        }
      }
      else if (analogRead(A0)<150&&analogRead(A0)>80)  //up button
      {
        if (modeVertical>0)
        {        
          modeVertical--;
          while(!drivingMenuPidsSupported[modeVertical])
          {
            if (modeVertical>0)
              modeVertical--;
            else
            {
              modeVertical = -1;
              break;
            }
 
          }
        }
        else
        {
          modeVertical = -1;
        }
      }
      if (modeVertical == -1)
      {
        lcd.setCursor(0,0);
        lcd.print("Driving values");
        lcd.setCursor(0,1);
        lcd.print("Press Down...");
      }
      else
      {
        lcd.setCursor(0,0);
        lcd.print(drivingMenu[modeVertical][0]);
        lcd.setCursor(0,1);
 
        if (generalMenu[modeVertical][2] == "0")
        {
          word value = 0;
          Serial.println("Calling " + drivingMenu[modeVertical][0]);
          if (!obd.getPidAsInteger(drivingMenuPids[modeVertical],value))
           value = 666;
           lcd.print(value);
           lcd.print(drivingMenu[modeVertical][1]);
        }
        else if (drivingMenu[modeVertical][2] = "1")
        {
//          Serial.println("Calling " + drivingMenu[modeVertical][0]);
          float value = 0;
          if (!obd.getPidAsFloat(drivingMenuPids[modeVertical],0.0f,16383.75f,value))
            value = 666;
          lcd.print(value);
          lcd.print(drivingMenu[modeVertical][1]);
        }
      }
    break;
 
    case 1:  //general infos
    if (analogRead(A0)>220&&analogRead(A0)<300)    //down button     {         if (modeVertical >= sizeof(generalMenuPidsSupported)-1)
          modeVertical = 0;
        else
          modeVertical++;
        while (!generalMenuPidsSupported[modeVertical])
        {
          if (modeVertical>=sizeof(generalMenuPidsSupported)-1)    
          {
            modeVertical = 0;
          }
          else
          {
            modeVertical++;
          }
        }
    }
    else if (analogRead(A0)<150&&analogRead(A0)>80)  //up button
    {
            if (modeVertical == 0)
        modeVertical = -1;
      else
      {
      if (modeVertical>0)
      {        
        modeVertical--;
        while(!generalMenuPidsSupported[modeVertical])
        {
          if (modeVertical>0)
            modeVertical--;
          else
          {
            modeVertical = -1;
          }
        }
      }
      }
    }
    if (modeVertical == -1)
    {
      lcd.setCursor(0,0);
      lcd.print("General infos");
      lcd.setCursor(0,1);
      lcd.print("Press Down...");
    }
    else
    {
      lcd.setCursor(0,0);
      lcd.print(generalMenu[modeVertical][0]);
      lcd.setCursor(0,1);
      if (generalMenu[modeVertical][2] == "0")
      {
        word value = 0;
        //Serial.println("Calling " + generalMenu[modeVertical][0]);
        if (!obd.getPidAsInteger(generalMenuPids[modeVertical],value))
         value = 666;
         lcd.print(value);
         lcd.print(generalMenu[modeVertical][1]);
      }
      else if (generalMenu[modeVertical][2] = "1")
      {
//        Serial.println("Calling " + generalMenu[modeVertical][0]);
        float value = 0;
        if (!obd.getPidAsFloat(generalMenuPids[modeVertical],0.0f,16383.75f,value))
          value = 666;
        lcd.print(value);
        lcd.print(generalMenu[modeVertical][1]);
      }
    }
    break;
 
    case 2:  //errors
    if (modeVertical == -1)
    {
      lcd.setCursor(0,0);
      lcd.print("Errors");
      lcd.setCursor(0,1);
      lcd.print("Press Down...");
    }
    break;
  }
  delay(125);
}
 
boolean probe(boolean slow, boolean extended) {
  ObdInterface obd;
  boolean dummy;
 
  obd.setSlow(slow);
  obd.setExtended(extended);
 
  obd.begin();
  boolean result = obd.isPidSupported(1, dummy);
  obd.end();
 
  delay(250);
 
  return result;
}

Leave a Reply