Giter Club home page Giter Club logo

Comments (14)

thebeardedgarage avatar thebeardedgarage commented on June 7, 2024 1

See Issue #44, parsing response data

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on June 7, 2024

Please post your formatted code and debug printouts.

from elmduino.

415Robots avatar 415Robots commented on June 7, 2024
#include "BluetoothSerial.h"
#include "ELMduino.h"

BluetoothSerial SerialBT;
ELM327 myELM327;

double var = 1.0;

void setup()
{
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);

  SerialBT.begin("ArduHUD", true);
  if (!SerialBT.connect("OBDII"))
  {
    Serial.println(F("Couldn't connect to OBD scanner - Phase 1"));
    while (1);
  }

  if (!myELM327.begin(SerialBT, true, 2000))
  {
    Serial.println(F("Couldn't connect to OBD scanner - Phase 2"));
    while (1);
  }
  
  Serial.println(F("Connected to ELM327"));
}


void loop() {
  var = myELM327.processPID(34, 82, 1, 1, 100.0/255.0,0);

  if (myELM327.nb_rx_state == ELM_SUCCESS) {
    Serial.print("Ethanol (%): ");
    Serial.println(var);
  } else {
    Serial.println("Failed to read Transmission Temperature or PID not supported.");
  }

  delay(200); // Delay between reads
}

data output
debug
test_ino_data

from elmduino.

jimwhitelaw avatar jimwhitelaw commented on June 7, 2024

@415Robots Your loop needs to handle the case where the code is still getting the data from the ELM device. Try this in your loop():

if (myELM327.nb_rx_state == ELM_SUCCESS)
      {
       Serial.print("Ethanol (%): ");
       Serial.println(var);
      }
      else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
      {
        myELM327.printError();
      }

That will allow the full response message to be received before being processed.

Also, the code shown in your two screenshots are both different than the code you posted, so it's not clear what code is actually running...

from elmduino.

415Robots avatar 415Robots commented on June 7, 2024

Thanks for the feedback, I'll add the print Error and post the results. I only have limited access to the vehicle, so the testing was a lot of modifying working code to try to get PID 220052 to work, apologies for the confusion.

  • Screenshot 1: Output from processPID with the following inputs: Service = 34 (0x22 = 34), PID = 82 (0x52 =82)
  • Screenshot 2: Debug information showing the query string, Service, and PID
  • Screenshot 3: Testing to see if "220052" is a valid PID using powerbroker's test.ino example with the serial input of "220052" and "340082". If you look at the last byte of the highlighted data in the message, you'll see the value C6. Applying the conversion from hex to percentage, the result yields the expected result of 77.6%.

Sidenote: I definitely will check out the ELMulator, I really could use some kind of bench test for this project.

from elmduino.

415Robots avatar 415Robots commented on June 7, 2024

Added the else if to target the non ELM_GETTING_MSG states, but it doesn't seem to generate an error... or I am doing it wrong. Results in the
Ethanol test with terminal
attached:

from elmduino.

jimwhitelaw avatar jimwhitelaw commented on June 7, 2024

You are not doing it wrong, and you should not expect an error. What I see happening now is that you’re getting a CAN “Response Pending” message (7Fxxxx). ELMduino doesn’t currently handle this type of response, and instead it returns zero. See p. 45 of the Elm327 datasheet for info.

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on June 7, 2024

@415Robots Can you either post the debug printouts in the text of your comments (formatted please) or post the screenshots different? It's hard for me to read in the screenshots and when I try to download the hires, github comes up with an empty page for some reason...

Either way, it looks like the response header for service 2 (or whichever service you're using) doesn't behave like response headers for service 1.

from elmduino.

thebeardedgarage avatar thebeardedgarage commented on June 7, 2024

21:54:08.931 -> Ethanol (%): 0.00
21:54:09.119 -> Service: 34
21:54:09.119 -> PID: 82
21:54:09.119 -> Normal length query detected
21:54:09.119 -> Query string: 22521
21:54:09.119 -> Clearing input serial buffer
21:54:09.157 -> Sending the following command/query: 22521
21:54:09.321 -> Received char: 7
21:54:09.534 -> Received char: F
21:54:09.755 -> Received char: 2
21:54:09.940 -> Received char: 2
21:54:10.153 -> Received char: 1
21:54:10.321 -> Received char: 2
21:54:10.534 -> Received char: \r
21:54:10.755 -> Received char: \r
21:54:10.932 -> Received char: >
21:54:10.932 -> Delimiter found.
21:54:10.932 -> All chars received: 7F2212
21:54:10.932 -> Expected response header: 6252
21:54:10.932 -> Response not detected
21:54:10.932 -> WARNING: Number of payload chars is less than the number of expected response chars returned by ELM327 - returning 0
21:54:10.984 -> Ethanol (%): 0.00
21:54:11.154 -> Service: 34
21:54:11.154 -> PID: 82
21:54:11.154 -> Normal length query detected
21:54:11.154 -> Query string: 22521
21:54:11.154 -> Clearing input serial buffer
21:54:11.154 -> Sending the following command/query: 22521
21:54:11.368 -> Received char: 7
21:54:11.581 -> Received char: F
21:54:11.772 -> Received char: 2
21:54:11.958 -> Received char: 2
21:54:12.180 -> Received char: 1
21:54:12.354 -> Received char: 2
21:54:12.559 -> Received char: \r
21:54:12.771 -> Received char: \r
21:54:12.970 -> Received char: >
21:54:12.970 -> Delimiter found.
21:54:12.970 -> All chars received: 7F2212
21:54:12.970 -> Expected response header: 6252
21:54:12.970 -> Response not detected
21:54:12.970 -> WARNING: Number of payload chars is less than the number of expected response chars returned by ELM327 - returning 0
21:54:13.024 -> Ethanol (%): 0.00
21:54:13.202 -> Service: 34
21:54:13.202 -> PID: 82
21:54:13.202 -> Normal length query detected
21:54:13.202 -> Query string: 22521
21:54:13.202 -> Clearing input serial buffer
21:54:13.202 -> Sending the following command/query: 22521
21:54:13.418 -> Received char: 7
21:54:13.587 -> Received char: F
21:54:13.801 -> Received char: 2
21:54:14.179 -> Received char: 2
21:54:14.189 -> Received char: 1
21:54:14.404 -> Received char: 2
21:54:14.606 -> Received char: \r
21:54:14.819 -> Received char: \r
21:54:14.988 -> Received char: >
21:54:14.988 -> Delimiter found.
21:54:14.988 -> All chars received: 7F2212
21:54:15.167 -> Expected response header: 6252
21:54:15.167 -> Response not detected
21:54:15.167 -> WARNING: Number of payload chars is less than the number of expected response chars returned by ELM327 - returning 0

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on June 7, 2024

I'm not sure if this is a CAN error/warning as mentioned earlier or if this is how a service 32 PID response header is supposed to look like - can you provide more info on this custom PID? Do you have any documentation on it? I'm conflicted on whether I should make a special case for it in the lib or not.

from elmduino.

thebeardedgarage avatar thebeardedgarage commented on June 7, 2024

Hello Powerbroker2, I am in the same situation as @415Robots. The information I have recieved on this PID is from the torque pro app.

PID: 220052
Min. Value: 0
Max Value:100
Scale Factor: x1
Unit type: %
Equation: A/255*100

When running this pid through the obd2 editor in torque app, I get this response:

Screenshot_20240123_224517_Torque

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on June 7, 2024

I'm still unsure of how the PID is supposed to work and how to calculate what the response header should be. Is there any actual documentation of the PID or PID response?

from elmduino.

thebeardedgarage avatar thebeardedgarage commented on June 7, 2024

Using your test.ino sketch, here is the response for 220052. The last byte of the highlighted data in the message, you'll see the value C6. Applying the conversion from hex to decimal (C6=198), 198/255*100 the result yields the expected result of 77.6%.

Screenshot_20240128_112350_Samsung Internet

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on June 7, 2024

Idk what was going on in the previous set of debug prints, but this particular response looks similar to what I would expect. Notice how the response header's first byte is +4 compared to the query response header's first byte. The library in findResponse() is setup to handle this case, even for 6-byte PID queries:

ELMduino/src/ELMduino.cpp

Lines 2327 to 2335 in 77874c0

if (longQuery)
{
header[0] = query[0] + 4;
header[1] = query[1];
header[2] = query[2];
header[3] = query[3];
header[4] = query[4];
header[5] = query[5];
}

I think more detailed debugging will be required to figure out what is going wrong.

from elmduino.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.