Currently I have begun working with the OBDII UART card connected to the Arduino board, I followed the example is the page of the card OBD II UART Hookup Guide - SparkFun Learn, but when I set the protocol sends me Ok, but when I ask for the speed I send a message from Seeking I do not understand ... that's what happens
Currently I have been doing a project where I need to know the speed of the vehicle, I have implemented the following code but the results have not been good because when the vehicle is in motion always prints STOPPED
I connected the OBDII-UART card with Sparkfun Arduino MEGA.
I really need help
- char rxData[20];
- char rxIndex = 0;
- String inputString = "";
- boolean stringComplete = false;
- void setup(){
- Serial.begin(9600);
- Serial1.begin(9600);
- Serial.flush();
- Serial1.flush();
- //Reset IC
- Serial1.println("ATZ");
- delay(1500);
- getOBDResponse();
- Serial.println(rxData);
- clearBuffer();
- getOBDResponse();
- Serial.println(rxData);
- clearBuffer();
- //Sets IC to defults
- Serial1.println("ATD");
- delay(1000);
- getOBDResponse();
- Serial.println(rxData);
- clearBuffer();
- getOBDResponse();
- Serial.println(rxData);
- clearBuffer();
- Serial1.println("ATSP0");
- delay(1000);
- getOBDResponse();
- Serial.println(rxData);
- clearBuffer();
- getOBDResponse();
- Serial.println(rxData);
- clearBuffer();
- Serial1.println("010D");
- delay(1000);
- getOBDResponse();
- Serial.println(rxData);
- clearBuffer();
- getOBDResponse();
- Serial.println(rxData);
- clearBuffer();
- Serial1.println("ATDP");
- delay(1000);
- getOBDResponse();
- Serial.println(rxData);
- clearBuffer();
- getOBDResponse();
- Serial.println(rxData);
- clearBuffer();
- //Bus initiation
- Serial1.println("ATSI");
- delay(3000);
- getOBDResponse();
- Serial.println(rxData);
- clearBuffer();
- getOBDResponse();
- Serial.println(rxData);
- clearBuffer();
- Serial.flush();
- Serial1.flush();
- }
- void loop(){
- /*
- if(stringComplete){
- Serial.println(inputString);
- inputString = "";
- stringComplete = false;
- }
- */
- Serial1.flush();
- Serial1.println("010D");
- getOBDResponse();
- Serial.println(rxData);
- clearBuffer();
- getOBDResponse();
- Serial.println(rxData);
- clearBuffer();
- }
- void getOBDResponse(){
- char inChar = 0;
- while(inChar != '\r'){
- if(Serial1.available() > 0){
- if(Serial1.peek() == '\r'){
- inChar = Serial1.read();
- rxData[rxIndex] = '\0';
- rxIndex = 0;
- }else{
- inChar = Serial1.read();
- rxData[rxIndex++] = inChar;
- }
- }
- }
- }
- void clearBuffer(){
- int i;
- for(i = 0; i < 20; i++){
- rxData = '';
100. }
101. }
102. void serialEvent1(){
103. while(Serial1.available()){
104. char input = (char)Serial1.read();
105. inputString += input;
106. if(input == '\r'){
107. stringComplete = true;
108. }
109. }