Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 17
61  Using Arduino / Networking, Protocols, and Devices / Re: OBDII to UART Issues on: July 05, 2012, 06:19:54 am
Here is my version of OBDuino from their code:

Code:
//This is a character buffer that will store the data from the serial port
char rxData[20];
char rxIndex=0;

//Variables to hold the speed and RPM data.
int vehicleSpeed=0;
int vehicleRPM=0;

void setup(){

  Serial1.begin(9600);
  Serial.begin(9600);   //This is for the serial debug

  //Wait for a little while before sending the reset command to the OBD-II-UART
  delay(1500);
  //Reset the OBD-II-UART
  Serial1.print("ATWS\r");
  //Wait for a bit before starting to send commands after the reset.
  delay(1000);
 
  // turn echo off
  Serial1.print("ATE0\r");
 
  // send 01 00 until we are connected
  do
  {
    Serial1.print("0100\r");
    delay(1000);
    getResponse();    //This is only called once since the schoecho has been turned off using ATE0\r
    Serial.print("0100 Response:  ");
    Serial.print(rxData[0]);Serial.print(rxData[1]);Serial.print(rxData[3]);Serial.print(rxData[4]);Serial.print(rxData[6]);Serial.print(rxData[7]); Serial.print(rxData[9]);Serial.print(rxData[10]);
    Serial.println("");
  }
  while(ELM_CHECK_RESPONSE("0100", rxData)!=0);
   
  Serial1.flush();
   
  Serial1.print("ATDPN\r");  //Shows the protocol
  getResponse();
  Serial.print("Protocol: ");Serial.print(rxData[0]);Serial.print(rxData[1]);Serial.println("");
  // str[0] should be 'A' for automatic
  // set header to talk directly to ECU#1
  if(rxData[1]=='1')  // PWM
    Serial1.print("ATSHE410F1\r");
  else if(rxData[1]=='2')  // VPW
    Serial1.print("ATSHA810F1\r");
  else if(rxData[1]=='3')  // ISO 9141
    Serial1.print("ATSH6810F1\r");
  else if(rxData[1]=='6')  // CAN 11 bits
    Serial1.print("ATSH7E0\r");
  else if(rxData[1]=='7')  // CAN 29 bits
    Serial1.print("ATSHDA10F1\r");
 
  //Delete any data that may be in the serial port before we begin.
  Serial1.flush();

}


void loop(){
  //Delete any data that may be in the serial port before we begin. 
  Serial1.flush();

  Serial1.print("010D\r");    //Query the OBD-II-UART for the Vehicle Speed

  //Get the response from the OBD-II-UART board. We get two responses
  //because the OBD-II-UART echoes the command that is sent.
  //We want the data in the second response.
  getResponse();

  //Convert the string data to an integer
  vehicleSpeed = strtol(&rxData[6],0,16);

  //Print the speed data to debug serial window
  Serial.print("SPEED: ");
  Serial.print(vehicleSpeed);
  Serial.print(" km/h");
  Serial.println(" ");
 
  delay(20);
 
  //Delete any data that may be left over in the serial port.
  Serial1.flush();

  //Query the OBD-II-UART for the Vehicle rpm
  Serial1.println("010C\r");
  //Get the response from the OBD-II-UART board
  getResponse();

  //Convert the string data to an integer
  //NOTE: RPM data is two bytes long, and delivered in 1/4 RPM from the OBD-II-UART
  vehicleRPM = ((strtol(&rxData[6],0,16)*256)+strtol(&rxData[9],0,16))/4;

  //Print the rpm data to debug serial window
  Serial.print("RPM: ");
  Serial.print(vehicleRPM);
  Serial.println(" ");

  //Give the OBD bus a rest
  delay(50);
 
}


byte ELM_CHECK_RESPONSE(const char *cmd, char *str)
{
  // cmd is something like "010D"
  // str should be "41 0D blabla"
  if(cmd[0]+4 != rxData[0]
    || cmd[1]!= rxData[1]
    || cmd[2]!= rxData[3]
    || cmd[3]!= rxData[4])
    return 1;

  return 0;  // no error
}


void getResponse(void){
  char inChar=0;
  //Keep reading characters until we get a carriage return
  while(inChar != '\r'){
    //If a character comes in on the serial port, we need to act on it.
    if(Serial1.available() > 0){
      //Start by checking if we've received the end of message character ('\r').
      if(Serial1.peek() == '\r'){
        //Clear the Serial buffer
        inChar=Serial1.read();
        //Put the end of string character on our data string
        rxData[rxIndex]='\0';
        //Reset the buffer index so that the next character goes back at the beginning of the string.
        rxIndex=0;
      }
      //If we didn't get the end of message character, just add the new character to the string.
      else{
        //Get the new character from the Serial port.
        inChar = Serial1.read();
        //Add the new character to the string, and increment the index variable.
        rxData[rxIndex++]=inChar;
      }
    }
  }
}
62  Using Arduino / Networking, Protocols, and Devices / Re: OBDII to UART Issues on: July 05, 2012, 04:29:45 am
Your version of OBDuino.
63  Using Arduino / Networking, Protocols, and Devices / Re: OBDII to UART Issues on: July 05, 2012, 04:21:45 am
Hi there and thanks for your time and effort testing the code, I very much appreciate it!

The protocol will be fixed for the moment as it will going on 1 particular car, but it would be good to make it "universal".

Would there be anyway of sharing your code with me at all?

Thanks.
64  Using Arduino / Networking, Protocols, and Devices / Re: OBDII to UART Issues on: July 04, 2012, 12:01:20 pm
Hi,

Any luck with the testing? Thanks man.
65  Using Arduino / Networking, Protocols, and Devices / Re: OBDII to UART Issues on: July 02, 2012, 08:08:54 am
Here it is, much appreciated. Just gonna test RPM and speed for now.

Code:
//This is a character buffer that will store the data from the serial port
char rxData[20];
char rxIndex=0;

//Variables to hold the speed and RPM data.
int vehicleSpeed=0;
int vehicleRPM=0;

void setup(){

  Serial1.begin(9600);
  Serial.begin(9600);   //This is for the serial debug

  //Wait for a little while before sending the reset command to the OBD-II-UART
  delay(1500);
  //Reset the OBD-II-UART
  Serial1.print("ATWS\r");
  //Wait for a bit before starting to send commands after the reset.
 
  delay(1000);
 
  Serial1.print("ATDPN\r");  //Shows the protocol
  delay(1000);
 
  Serial1.print("0100\r"); 
  delay(2000);
 
  //Delete any data that may be in the serial port before we begin.
  Serial1.flush();

}


void loop(){
  //Delete any data that may be in the serial port before we begin. 
  Serial1.flush();

  Serial1.print("010D\r");    //Query the OBD-II-UART for the Vehicle Speed

  //Get the response from the OBD-II-UART board. We get two responses
  //because the OBD-II-UART echoes the command that is sent.
  //We want the data in the second response.
  getResponse();
  getResponse();

  //Convert the string data to an integer
  vehicleSpeed = strtol(&rxData[6],0,16);

  //Print the speed data to debug serial window
  Serial.print("SPEED: ");
  Serial.print(vehicleSpeed);
  Serial.print(" km/h");
  Serial.println(" ");
 
  delay(20);
 
  //Delete any data that may be left over in the serial port.
  Serial1.flush();

  //Query the OBD-II-UART for the Vehicle rpm
  Serial1.println("010C\r");
  //Get the response from the OBD-II-UART board
  getResponse();
  getResponse();
  //Convert the string data to an integer
  //NOTE: RPM data is two bytes long, and delivered in 1/4 RPM from the OBD-II-UART
  vehicleRPM = ((strtol(&rxData[6],0,16)*256)+strtol(&rxData[9],0,16))/4;

  //Print the rpm data to debug serial window
  Serial.print("RPM: ");
  Serial.print(vehicleRPM);
  Serial.println(" ");

  //Give the OBD bus a rest
  delay(50);
 
}



void getResponse(void){
  char inChar=0;
  //Keep reading characters until we get a carriage return
  while(inChar != '\r'){
    //If a character comes in on the serial port, we need to act on it.
    if(Serial1.available() > 0){
      //Start by checking if we've received the end of message character ('\r').
      if(Serial1.peek() == '\r'){
        //Clear the Serial buffer
        inChar=Serial1.read();
        //Put the end of string character on our data string
        rxData[rxIndex]='\0';
        //Reset the buffer index so that the next character goes back at the beginning of the string.
        rxIndex=0;
      }
      //If we didn't get the end of message character, just add the new character to the string.
      else{
        //Get the new character from the Serial port.
        inChar = Serial1.read();
        //Add the new character to the string, and increment the index variable.
        rxData[rxIndex++]=inChar;
      }
    }
  }
}
66  Using Arduino / Networking, Protocols, and Devices / Re: OBDII to UART Issues on: July 02, 2012, 06:32:14 am
I won't be able to test until I find another car close to me, that's OBDII compatible.

Does the code look fine to you? Also will you be kind enough to test the code for me if you have access to the board/car? If not, don't worry.

Thanks.
67  Using Arduino / Networking, Protocols, and Devices / Re: OBDII to UART Issues on: July 01, 2012, 02:45:58 pm
This is what I tried next:

Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(26,28,30,32,34,36);

//This is a character buffer that will store the data from the serial port
char rxData[20];
char rxIndex=0;

//Variables to hold the speed and RPM data.
int vehicleSpeed=0;
int vehicleRPM=0;

void setup(){
  //Both the Serial LCD and the OBD-II-UART use 9600 bps.
  lcd.begin(4, 20);    

  Serial1.begin(9600);
//  Serial.begin(9600);
  
  //Clear the old data from the LCD.
  lcd.clear();
  
  //Put the speed header on the first row.

  lcd.print("Speed: ");

  //Put the RPM header on the second row.
  lcd.setCursor(0,1);
  lcd.print("RPM: ");

        lcd.setCursor(0,2);
        lcd.print("Coolant");
  
  //Wait for a little while before sending the reset command to the OBD-II-UART
  delay(1500);
  //Reset the OBD-II-UART
  Serial1.print("ATWS/r");
  //Wait for a bit before starting to send commands after the reset.
  delay(1000);
  
  Serial1.print("ATDPN/r");  //Shows the protocol
  delay(1000);
  
  Serial1.print("0100/r");  
  delay(2000);
  
  //Delete any data that may be in the serial port before we begin.
  Serial1.flush();
}


void loop(){
  //Delete any data that may be in the serial port before we begin.  
  Serial1.flush();
  //Set the cursor in the position where we want the speed data.

  //Clear out the old speed data, and reset the cursor position.
//  lcd.setCursor(10,0);
//  lcd.print("   ");

  //Query the OBD-II-UART for the Vehicle Speed
  Serial1.print("010D\r");
  //Get the response from the OBD-II-UART board. We get two responses
  //because the OBD-II-UART echoes the command that is sent.
  //We want the data in the second response.
  getResponse();
  getResponse();
  //Convert the string data to an integer
  vehicleSpeed = strtol(&rxData[6],0,16);
  //Print the speed data to the lcd
  lcd.setCursor(10,0);
  lcd.print(vehicleSpeed);
  

  
  lcd.setCursor(16,0);
  lcd.print("km/h");
  delay(100);
  
  //Delete any data that may be left over in the serial port.
  Serial1.flush();

  //Query the OBD-II-UART for the Vehicle rpm
  Serial1.print("010C\r");
  //Get the response from the OBD-II-UART board
  getResponse();
  getResponse();
  //Convert the string data to an integer
  //NOTE: RPM data is two bytes long, and delivered in 1/4 RPM from the OBD-II-UART
  vehicleRPM = ((strtol(&rxData[6],0,16)*256)+strtol(&rxData[9],0,16))/4;
  //Print the rpm data to the lcd
  lcd.setCursor(10,1);
  lcd.print(vehicleRPM);

  //Give the OBD bus a rest
  delay(100);

}



void getResponse(void){
  char inChar=0;
  //Keep reading characters until we get a carriage return
  while(inChar != '\r'){
    //If a character comes in on the serial port, we need to act on it.
    if(Serial1.available() > 0){
      //Start by checking if we've received the end of message character ('\r').
      if(Serial1.peek() == '\r'){
        //Clear the Serial buffer
        inChar=Serial1.read();
        //Put the end of string character on our data string
        rxData[rxIndex]='\0';
        //Reset the buffer index so that the next character goes back at the beginning of the string.
        rxIndex=0;
      }
      //If we didn't get the end of message character, just add the new character to the string.
      else{
        //Get the new character from the Serial port.
        inChar = Serial1.read();
        //Add the new character to the string, and increment the index variable.
        rxData[rxIndex++]=inChar;
      }
    }
  }
}
68  Using Arduino / Networking, Protocols, and Devices / Re: OBDII to UART Issues on: July 01, 2012, 02:38:28 pm
This is what I tested first:

Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(26,28,30,32,34,36);

//This is a character buffer that will store the data from the serial port
char rxData[20];
char rxIndex=0;

//Variables to hold the speed and RPM data.
int vehicleSpeed=0;
int vehicleRPM=0;

void setup(){
  //Both the Serial LCD and the OBD-II-UART use 9600 bps.
  lcd.begin(4, 20);   

  Serial1.begin(9600);
//  Serial.begin(9600);
 
  //Clear the old data from the LCD.
  lcd.clear();
 
  //Put the speed header on the first row.

  lcd.print("Speed: ");

  //Put the RPM header on the second row.
  lcd.setCursor(0,1);
  lcd.print("RPM: ");

  //Wait for a little while before sending the reset command to the OBD-II-UART
  delay(1500);
  //Reset the OBD-II-UART
  Serial1.print("ATZ\r");
  //Wait for a bit before starting to send commands after the reset.
 
  delay(2000);
 
  //Delete any data that may be in the serial port before we begin.
  Serial1.flush();
}


void loop(){
  //Delete any data that may be in the serial port before we begin. 
  Serial1.flush();
  //Set the cursor in the position where we want the speed data.

  //Clear out the old speed data, and reset the cursor position.
//  lcd.setCursor(10,0);
//  lcd.print("   ");

  //Query the OBD-II-UART for the Vehicle Speed
  Serial1.print("010D\r");
  //Get the response from the OBD-II-UART board. We get two responses
  //because the OBD-II-UART echoes the command that is sent.
  //We want the data in the second response.
  getResponse();
  getResponse();
  //Convert the string data to an integer
  vehicleSpeed = strtol(&rxData[6],0,16);
  //Print the speed data to the lcd
  lcd.setCursor(10,0);
  lcd.print(vehicleSpeed);
 

 
  lcd.setCursor(16,0);
  lcd.print("km/h");
  delay(100);
 
  //Delete any data that may be left over in the serial port.
  Serial1.flush();


  //Query the OBD-II-UART for the Vehicle rpm
  Serial1.print("010C\r");
  //Get the response from the OBD-II-UART board
  getResponse();
  getResponse();
  //Convert the string data to an integer
  //NOTE: RPM data is two bytes long, and delivered in 1/4 RPM from the OBD-II-UART
  vehicleRPM = ((strtol(&rxData[6],0,16)*256)+strtol(&rxData[9],0,16))/4;
  //Print the rpm data to the lcd
  lcd.setCursor(10,1);
  lcd.print(vehicleRPM);

  //Give the OBD bus a rest
  delay(100);
 

}



void getResponse(void){
  char inChar=0;
  //Keep reading characters until we get a carriage return
  while(inChar != '\r'){
    //If a character comes in on the serial port, we need to act on it.
    if(Serial1.available() > 0){
      //Start by checking if we've received the end of message character ('\r').
      if(Serial1.peek() == '\r'){
        //Clear the Serial buffer
        inChar=Serial1.read();
        //Put the end of string character on our data string
        rxData[rxIndex]='\0';
        //Reset the buffer index so that the next character goes back at the beginning of the string.
        rxIndex=0;
      }
      //If we didn't get the end of message character, just add the new character to the string.
      else{
        //Get the new character from the Serial port.
        inChar = Serial1.read();
        //Add the new character to the string, and increment the index variable.
        rxData[rxIndex++]=inChar;
      }
    }
  }
}
69  Using Arduino / Networking, Protocols, and Devices / Re: OBDII to UART Issues on: June 30, 2012, 12:42:06 pm
Looks like it.

This will eventually go on a GM ls9 engine manufactured in 2010.

The code I provided at the start of this thread didn't work with the BMW though
 I even changed the restart sequence to the last one you provided, but couldn't get any data back.

Any ideas?

Thanks.
70  Using Arduino / Networking, Protocols, and Devices / Re: OBDII to UART Issues on: June 30, 2012, 11:38:21 am
And when I put these:

ATWS


ELM327 v1.3a

>ATDPN
A3

>0100
41 00 BF 9F F9 91

>
71  Using Arduino / Networking, Protocols, and Devices / Re: OBDII to UART Issues on: June 30, 2012, 11:35:39 am
For BMW 3 series 2004.

When I put ATZ, then ATSP0, then 0100 I get these:

0100
SEARCHING...
41 00 BF 9F F9 91
41 00 80 00 00 00

>

So we know it was the car, and not the board.
72  Using Arduino / Networking, Protocols, and Devices / Re: OBDII to UART Issues on: June 29, 2012, 12:40:58 pm
I don't know but can have a look.

73  Using Arduino / Networking, Protocols, and Devices / Re: OBDII to UART Issues on: June 29, 2012, 11:23:13 am
I bought an OBDII to DB9 cable from eBay. I have checked the pins and are exactly like this one:

http://www.sparkfun.com/products/10087

However on the OBD connector, pin 5 is connected to pin 4. Pin 5 on the OBDII connector is not connected to pin 1 of the DB9 connector.
74  Using Arduino / Networking, Protocols, and Devices / Re: OBDII to UART Issues on: June 29, 2012, 10:44:48 am
Hi,

I am sure my car has OBDII, all the Golf MK4's have them.

I am can try tomorrow with my brother's 2004 BMW 3 series and his Jaguar XF 2008.

Thanks.
75  Using Arduino / Networking, Protocols, and Devices / Re: OBDII to UART Issues on: June 29, 2012, 10:15:35 am
This is what I get:

ATWS


ELM327 v1.3a

>

ATDPN
A

>

0100
CAN ERROR

>
Pages: 1 ... 3 4 [5] 6 7 ... 17