View Single Post
Old 03-06-2012, 05:18 AM   #41 (permalink)
toc
EcoModding Apprentice
 
Join Date: Jan 2011
Location: Australia
Posts: 179

Sonata97 - '97 Hyundai Sonata GL
90 day: 25.96 mpg (US)

Pulsar - '03 Nissan Pulsar ST
Team Nissan
90 day: 36.09 mpg (US)

Lancer - '04 Mitsubishi Lancer
90 day: 31.11 mpg (US)

Lancer 2.0 - '09 Mitsubishi Lancer
90 day: 27.1 mpg (US)
Thanks: 9
Thanked 16 Times in 13 Posts
Set it to 100 or 200. Won't matter much.

#define MAX_WAIT_TIME 100


int fetch_data(byte cmd) {
int dat[3];
int temp;
int i;
Serial.write(cmd);
starttime = millis();
while ((Serial.available()<2) && ( (millis() - starttime) < MAX_WAIT_TIME) ) {
//do nothing
}
if (Serial.available()<2) {
wireless.print("Error - 2 Bytes not found - We did get:");
wireless.println(Serial.read(), HEX);
Serial.flush();
} else {
i = 0;
delay(10);
while (Serial.available() > 0) {

temp = Serial.read();
wireless.print("Dat ");
wireless.print(i);
wireless.print(": ");
wireless.print(temp, HEX);
dat[i] = temp;
i++;
//dat[0] should be the cmd we sent
//dat[1] should be the result of the cmd.
}
Serial.flush();
return dat[1];
}

}

void loop()
{
int temp_val;
int temp_real_val;
wireless.println("Testing at 1920bps");
wireless.print("RPM: Result:");
temp_val = fetch_data(0x21);
temp_real_val = temp_val * 31.25;
wireless.print(temp_val, HEX);
wireless.print("|RPM Val: ");
wireless.println(temp_real_val);

You should be able to fetch the HEX value - 0x21, and convert to DEC then multiply by 31.25.

Looks like I missed the convert to dec perhaps..


If you are still having problems, give us a look at the parameter you are requesting (RPM is a good one), tell us the hex value of the response, and what value you are getting..

__________________
  Reply With Quote