
I am struggling with the X-Sim USO serial/USB output - I have it talking to an Arduino using the COM port so things should be simple. As far as I know there is nothing wrong with my code; using HTerm or the Arduino COM port listener I can send data and receive sane data back telling me I've parsed the 2-byte value correctly. For debugging I have the LED on the Arduino flashing once for every 1k RPM, and this behaves with data injected manually. When I send the data from X-Sim (Math Setup just 1:1) I get 36 blinks of the LED, so the supposed RPM value is something between 36,000 and 37,000 (should be ~2,200). Can anyone spot what I've done wrong?

- Code: Select all
const int LED = 13;
void setup() {
Serial.begin(115200);
pinMode(LED,OUTPUT);
}
void loop() {
char dataID;
while (Serial.available() > 0) {
dataID = Serial.read();
if (dataID == 'R') f_RPM();
}
}
void f_RPM() {
delay(1);
unsigned char d1 = Serial.read(); // high byte
delay(1);
unsigned char d2 = Serial.read(); // low byte
unsigned int rpm = word(d1,d2);
Serial.print(rpm);
Serial.write(rpm);
for (int i = 0; i < (rpm/1000); i++) {
digitalWrite(LED, HIGH);
delay(300);
digitalWrite(LED, LOW);
delay(300);
}
}
Thanks in advance, and to those whose code I've pored over.