I made another attempt: I've inverted the logic of the program to turn on the led 13 when RPM are lower than 3000 and turn it off at higher values. Again no results, the led stays off
I thought that maybe the problem is located in the initialization phase, so I modified the program to turn on the led during the init (the setup function) and turn it off at the end (see code below).
After uploading the program, I can see clearly the led turning on and off but after... nothing happens.
As further step I have inserted also other debug "flashing led code" inside the IF statement but no results, as I understand the instruction obd.read(PID_RPM, value) always returns the false value.
Please note that I can read OBD2 codes on my motorcycle by using my notebook and a simple (freeware) program. Maybe the adapter does not work on protocol ISO9141-2???
Any clue?
Code: Select all
/*************************************************************************
* Sample sketch based on OBD-II library for Arduino
* Distributed under GPL v2.0
* Visit http://freematics.com for more information
* (C)2012-2014 Stanley Huang <stanleyhuangyc@gmail.com>
*************************************************************************/
#include <Arduino.h>
#include <Wire.h>
#include <OBD.h>
COBD obd;
void setup()
{
// we'll use the debug LED as output
pinMode(13, OUTPUT);
digitalWrite(13,HIGH); // debug: turn the led ON when init starts
// start communication with OBD-II UART adapter
obd.begin();
// initiate OBD-II connection until success
while (!obd.init());
digitalWrite(13,LOW); // debug: turn the led OFF when init ends
}
void loop()
{
int value;
if (obd.read(PID_RPM, value)) {
// RPM is successfully read and its value stored in variable 'value'
// light on LED when RPM exceeds 3000
digitalWrite(13, value < 1800 ? HIGH : LOW);
}
}