Hi,
im trying to read from ELM327 connected to the OBD interface of my car. It seems to work, but there is an issue with the reception.
My Serial output:
[ELM327 v1.3a]
[>ATE0]
[>OK]
[>OK]
[>SEARCHING…41 0C 00441 441441 0C 00 00 ]
[441 0C 41 441 0441 0441 0C 00 00 ]
[>41 0C 00 00 ]
[>41 0C 00 00 ]
[>41 0C 00 00 ]
[>41 0C 00 00 ]
[>41 0C 00 00 ]
[>41 0C 00 00 ]
[>41 0C 00 00 ]
[>4141 0C 00 00 ]
[441 0C 00 00 ]
[441 0C 00 00 ]
[441 0C 00 00 ]
[441 0C 00 00 ]
[>4141 0C 00 00 ]
[441 0C 00 00 ]
[441 0C 00 00 ]
[441 0C 00 00 ]
[441 0C 00 00 ]
[>4141 0C 00 00 ]
As you see there is corrupted data every 5 lines. Do you know why this happens?
My code:
#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>
String inputString = ""; // a string to hold incoming data
SoftwareSerial softwareSerial(8, 9);
int serIn;
char serInString[100]; // array that will hold the different bytes 100=100characters;
// -> you must state how long the array will be else it won't work.
int serInIndx = 0; // index of serInString[] in which to insert the next incoming byte
int serOutIndx = 0; // index of the outgoing serInString[] array;
//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()
{
Serial.begin(9600);
softwareSerial.begin(19200);
softwareSerial.println("Start...");
delay(1000);
Serial.flush();
Serial.println("ATZ");
delay(1000);
Serial.print("ATZ\r");
delay(5000);
Serial.print("ATE0\r");
delay(1000);
Serial.print("ATL0\r");
delay(1000);
Serial.print("ATSP0\r");
delay(1000);
Serial.print("0100\r");
delay(5000);
}
void readOBD() {
char inChar;
String rec = "[";
// only if there are bytes in the serial buffer execute the following code
if(Serial.available()) {
//keep reading and printing from serial untill there are bytes in the serial buffer
while (Serial.available()>0){
inChar = Serial.read(); //read Serial
if(inChar == '\r' || inChar == '\n') break;
rec += String(inChar);
}
rec += "]";
if(rec.length() > 4)
{
softwareSerial.println(rec);
}
else {
rec = "";
}
}
}
void loop()
{
Serial.println("010C");
readOBD();
delay(200);
}