Thanks Magister,
Well i have to say this was a high tech code for my rookie knowledge.
I can see it contains a high amount of functions as a fault code reader and other functions recording diffrent values,
I will check the speed issue, have been using 38400 bauds without problems.
Did find that command ATS0 speeds up things, it removes the spaces in the hexa reply. Maybe you are using it allready.
As i am running a regular arduino with a big graphical library i have to make my code way smaller then yours.
So according to my knowledge the code below will pick out the last four bytes and convert them to a decimal number.
But in what way can i get a simple reply in a decimal form?
If you have a possibillity of checking my simple rookie code below you are welcome any pointers will do fine...
Hope i am not doing anything wrong by using your code and showing it here?
Code:
#include <Arial14.h>
#include <ks0108.h>
#include <avr/sleep.h>
#define rxPin 0 //arduino pin for rx
#define txPin 1 //arduino pin for tx
#define STRLEN 40
#define NUL '\0'
#define CR '\r' // carriage return = 0x0d = 13
#define PROMPT '>'
#define DATA 1 // data with no cr/prompt
/* This code used to pick out the correct bytes and to cnvert them to decimal */
byte elm_read(char *str, byte size)
{
int b;
byte i;
byte *pos;
// wait for something on com port
i=0;
while((b=serialRead())!=PROMPT && i<size)
{
if(/*b!=-1 &&*/ b>=' ')
str[i++]=b;
sleep_mode(); // macro that enable/sleep/disable
}
if(i!=size) // we got a prompt
{
str[i]=NUL; // replace CR by NUL
return PROMPT;
}
else
{
return DATA;
}
}
// buf must be ASCIIZ
void elm_write(char *str)
{
while(*str!=NUL)
serialWrite(*str++);
}
// check header byte
byte elm_check_response(byte *cmd, char *str)
{
// cmd is something like "010D"
// str should be "41 0D blabla"
#if 0
if(cmd[0]+4 != str[0]
|| cmd[1]!=str[1]
|| cmd[2]!=str[3]
|| cmd[3]!=str[4])
return 1;
#endif
return 0; // no error
}
byte elm_compact_response(byte *buf, char *str)
{
byte i;
// start at 6 which is the first hex byte after header
// ex: "41 0C 1A F8"
// return buf: 0x1AF8
i=0;
str+=6;
while(*str!=NUL)
buf[i++]=strtol(str, &str, 16);
return i;
}
void setup(){
byte r;
char str[16];
pinMode(rxPin, INPUT); //set rx pin
pinMode(txPin, OUTPUT); //set tx pin
Serial.begin(38400); //set baud rate
Serial.println(); //execute any data garbage
delay(1000);
Serial.println("ATWS"); //reset
delay(1000); //wait for reset
Serial.println("ATS0"); //remove space characters from reply of ELM
delay(1000);
Serial.println("ATE0"); // turn off command echo
delay(1000);
Serial.println("ATSP0"); //set protocol
}
void loop(){
Serialwrite(01 C1); //rpm request
GLCD.GotoXY(98,30);
GLCD.PrintNumber(char str[16]); //example on how to display reply on a lcd
delay(500);
}