Go Down

Topic: Problem with reading sensor (Read 1 time) previous topic - next topic

marcin_i

Hi,
Finally I've made my OBD2 logger. It's recording data, but I don't know why only first value is acctual.
Code: [Select]
PID_RPM: 1479;PID_SPEED: 0;PID_THROTTLE: 18;PID_ENGINE_LOAD: 41;PID_ABS_ENGINE_LOAD: 0;PID_FUEL_LEVEL: 0;PID_DISTANCE: 0
PID_RPM: 1476;PID_SPEED: 0;PID_THROTTLE: 18;PID_ENGINE_LOAD: 41;PID_ABS_ENGINE_LOAD: 0;PID_FUEL_LEVEL: 0;PID_DISTANCE: 0

Rest of pid's value seems to be frozen at moment when I start logging.

Can you help me ivestigate this, why it doesn't record all pid's?
Here is my code:
Code: [Select]
#include <SdFat.h>
#include <arduino.h>
#include <OBD.h>

const uint8_t chipSelect = SS;
unsigned long lastTick = millis();

SdFat sd;
COBD obd;

  int rpm;
  int speed_;
  int throttle;
  int eng_load;
  int abs_eng_load;
  int fuel;
  int dist;

void setup() {
  Serial.begin(OBD_SERIAL_BAUDRATE);
  sd.begin(chipSelect, SPI_FULL_SPEED);
  obd.Init();
}
//------------------------------------------------------------------------------
void loop() {
 
  unsigned long curTick = millis();
  if (curTick - lastTick > 500)
        {
    ofstream sdlog("LOGFILE.TXT", ios::out | ios::app);
          obd.ReadSensor(PID_RPM, rpm);
          obd.ReadSensor(PID_SPEED, predk);
          obd.ReadSensor(PID_THROTTLE, przepustnica);
          obd.ReadSensor(PID_ENGINE_LOAD, eng_load);
          obd.ReadSensor(PID_ABS_ENGINE_LOAD, abs_eng_load);
          obd.ReadSensor(PID_FUEL_LEVEL, fuel);
          obd.ReadSensor(PID_DISTANCE, dist);
         
          sdlog << "PID_RPM: " << rpm << ";PID_SPEED: " << predk << ";PID_THROTTLE: " << przepustnica << ";PID_ENGINE_LOAD: " << eng_load << ";PID_ABS_ENGINE_LOAD: " << abs_eng_load << ";PID_FUEL_LEVEL: " << fuel << ";PID_DISTANCE: " << dist << endl;
         // if (!sdlog) sd.errorHalt("append failed");
  lastTick = curTick;
}
}

robtillaart


I would first try to read the data and display them on an LCD or so. Much easier to debug.

DO you have a link to the ODB library?

does this code actually run? as predk and przepustnica are not defined?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

marcin_i

Hi,
I've got OBD2 library from www.arduinodev.com/hardware/obd-kit/
It's display data correctly, I've try it earlier, and it works out of the box. Yes I know that this two variables are not defined, but it doesn't change anything.

robtillaart

#3
Dec 22, 2012, 08:56 pm Last Edit: Dec 22, 2012, 09:00 pm by robtillaart Reason: 1
I found a diff with the rpm_led demo - it's probably the initialization

Code: [Select]

const uint8_t chipSelect = SS;
unsigned long lastTick = millis();

SdFat sd;
COBD obd;

 int rpm;
 int speed_;
 int throttle;
 int eng_load;
 int abs_eng_load;
 int fuel;
 int dist;

void setup() {
 Serial.begin(OBD_SERIAL_BAUDRATE);
 sd.begin(chipSelect, SPI_FULL_SPEED);
 while (!obd.Init());   // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< change this line this is from the example program
}
//------------------------------------------------------------------------------
void loop() {
 
 unsigned long curTick = millis();
 if (curTick - lastTick > 500)
       {
   ofstream sdlog("LOGFILE.TXT", ios::out | ios::app);
         obd.ReadSensor(PID_RPM, rpm);
         obd.ReadSensor(PID_SPEED, predk);
         obd.ReadSensor(PID_THROTTLE, przepustnica);
         obd.ReadSensor(PID_ENGINE_LOAD, eng_load);
         obd.ReadSensor(PID_ABS_ENGINE_LOAD, abs_eng_load);
         obd.ReadSensor(PID_FUEL_LEVEL, fuel);
         obd.ReadSensor(PID_DISTANCE, dist);
       
         sdlog << "PID_RPM: " << rpm << ";PID_SPEED: " << predk << ";PID_THROTTLE: " << przepustnica << ";PID_ENGINE_LOAD: " << eng_load << ";PID_ABS_ENGINE_LOAD: " << abs_eng_load << ";PID_FUEL_LEVEL: " << fuel << ";PID_DISTANCE: " << dist << endl;
        // if (!sdlog) sd.errorHalt("append failed");
 lastTick = curTick;
}
}
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

marcin_i

Truthly  I doubt that this change is necessary. As I understand this line it's try initiate obd until it finish success, and this is executed only once on start. So when I received this one value, this means obd was initialized successfully.

Go Up