Arduino Forum

Using Arduino => Programming Questions => Topic started by: stoopkid on Jun 07, 2012, 07:36 am

Title: OBD.h not compiling
Post by: stoopkid on Jun 07, 2012, 07:36 am
I just got an OBD library here. (http://sourceforge.net/projects/obdcon/) I opened an example sketch and tried to upload it but got errors that I do not understand.

code:
Code: [Select]

/*************************************************************************
* Sample sketch based on OBD-II library for Arduino
* Distributed under GPL v2.0
* Copyright (c) 2012 Stanley Huang <stanleyhuangyc@gmail.com>
* All rights reserved.
*************************************************************************/

#include <OBD.h>

COBD obd;

void setup()
{
  // we'll use the debug LED as output
  pinMode(13, OUTPUT); 
  // start serial communication at the adapter defined baudrate
  Serial.begin(OBD_SERIAL_BAUDRATE);
  // initiate OBD-II connection until success
  while (!obd.Init()); 
}

void loop()
{
  int value;
  if (obd.ReadSensor(PID_RPM, value)) {
    // RPM is read and stored in 'value'
    // light on LED when RPM exceeds 5000
    digitalWrite(13, value > 5000 ? HIGH : LOW);
  }
}


errors:

Quote

In file included from rpm_led.cpp:8:
C:\Users\Nick\Documents\Arduino\libraries\OBD/OBD.h:46: error: 'byte' has not been declared
C:\Users\Nick\Documents\Arduino\libraries\OBD/OBD.h:48: error: 'byte' does not name a type
C:\Users\Nick\Documents\Arduino\libraries\OBD/OBD.h:49: error: 'byte' does not name a type
C:\Users\Nick\Documents\Arduino\libraries\OBD/OBD.h:54: error: 'byte' has not been declared
C:\Users\Nick\Documents\Arduino\libraries\OBD/OBD.h:55: error: 'byte' has not been declared
C:\Users\Nick\Documents\Arduino\libraries\OBD/OBD.h:75: error: 'byte' does not name a type
C:\Users\Nick\Documents\Arduino\libraries\OBD/OBD.h: In constructor 'COBD::COBD()':
C:\Users\Nick\Documents\Arduino\libraries\OBD/OBD.h:41: error: 'dataMode' was not declared in this scope
C:\Users\Nick\Documents\Arduino\libraries\OBD/OBD.h:42: error: 'errors' was not declared in this scope


OBD.h is located in "C:\Users\Nick\Documents\Arduino\Libraries\OBD"

I've tried with IDE 1.0 and 1.0.1. What could be causing this?


Thanks
Title: Re: OBD.h not compiling
Post by: Coding Badly on Jun 07, 2012, 09:06 am

• Locate and open OBD.h in your favourite text editor

• Change the top of the file to this (basically add the #ifndef through the #include)...

Quote
[font=Courier New]/*************************************************************************
* OBD-II (ELM327) data accessing library for Arduino
* Distributed under GPL v2.0
* Copyright (c) 2012 Stanley Huang <stanleyhuangyc@gmail.com>
* All rights reserved.
*************************************************************************/
#ifndef OBD_h
#define OBD_h

#include <Arduino.h>

#define OBD_TIMEOUT_SHORT 2000 /* ms */
#define OBD_TIMEOUT_LONG 7000 /* ms */[/font]


• Add a #endif to the bottom of the file...

Quote
[font=Courier New]   virtual char ReadData();
   virtual byte WriteData(const char* s);
};

#endif[/font]


• Save and close OBD.h

• Try again (you do not need to restart the IDE)
Title: Re: OBD.h not compiling
Post by: stoopkid on Jun 07, 2012, 09:50 am
Thank you that got it to compile... However I'm still having trouble, it doesn't seem to respond to the device. I think it was incorrect for me to assume that this USB device could be interfaced as easily as an RS232 one.
Title: Re: OBD.h not compiling
Post by: Coding Badly on Jun 07, 2012, 09:54 am

You are welcome.  I don't have any experience with OBD so I can't help with the next problem.