Can't get OBD RPM to log

Hey guys so I’ve been working on a data logger and have gotten everything to work except the OBD part.

When I use the example, the setup works fine. The arduino reads the RPM and lights up the LED if it exceeds 1000rpm. (I know the example I posted says 3000)

However, when I try to read the RPM in my sketch, it will just report 0 and not the RPM. Any ideas?

rpm_led_uart.ino (856 Bytes)

Logger.ino (3.33 KB)

      float temp = ( - '0');
      refresh_rate = temp;

The read method returns an int. From that, you subtract a char, and store the result in a float. Can you explain why?

  // start communication with OBD-II UART adapter
  // initiate OBD-II connection until success
  while (!obd.init());  

{What} {are} {the} {curly} {braces} {for} {?}

    int RPM;
    RPM =, RPM);

The read() method reads some data from the device, and stores it in the second argument, and returns a value. I’m not familiar with the library, but I’d guess that read() returns 0 for success. You store that in RPM, trashing what read() put in RPM. Why?

The first 2 sections you quote were copied out of an example. Not sure why what you are questioning is there.

I will try and remove the RPM = part and see what happens.


So I tried the following code and it did not work. It returned a value of 767 but that was not the correct RPM nor did it change as input was altered.

int RPM;, RPM);

I also tried editing the example sketch by adding Serial.println(value); but it returned random letters and symbols.

I attached the OBD library is that helps.

OBD.h (5.94 KB)

OBD.cpp (10.2 KB)

I am now getting random values for RPM. It stays at 2156 and doesn't move. Any ideas anybody?

I don't understand why the example works fine but I can't get the value to store and write to the SD card

Which model OBD reader do you have? Model A or B?

COBD obd; /* for Model A (UART version) */

This code is for the Model A which runs on the Serial UART RX and TX.

I wonder if there is some interaction with the Serial.print() statements in your code. Possible Baud Rate issues?What rpm values you can log if you remove the Serial printing?

Model A I believe.

It logs the same value without the serial printing lines.

From OBD.h


Try setting your sketch Serial.begin(38400). Or modify the .h file for 9600.

Try to add a serial print statement or SD logging to the rpm_led_uart sketch

That did it! Thank you so much for that.

Now I just have to figure out how to speed up the readings. It seems, my logger only records every 1.5 seconds or so.

what is the refresh rate?

//Read the Configuration information (Rate.txt)
  File commandFile ="Rate.txt");
  if (commandFile)
    Serial.println("Reading Command File");
    float decade = pow(10, (commandFile.available() - 1));
      float temp = ( - '0');
      refresh_rate = temp;
    Serial.print("Refresh Rate = ");

I removed that part of code because it was not working correctly. I copied that part out of an example I found somewhere and while it worked fine in the example, it would not work in my code.

So there are no delays written in the code as of now.

It also made the File header write command not work for some reason. After removing that section of code, the file headers write correctly to the SD card file.

I found a previous thread about speeding up the UART adapters by messing with the timings in the library. However, I had the same issue as he did with inconsistent data.

I also tried changing the baud rate but on my particular version (v1.2), I don't believe I can. I read in the OBD library that I need a V2 to be able to change the baud rate. I just got garbled data spitting back in my serial monitor and the code never began.

I removed all the serial print lines from the code and it is MUCH faster. I was able to get about 350 strings of data in a 30 second sample.