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..
__________________
|