I'm using the OBDII-UART adapter OBD II UART Hookup Guide - SparkFun Learn with an UNO and serial LCD
and using the the code on the tutorial
/*
* OBD-II-UART Quickstart Sketch
* Written by Ryan Owens for SparkFun Electronics
* 7/5/2011
*
* Released under the 'beer-me' license
* (Do what you want with the code, but if we ever meet then you buy me a beer)
*
* This sketch will grab RPM and Vehicle Speed data from a vehicle with an OBD port
* using the OBD-II-UART board from SparkFun electronics. The data will be displayed
* on a serial 16x2 LCD. See this tutorial to learn how to hook up the hardware:
*
*/
#include <NewSoftSerial.h>
//Create an instance of the new soft serial library to control the serial LCD
//Note, digital pin 3 of the Arduino should be connected to Rx of the serial LCD.
NewSoftSerial lcd(2,3);
//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(9600);
Serial.begin(9600);
//Clear the old data from the LCD.
lcd.print(254, BYTE);
lcd.print(1, BYTE);
//Put the speed header on the first row.
lcd.print("Speed: ");
lcd.print(254, BYTE);
//Put the RPM header on the second row.
lcd.print(128+64, BYTE);
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
Serial.println("ATZ");
//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.
Serial.flush();
}
void loop(){
//Delete any data that may be in the serial port before we begin.
Serial.flush();
//Set the cursor in the position where we want the speed data.
lcd.print(254, BYTE);
lcd.print(128+8, BYTE);
//Clear out the old speed data, and reset the cursor position.
lcd.print(" ");
lcd.print(254, BYTE);
lcd.print(128+8, BYTE);
//Query the OBD-II-UART for the Vehicle Speed
Serial.println("010D");
//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.print(vehicleSpeed);
lcd.print(" km/h");
delay(100);
//Delete any data that may be left over in the serial port.
Serial.flush();
//Move the serial cursor to the position where we want the RPM data.
lcd.print(254, BYTE);
lcd.print(128 + 69, BYTE);
//Clear the old RPM data, and then move the cursor position back.
lcd.print(" ");
lcd.print(254, BYTE);
lcd.print(128+69, BYTE);
//Query the OBD-II-UART for the Vehicle rpm
Serial.println("010C");
//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.print(vehicleRPM);
//Give the OBD bus a rest
delay(100);
}
//The getResponse function collects incoming data from the UART into the rxData buffer
// and only exits when a carriage return character is seen. Once the carriage return
// string is detected, the rxData buffer is null terminated (so we can treat it as a string)
// and the rxData index is reset to 0 so that the next string can be copied.
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(Serial.available() > 0){
//Start by checking if we've received the end of message character ('\r').
if(Serial.peek() == '\r'){
//Clear the Serial buffer
inChar=Serial.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 = Serial.read();
//Add the new character to the string, and increment the index variable.
rxData[rxIndex++]=inChar;
}
}
}
}
When I connect everything up all I get is
Speed: 13
RPM: 832
regardless of the engine running or not. There seems to be a few people out there with this problem but no solutions.
All I've found so far though my searches on the net is to change
Serial.println("????"); to Serial.print("????\r");
and change Serial.println("ATZ") to ("ATWS").
Neither of these make any difference.
My Tx and Rx lights are flashing on the OBDII-UART board, but I'm only getting the Tx light flashing on the UNO. I've checked the wiring and the Tx of one is connected to the Rx of the other and vice versa.
Is there a way to test if UNO is receiving Data using this setup.
I'm very new to all this so any help would be very much appreciated
Thanks in advance