You Reply:Stanley, I'm still getting the error even with the updated library. The cpp and header is in my Arudino library's folder and I know its recognizing it because if I comment out #include <OBD.h> I get the error... [code] rpm_led:11: error: 'COBD' does not name a type rpm_led.ino: In function 'void setup()': rpm_led:18: error: 'obd' was not declared in this scope rpm_led.ino: In function 'void loop()': rpm_led:26: error: 'obd' was not declared in this scope rpm_led:26: error: 'PID_RPM' was not declared in this scope[/code]
as oppose to
[code]rpm_led.ino: In function 'void setup()': rpm_led:18: error: 'class COBD' has no member named 'begin' rpm_led:20: error: 'class COBD' has no member named 'init' rpm_led.ino: In function 'void loop()': rpm_led:26: error: 'class COBD' has no member named 'readSensor' [/code]
Any suggestions?
OBD.h [code]/************************************************************************* * Arduino Library for OBD-II UART Adapter * Distributed under GPL v2.0 * Copyright (c) 2012~2013 Stanley Huang <[email protected]> * All rights reserved. *************************************************************************/
#define OBD_TIMEOUT_SHORT 2000 /* ms */ #define OBD_TIMEOUT_LONG 7000 /* ms */ #define OBD_TIMEOUT_INIT 3000 /* ms */ #define OBD_SERIAL_BAUDRATE 38400 #define OBD_RECV_BUF_SIZE 64
unsigned int hex2uint16(const char *p) { char c = *p; unsigned int i = 0; for (char n = 0; c && n < 4; c = *(++p)) { if (c >= 'A' && c <= 'F') { c -= 7; } else if (c>='a' && c<='f') { c -= 39; } else if (c == ' ') { continue; } else if (c < '0' || c > '9') { break; } i = (i << 4) | (c & 0xF); n++; } return i; }
void COBD::write(const char c) { OBDUART.write(c); }
int COBD::normalizeData(byte pid, char* data) { int result; switch (pid) { case PID_RPM: result = getLargeValue(data) >> 2; break; case PID_FUEL_PRESSURE: result = getSmallValue(data) * 3; break; case PID_COOLANT_TEMP: case PID_INTAKE_TEMP: case PID_AMBIENT_TEMP: result = getTemperatureValue(data); break; case PID_ABS_ENGINE_LOAD: result = getLargeValue(data) * 100 / 255; break; case PID_MAF_FLOW: result = getLargeValue(data) / 100; break; case PID_THROTTLE: case PID_ENGINE_LOAD: case PID_FUEL_LEVEL: result = getPercentageValue(data); break; case PID_TIMING_ADVANCE: result = (getSmallValue(data) - 128) >> 1; break; case PID_DISTANCE: case PID_RUNTIME: result = getLargeValue(data); break; default: result = getSmallValue(data); } return result; }
for (unsigned char i = 0; i < sizeof(s_initcmd) / sizeof(s_initcmd[0]); i++) { if (!passive) { char cmd[MAX_CMD_LEN]; strcpy_P(cmd, s_initcmd[i]); write(cmd); } n = 0; prompted = 0; currentMillis = millis(); for (;;) { if (available()) { char c = read(); if (n > 2 && c == '>') { buffer[n] = 0; prompted++; } else if (n < OBD_RECV_BUF_SIZE - 1) { buffer[n++] = c; } } else if (prompted) { break; } else { unsigned long elapsed = millis() - currentMillis; if (elapsed > OBD_TIMEOUT_INIT) { // init timeout //WriteData("\r"); return false; } initIdleLoop(); } } } while (available()) read();
// load pid map memset(pidmap, 0, sizeof(pidmap)); for (byte i = 0; i < 4; i++) { byte pid = i * 0x20; sendQuery(pid); char* data = getResponse(pid, buffer); if (!data) break; data--; for (byte n = 0; n < 4; n++) { if (data[n * 3] != ' ') break; pidmap[i * 4 + n] = hex2uint8(data + n * 3 + 1); } } while (available()) read();
errors = 0; return true; }[/code]
OBD.ino [code]/************************************************************************* * Sample sketch based on OBD-II library for Arduino * Distributed under GPL v2.0 * Copyright (c) 2012-2013 Stanley Huang <[email protected]> * All rights reserved. *************************************************************************/
#include <Arduino.h> #include "OBD.h"
COBD obd;
void setup() { // we'll use the debug LED as output pinMode(13, OUTPUT); // start communication with OBD-II UART adapter obd.begin(); // 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); } }[/code]