Hi,
I have an OBD-II UART adapter from Freematics OBD-II Adapter for Arduino | ArduinoDev.com (ver 1.2, B) that I'd like to use with my Diavolino in a 98 Honda.
I'm still waiting on my forum account to be approved at dfrobot.com, and the Arduino forum's always been a good starting point for advice.
I've downloaded the libraries recommended on their site, and am using a slightly altered version of their RPM_LED sketch (started tweaking random things after it didn't work consistently). The new sketch's goal is to take information from the OBD connection and print it to a separate serial connection.
The problems I've been running into feel really varied, and sometimes change between unplugging everything and giving it a fresh start, much less doing something in code. The most prevalent, however, follows this rough description:
- I plug in the OBD UART adapter, which is wired to power the arduino, and connected to D0, and D1.
- The arduino and UART turn on, because it's getting power from the car.
- The arduino hangs while waiting on [obd.init()]
- I unplug the serial connection (D0, D1) and then plug it back in after a few seconds.
- I repeat unplugging/plugging until the arduino magically connects to the UART and starts displaying data, either by LED notifications or software serial.
If I get it working, figure something out in code, or wind up asking for help on dfrobot, I'll post back here.
Thanks for the help!
My sketch as it stands:
/*************************************************************************
* Sample sketch based on OBD-II library for Arduino
* Distributed under GPL v2.0
* Copyright (c) 2012-2013 Stanley Huang <stanleyhuangyc@gmail.com>
* All rights reserved.
*************************************************************************/
#include <Arduino.h>
#include "OBD.h"
#include <SoftwareSerial.h>
COBD obd;
SoftwareSerial softSerial(10, 11); // RX, TX
void setup()
{
// we'll use the debug LED as output
pinMode(13, OUTPUT);
int pinState = 0;
// start serial communication at the adapter defined baudrate
obd.begin();
softSerial.begin(9600);
softSerial.println("Software Serial Init.");
while(!softSerial.available())
{
softSerial.println("Waiting on confirmed connection...");
delay(1000);
}
// initiate OBD-II connection until success
softSerial.println("begin obd.init()");
while (!obd.init())
{
// blink LED until obd.init() returns true?
if (pinState == 0)
{
digitalWrite(13, HIGH);
pinState = 1;
}
else
{
digitalWrite(13, LOW);
pinState = 0;
}
};
// alert me that the connection to obd is hopefully open
softSerial.println("obd.init() passed");
for (int c = 0; c < 20; c++)
{
if (2%c)
{
digitalWrite(13, HIGH);
}
else
{
digitalWrite(13, LOW);
}
delay(50);
}
}
void loop()
{
int value = 0;
softSerial.println("\n\r\n\rTop of loop:");
obd.readSensor(PID_RPM, value);
digitalWrite(13, value > 1000 ? HIGH : LOW);
softSerial.print("\n\rRPM: ");
softSerial.print(value);
obd.readSensor(PID_SPEED, value);
softSerial.print("\tSPEED: ");
softSerial.print(value);
delay(400);
}