PowerBroker2 / ELMduino

Arduino OBD-II Bluetooth Scanner Interface Library for Car Hacking Projects
MIT License
636 stars 123 forks source link

Library not reading PIDs correctly #144

Closed bborisov567 closed 1 year ago

bborisov567 commented 1 year ago

I have a problem with reading PIDs. When requesting data through directly from the ELM device through Terminal i get a correct response, also ELM is working fine with the Android app. With intakeCoolanttemp() i am getting a value of 168 on a cold engine. With manifoldPressure() i am getting a value of 208 that is not changing. With rpm() i am getting value of 0, on a running engine. There is definatelly something wrong. COnncetion between ELM and arduino is ok. I am using the example code. https://imgur.com/uhBQyaS https://imgur.com/lyM69La

PowerBroker2 commented 1 year ago

Run the code with the lib in debug mode and post BOTH the sketch and the debug printouts. Be sure to use proper code tags

bborisov567 commented 1 year ago

I did some more testing ang got the following results: Functions:

rpm()
mafRate()
intakeAirTemp()

work correctly!

But the functions:

engineCoolantTemp()
shortTermFuelTrimBank_1()
shortTermFuelTrimBank2()

don't work.

I attach the debug return as a text file because line formatting is lost when i paste it. Here is my code, i change the function accordingly every time. debug_return.txt

#include <SoftwareSerial.h>
#include "ELMduino.h"

SoftwareSerial mySerial(2, 3); // RX, TX
ELM327 myELM327;

uint32_t rpm = 0;

void setup()
{
  Serial.begin(115200);
  mySerial.begin(38400);
  myELM327.begin(mySerial, true, 2000);
}

void loop()
{
  float tempRPM = myELM327.shortTermFuelTrimBank_2();  // I change the function here.
  if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
    rpm = (uint32_t)tempRPM;
    Serial.print("RPM: "); Serial.println(rpm);
  }
  else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
    myELM327.printError();
}
PowerBroker2 commented 1 year ago

When the ELM327 responds with "STOPPED" it means the Arduino sent data to the scanner before it was finished with the current query. Not sure why that would happen, but perhaps try adding some delays? Otherwise, I'm not sure how to fix.

bborisov567 commented 1 year ago

Adding 1000ms delay did indeed helped! One last question - is it possible the returned trim value to go negative or the library calculates the value to be always positive?

PowerBroker2 commented 1 year ago

Yes, it can go negative. I used the formula found on the OBDII PID wiki: dadc5977cfe2af2bd9733d2564ec848e5a00804f

bborisov567 commented 1 year ago

Okay, than you!