Comments: OBD II Uart Hookup Guide

Pages

Comments 2 comments

  • In order that the serial communication works, the Baud rate needs to be set to 38.4 KBps

    I checked the ELM327 datasheet too, and it says that the default baudrate for serial communication is set to 38.4 KBps. The tutorial instructs to set the baud rate to 9600 bps. I think the tutorial needs to be updated with the correct baud rate.

  • I noticed that I am having an issue implementing this code with speeds above idle. I added a Serial.println after the program gives the command 010c to ask for RPM data and I notice the serial monitors starts to say STOPPED.

    Notes: My code is almost identical to the one outlined above except that I stripped out the speed sections and focused on RPM and I am using the Liquid Crystal library as opposed to the serial library as I do not know if the lcd I have has a serial interface.

    <#include <LiquidCrystal.h>
    
    LiquidCrystal lcd (12, 11, 5, 4, 3, 2);
    
    char rxData[20];
    char rxIndex=0;
    
    int vehicleRpm=0;
    
    void setup(){
      lcd.begin(16,2);
      Serial.begin(9600);
    
      lcd.setCursor(0,0);
    
      delay(1500);
    
      Serial.println("ATZ");
    
      delay(1500);
    
      Serial.flush();
    }
    
    void loop(){
    
      Serial.flush();
    
      lcd.setCursor(0,0);
    
      lcd.print("        ");
    
      Serial.println("010C");
      delay(1000);
    
      getResponse();
      getResponse();
    
      vehicleRpm = ((strtol(&rxData[6],0,16)*256)+strtol(&rxData[9],0,16))/4;
    
      Serial.println(rxData);
    
      lcd.print(vehicleRpm);
    
      delay(5000);
    }
    
    
    void getResponse(void){
      char inChar=0;
    
      while(inChar != '\r'){
    
        if(Serial.available() > 0){
    
          if(Serial.peek() == '\r'){
    
            inChar=Serial.read();
    
            rxData[rxIndex]='\0';
    
            rxIndex=0;
          } else {
            inChar = Serial.read();
    
            rxData[rxIndex++]=inChar;
          }
        }
      }
    }
    

    My results looking at the serial monitor resulted in the following:

    ATZ
    010C
    
    010C
    ELM327 v1.3a
    010C
    >010C
    010C
    STOPPED
    010C
    >010C
    010C
    STOPPED
    010C
    >a
    010C
    
    010C
    
    010C
    SEARCHSTOPPEDSTOPPED
    010C
    

    Any help would be greatly appreciated.


If you've found a bug or have other constructive feedback for our tutorial authors, please send us your feedback!