Problems reading more than one PID
Posted: Thu Aug 27, 2015 7:33 pm
I have this code to read an show some PIDs, I don't know why but only read the first (RPMs) the other values are 0 or the same as RPMs, can somebody help me? I think that all is correct.
Best regards
Best regards
Code: Select all
#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <OBD.h>
SoftwareSerial mySerial(2, 3); // RX, TX
#define PID_ENGINE_FUEL_RATE 0x5E
//Global objets and variables
COBD obd;
int value0;
int value1;
int value2;
int value3;
int value4;
int value5;
int value6;
bool err;
void setup()
{
//Wait 10 seconds for connect debug device
delay(1000*10);
mySerial.begin(9600);
mySerial.println(F("OBD-II test"));
mySerial.println(F("Copyright (C) 2015 Custodium soluciones y sistemas SL"));
mySerial.println();
// start communication with OBD-II UART adapter
mySerial.println(F("obd.begin()"));
obd.begin();
// initiate OBD-II connection until success
mySerial.println(F("Waiting while !obd.init()"));
while (!obd.init());
}
void loop()
{
mySerial.println(F("Entering loop"));
err=obd.read(PID_RPM, value0);
/*
if(!err) {
mySerial.println(F("Error reading"));
}
*/
mySerial.print(F("RPM: "));
mySerial.println(value0);
delay(100);
err=obd.read(PID_ENGINE_TORQUE_PERCENTAGE, value1);
mySerial.print(F("ENGINE_TORQUE_PERCENTAGE: "));
mySerial.println(value1);
delay(100);
err=obd.read(PID_ENGINE_REF_TORQUE, value2);
mySerial.print(F("ENGINE_REF_TORQUE: "));
mySerial.println(value2);
delay(100);
err=obd.read(PID_ENGINE_REF_TORQUE, value3);
mySerial.print(F("ENGINE_REF_TORQUE: "));
mySerial.println(value3);
delay(100);
err=obd.read(PID_MAF_FLOW, value4);
mySerial.print(F("MAF_FLOW: "));
mySerial.println(value4);
delay(100);
err=obd.read(PID_SPEED, value5);
mySerial.print(F("SPEED: "));
mySerial.println(value5);
delay(100);
err=obd.read(PID_ENGINE_FUEL_RATE, value6);
mySerial.print(F("FUEL_RATE: "));
mySerial.println(value6);
delay(100);
delay(1000*10);
mySerial.println("Exiting loop");
}