Getting started - DTC management?

Inquiry and support for Freematics products
BoxOfSnoo
Posts: 12
Joined: Tue Jun 24, 2014 6:35 am

Getting started - DTC management?

Post by BoxOfSnoo »

Has anyone retrieved trouble codes using this adapter? The supplied code doesn't seem to address this, it looks like it can be done but it's not immediately apparent how to do so.

I found this library on GitHub addressing the ELM327 functionality but I'm not sure if it hasn't already been implemented in the Freematics code.

Does anyone have sample code for retrieving - and resetting - DTCs? I know it's Mode 3 and returns 6 bytes to request but not sure of the syntax to put in the loop.

Thanks.

Edit: While you're thinking about that, more questions...

I found out this is the sequence I'm supposed to write;
01 01 (Returns 41 xx where xx is the number of codes)
03 (Returns ALL the codes in a 6-byte string, one for each code)

and when done...
04 (Reset)

So will this work? (Sorry I don't have my device yet, I can't just test it)

Code: Select all

obd.write("01 01");
int numResult = obd.receive(&buffer,1000); // presumably I will have initialized buffer elsewhere


I'm not sure how to initialize the unit yet, either.
Last edited by BoxOfSnoo on Mon Jun 30, 2014 4:46 am, edited 1 time in total.
stanley
Site Admin
Posts: 1026
Joined: Sat Mar 01, 2014 3:15 am

Re: Getting started - DTC management?

Post by stanley »

To query a specific PID, make sure to terminate the command with \r. So it should be "0101\r". The code is like this:

Code: Select all

char buffer[64];
obd.write("0101\r");
int bytesReceived = obd.receive(buffer,1000);

if bytesReceived is greater than zero, buffer has the response string and all you need to do is parsing it the way you like.
AADOY
Posts: 1
Joined: Wed Jul 02, 2014 2:15 pm

Re: Getting started - DTC management?

Post by AADOY »

I'm trying to do the same thing. where did i need to put that code?
or how can i get the trouble codes?
stanley
Site Admin
Posts: 1026
Joined: Sat Mar 01, 2014 3:15 am

Re: Getting started - DTC management?

Post by stanley »

That code is for Arduino sketch.
BoxOfSnoo
Posts: 12
Joined: Tue Jun 24, 2014 6:35 am

Re: Getting started - DTC management?

Post by BoxOfSnoo »

stanley wrote:To query a specific PID, make sure to terminate the command with \r. So it should be "0101\r". The code is like this:

Code: Select all

char buf[64];
obd.write("0101\r");
int bytesReceived = obd.receive(buffer,1000);

if bytesReceived is greater than zero, buffer has the response string and all you need to do is parsing it the way you like.


That's extremely useful, thank you!

I presume you meant buf instead of buffer. Do I not need to pass it as a pointer?

Next task, to get the actual codes... that's probably

obd.write("03\r");

and expect back any number of 6-byte responses (plus a linefeed, I guess)
stanley
Site Admin
Posts: 1026
Joined: Sat Mar 01, 2014 3:15 am

Re: Getting started - DTC management?

Post by stanley »

Right. It was a typo. :D
BoxOfSnoo
Posts: 12
Joined: Tue Jun 24, 2014 6:35 am

Re: Getting started - DTC management?

Post by BoxOfSnoo »

This is where I am at this point, getting the actual codes should be very similar. Does it look reasonable? Do you know if the commands and responses are bytes or are they strings - including or excluding the separating space?

It's still at a debugging stage, obviously, and I haven't received data I can use, just yet. I thought this might help some others too.

Thanks

Code: Select all

    void queryDTCCount()
    {
      char buffer[64];
      write("0101\r");  // send OBD request for DTCs
      int bytesReceived = receive(buffer,1000);
      buffer[bytesReceived+1] = 0;  // just in case, terminate the string

      if (bytesReceived>0) {

         // Response should be "41 01 xx yy yy yy"
         // looking for the value in xx

#if LCD_DISPLAY
         int response = strncmp(buffer,"41",2);
         if (response > 0) {
            lcd.print("OK");
            lcd.println(buffer);

// if (val3 & 128) { // MIL is on
//   val3 = val3 - 128;
// }
           
            queryDTCs();
         } else {
            lcd.print("No");
            lcd.println(buffer);
         }
         
#endif
      }

    }
stanley
Site Admin
Posts: 1026
Joined: Sat Mar 01, 2014 3:15 am

Re: Getting started - DTC management?

Post by stanley »

Response is a zero terminated string with padded space between each 2-char hex.
BoxOfSnoo
Posts: 12
Joined: Tue Jun 24, 2014 6:35 am

Re: Getting started - DTC management?

Post by BoxOfSnoo »

I forked your project to work on this, if you like you can see my changes at https://github.com/BoxOfSnoo/Freematics

Note firmware_v2/codelogger - I have DTC functions in there that seem to work (no reset, yet). You are welcome to integrate the code, I can send you a pull request if you like.

I plan to add DTC logging to the SD card - in a separate file from the existing data log. I may extract this code into another file for cleanliness.

One other question was when the query for DTCs should be made. Right now I'm doing it at setup, but since my OBD port seems to be powered whether the key is on or not, it only happens when the device is plugged in. That's a little clumsy for a device that should really live in the port all the time. I could do it in the loop, but with a 1 second timeout that would slow everything down. Any suggestions?

Also I would like to request that you include the DTCs in the iOS application, that would be pretty important, and eliminate the need for the LCD interface. A smaller request would be to have some kind of button in the app that sends a signal back to the adapter, this could be used to request the DTCs on demand (and optionally reset them). This would bring the combo of app and adapter up to par with other apps/interfaces.
stanley
Site Admin
Posts: 1026
Joined: Sat Mar 01, 2014 3:15 am

Re: Getting started - DTC management?

Post by stanley »

I will take a look at your code!
As for iOS App, are you capable of iOS development?
Post Reply