0
Offline
Full Member
Karma: 0
Posts: 224
Arduino rocks
|
 |
« Reply #15 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.
|
|
|
|
|
Logged
|
|
|
|
|
Switzerland
Offline
Faraday Member
Karma: 69
Posts: 3288
|
 |
« Reply #16 on: June 29, 2012, 10:52:41 am » |
Just to check that too: How did you made the connection from the Sparkfun board to the OBD-II? Did you buy the cable or is it self-made? If self-made, what connections did you wire through?
I'm asking this because the different protocols supported by the Sparkfun board uses different pins on the OBD-II connector. If you missed one or if something other in the cabling is wrong, you probably get what you get too.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 224
Arduino rocks
|
 |
« Reply #17 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/10087However 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.
|
|
|
|
|
Logged
|
|
|
|
|
Switzerland
Offline
Faraday Member
Karma: 69
Posts: 3288
|
 |
« Reply #18 on: June 29, 2012, 12:36:41 pm » |
I think this goes OK. Do you know which of the pins are connected in your car? Often you can see it by looking at the connector and you don't have to measure. This way you might get an idea which protocol is used.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 224
Arduino rocks
|
 |
« Reply #19 on: June 29, 2012, 12:40:58 pm » |
I don't know but can have a look.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 224
Arduino rocks
|
 |
« Reply #20 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.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 224
Arduino rocks
|
 |
« Reply #21 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
>
|
|
|
|
|
Logged
|
|
|
|
|
Switzerland
Offline
Faraday Member
Karma: 69
Posts: 3288
|
 |
« Reply #22 on: June 30, 2012, 12:27:24 pm » |
Looks like your Golf doesn't support the OBD-II standard. Maybe it just has the same connector but does not conform to the OBD-II standard.
BTW: The BMW uses ISO-9141 and does support most of the standard OBD-II PIDs in the first range (1-32).
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 224
Arduino rocks
|
 |
« Reply #23 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.
|
|
|
|
|
Logged
|
|
|
|
|
Switzerland
Offline
Faraday Member
Karma: 69
Posts: 3288
|
 |
« Reply #24 on: July 01, 2012, 12:40:09 pm » |
Can you show what you've done? Code?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 224
Arduino rocks
|
 |
« Reply #25 on: July 01, 2012, 02:38:28 pm » |
This is what I tested first: #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; } } } }
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 224
Arduino rocks
|
 |
« Reply #26 on: July 01, 2012, 02:45:58 pm » |
This is what I tried next: #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; } } } }
|
|
|
|
|
Logged
|
|
|
|
|
Switzerland
Offline
Faraday Member
Karma: 69
Posts: 3288
|
 |
« Reply #27 on: July 02, 2012, 04:48:08 am » |
Insert debugging statements that put out everything you get on the Serial1 to the Serial. This way you see the raw data and you can distinguish between irregular data you get from the engine and errors in interpreting it. At least your BMW says it supports the speed and RPM PIDs (010D and 010C).
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 224
Arduino rocks
|
 |
« Reply #28 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.
|
|
|
|
|
Logged
|
|
|
|
|
Switzerland
Offline
Faraday Member
Karma: 69
Posts: 3288
|
 |
« Reply #29 on: July 02, 2012, 07:08:22 am » |
If you change the code to put out to the PC serial instead of the LCD, I will test it for you. I have a graphical LCD on my OBD-Arduino, so your code will not work the way it currently is.
Also keep in mind, that different cars are different, especially in this regard. My car uses the CAN bus, your brother's BMW uses ISO 9141. Just reading the RPMs and speed values should work on most OBD-II compatible cars though.
|
|
|
|
|
Logged
|
|
|
|
|
|